]> git.andy128k.dev Git - ipf.git/commitdiff
MORE, more reorder customizable
authoravl <alex.litovchenko@gmail.com>
Wed, 25 Mar 2009 11:02:09 +0000 (13:02 +0200)
committeravl <alex.litovchenko@gmail.com>
Wed, 25 Mar 2009 11:02:09 +0000 (13:02 +0200)
ipf/admin/templates/admin/items.html
ipf/admin/views.php
ipf/orm/record.php

index c32ed12ca94e415d96595242dd381fffb55a565e..c5b546eb8c5e51b9bd82d47db1918eb3431bdfb0 100644 (file)
 <script language="javascript" type="text/javascript" src="{$ADMIN_MEDIA_URL}js/jquery.tablednd.js"></script>
 <script type="text/javascript">
 var reorder_url = "reorder/";
+var prev_ids;
 {literal}
 $(document).ready(function()
 {
-       $('#items-grid').tableDnD({
+    $('#items-grid').tableDnD({
         onDragClass: "ItemsDragClass",
-               onDrop: function(table, row) {
-            $.post(reorder_url, {'ids': $.tableDnD.serialize(), 'drop_id':row.id}, function(data){});
+        onDragStart: function(table, row) {
+            prev_ids = $.tableDnD.serialize();
+        },
+        onDrop: function(table, row) {
+            $.post(reorder_url, {'ids': $.tableDnD.serialize(), 'prev_ids': prev_ids, 'drop_id':row.id}, function(data){});
         }
-       });
+    });
 });
 {/literal}
 </script>
index 80c5761697c970dbbf4b79f229e5625d6949b026..615eb6c3ec21f10f115fb68969be58fae734930b 100644 (file)
@@ -80,19 +80,20 @@ function IPF_Admin_Views_Reorder($request, $match){
     if ($ca!==true) return $ca;
 
     if ($request->method != 'POST')
-       return new IPF_HTTP_Response_NotFound();
+        return new IPF_HTTP_Response_NotFound();
 
     if (!isset($request->POST['ids']))
-       return new IPF_HTTP_Response_NotFound();
+        return new IPF_HTTP_Response_NotFound();
+
+        if (!isset($request->POST['prev_ids']))
+        return new IPF_HTTP_Response_NotFound();
 
     if (!isset($request->POST['drop_id']))
-       return new IPF_HTTP_Response_NotFound();
-    $drop_id = $request->POST['drop_id'];
+        return new IPF_HTTP_Response_NotFound();
 
     $lapp = $match[1];
     $lmodel = $match[2];
 
-
     foreach (IPF_Project::getInstance()->appList() as $app){
         foreach($app->modelList() as $m){
             if (strtolower($m)==$lmodel){
@@ -101,14 +102,17 @@ function IPF_Admin_Views_Reorder($request, $match){
                     return new IPF_HTTP_Response_NotFound();
 
                 if (method_exists($ma, 'list_order'))
-                       $ord_field = $ma->list_order();
+                    $ord_field = $ma->list_order();
                 else
-                               return new IPF_HTTP_Response_NotFound();
+                    return new IPF_HTTP_Response_NotFound();
+
+                $ids      = split(',',(string)$request->POST['ids']);
+                $prev_ids = split(',',(string)$request->POST['prev_ids']);
+                $drop_id  = $request->POST['drop_id'];
 
                 $o = new $m();
-                $ids = split(',',(string)$request->POST['ids']);
-                $o->_reorder($ids, $ord_field, $drop_id);
-                           return new IPF_HTTP_Response_Json("Ok");
+                $o->_reorder($ids, $ord_field, $drop_id, $prev_ids);
+                return new IPF_HTTP_Response_Json("Ok");
             }
         }
     }
index 6333a3490134f2ee0d06b1e69ac31824aedc3603..d389b23b5f2713e121d4f99c3850f070c13775a3 100644 (file)
@@ -1296,7 +1296,7 @@ abstract class IPF_ORM_Record extends IPF_ORM_Record_Abstract implements Countab
        return null;
     }
 
-    public function _reorder($ids, $ord_field, $drop_id){
+       public function _reorder($ids, $ord_field, $drop_id, $prev_ids){
         $ord = 1;
         foreach($ids as $id){
             $item = $this->getTable()->find($id);
@@ -1305,5 +1305,4 @@ abstract class IPF_ORM_Record extends IPF_ORM_Record_Abstract implements Countab
             $ord++;
         }
     }
-
 }
\ No newline at end of file