.flatpages-flatpage #id_content { height:40.2em; }
.module table .vPositiveSmallIntegerField { width:2.2em; }
+/* INLINE REORDER */
+.ItemsDragClass{background-color:#E3F3FE;}
+
abstract function getModelName();
+ public function getApplication()
+ {
+ return IPF_Utils::appByModel($this->getModelName());
+ }
+
function getAddNum(){ return 4; }
function getLegend(){
$this->formset = array();
+ $o = $this->_orderableColumn();
+
+ $form_extra = array(
+ 'exclude' => array(
+ $this->getFkName(),
+ $this->getFkLocal(),
+ ),
+ );
+ if ($o)
+ $form_extra['exclude'][] = $o;
+
$first = true;
if ($this->parentModel->exists()){
- $objects = IPF_ORM_Query::create()
+ $query = IPF_ORM_Query::create()
->from(get_class($this->model))
- ->orderby($this->orderby)
- ->where($this->getFkLocal().'='.$this->parentModel->id)
- ->execute();
+ ->where($this->getFkLocal().'='.$this->parentModel->id);
+
+ if ($o)
+ $objects = $query->orderby($o)->execute();
+ else
+ $objects = $query->orderby($this->orderby)->execute();
foreach ($objects as $obj){
$prefix = 'edit_'.get_class($this->model).'_'.$obj->id.'_';
}
}
- $form = $this->_getForm($obj, $d,
- array('exclude'=>array($this->getFkName(),$this->getFkLocal()))
- );
+ $form = $this->_getForm($obj, $d, $form_extra);
$form->prefix = $prefix;
$n_addnum = $this->getAddNum();
for($i=0; $i<$n_addnum; $i++ ){
- $form = $this->_getForm($this->model->copy(), null, array('exclude'=>array($this->getFkName(),$this->getFkLocal())));
+ $form = $this->_getForm($this->model->copy(), null, $form_extra);
$form->fields = array_merge(array(new IPF_Form_Field_Boolean(array('label'=>'Del','name'=>'delete_', 'widget_attrs'=>array('disabled'=>'disabled')))),$form->fields);
$form->prefix = 'add_'.get_class($this->model).'_'.$i.'_';
$form->data = $data;
}
}
}
+
+ public function _orderable()
+ {
+ return $this->_orderableColumn() !== null;
+ }
+
+ public function _orderableColumn()
+ {
+ if ($this->model->getTable()->hasTemplate('IPF_ORM_Template_Orderable'))
+ return $this->model->getTable()->getTemplate('IPF_ORM_Template_Orderable')->getColumnName();
+ else
+ return null;
+ }
}
+
{block breadcrumbs}<div class="breadcrumbs"><a href="{url 'IPF_Admin_Views_Index'}">Home</a> » <a href="{url 'IPF_Admin_Views_ListItems', array($lapp, $lmodel)}">{$classname}</a> » {$page_title}</div>{/block}
{block content}
-
-<script type="text/javascript">
-{literal}
-$(document).ready(function(){
- $("#id_ipf_referrer").val(document.referrer);
- var del_href = $("#id_a_delete").attr("href");
- $("#id_a_delete").attr("href", del_href+'?ipf_referrer='+document.referrer);
-});
-{/literal}
-</script>
-
<div id="content" class="colM">
<h1>{$page_title}</h1>
<div id="content-main">
<div class="tabular inline-related">
<fieldset class="module">
<h2>{$inline->getLegend()}</h2>
- <table>
+ <table{if $inline->_orderable()}
+ class="orderable-inlne"
+ data-url="{url 'IPF_Admin_Views_ListItems', array($inline->getApplication()->getSlug(), strtolower($inline->getModelName()))}"
+ {/if}>
{foreach $inline.formset as $formset}
{if $formset.isFirst}
<thead>
</thead>
<tbody>
{/if}
- <tr>
+ <tr{if !$formset.isAdd} data-id="{$formset.model.pk()}"{else} class="nodrag nodrop"{/if}>
{foreach $formset.fields as $fieldname=>$field}
<td{if $field.widget.is_hidden} style="display:none;"{/if}>{$formset.field($fieldname).fieldErrors()}{$formset.field($fieldname)|safe}</td>
{/foreach}
</div>
<br class="clear" />
</div>
+{/block}
+{block scripts}
+<script type="text/javascript" src="{$ADMIN_MEDIA_URL}js/jquery.tablednd.js"></script>
+<script type="text/javascript">
+{literal}
+$(document).ready(function(){
+ $("#id_ipf_referrer").val(document.referrer);
+ var del_href = $("#id_a_delete").attr("href");
+ $("#id_a_delete").attr("href", del_href+'?ipf_referrer='+document.referrer);
+
+ $('.orderable-inlne').each(function(){
+ var $table = $(this);
+ $table.tableDnD({
+ onDragClass: "ItemsDragClass",
+ onDrop: function(table, row) {
+ var ids = [];
+ $table.find('tr[data-id]').each(function(){
+ ids.push($(this).data('id'));
+ });
+ $.post($table.data('url') + 'reorder/', { 'ids[]': ids }, function(data){});
+ }
+ });
+ });
+});
+{/literal}
+</script>
{/block}
{block breadcrumbs}<div class="breadcrumbs"><a href="{url 'IPF_Admin_Views_Index'}">Home</a> » {$classname}</div>{/block}
{block content}
-
-{if $orderable}
-<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({
- onDragClass: "ItemsDragClass",
- 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>
-{/if}
-
<div id="content" class="flex">
<h1>{$page_title}</h1>
<div id="content-main">
</div>
<br class="clear" />
</div>
+{/block}
-
-
-
-
+{block scripts}
+{if $orderable}
+<script type="text/javascript" src="{$ADMIN_MEDIA_URL}js/jquery.tablednd.js"></script>
+<script type="text/javascript">
+{literal}
+$(document).ready(function(){
+ $('#items-grid').tableDnD({
+ onDragClass: "ItemsDragClass",
+ onDrop: function(table, row) {
+ var ids = [];
+ $('#items-grid .trsort').each(function(){
+ ids.push(this.id);
+ });
+ $.post('reorder/', { 'ids[]': ids }, function(data){});
+ }
+ });
+});
+{/literal}
+</script>
+{/if}
{/block}
$ca = IPF_Admin_App::checkAdminAuth($request);
if ($ca!==true) return $ca;
- if ($request->method != 'POST' || !isset($request->POST['ids']) || !isset($request->POST['prev_ids']) || !isset($request->POST['drop_id']))
+ if ($request->method != 'POST' || !isset($request->POST['ids']) || !is_array($request->POST['ids']))
return new IPF_HTTP_Response_NotFound();
$lapp = $match[1];
if ($ma !==null && $ma->_orderable()) {
$ord_field = $ma->_orderableColumn();
- $ids = explode(',',(string)$request->POST['ids']);
- $prev_ids = explode(',',(string)$request->POST['prev_ids']);
- $drop_id = $request->POST['drop_id'];
+ $ids = $request->POST['ids'];
+
+ $table = IPF_ORM::getTable($m);
+ $conn = $table->getConnection();
+
+ $idColumn = $table->getIdentifier();
+ if (is_array($idColumn))
+ $idColumn = $idColumn[0];
+
+ $questions = str_repeat('?,', count($ids)-1) . '?';
+ $query = 'SELECT ' . $conn->quoteIdentifier($ord_field) .
+ ' FROM ' . $conn->quoteIdentifier($table->getTableName()) .
+ ' WHERE ' . $conn->quoteIdentifier($idColumn) . ' IN (' . $questions . ')' .
+ ' ORDER BY ' . $conn->quoteIdentifier($ord_field);
+ $ords = $conn->fetchColumn($query, $ids);
+
+ $i = 0;
+ foreach ($ids as $id) {
+ $item = $table->find($id);
+ $item[$ord_field] = $ords[$i];
+ $item->save();
+ $i++;
+ }
- $o = new $m();
- $o->_reorder($ids, $ord_field, $drop_id, $prev_ids);
-
return new IPF_HTTP_Response_Json("Ok");
}
}
return $this->_custom[$name];
return null;
}
-
- public function _reorder($ids, $ord_field, $drop_id, $prev_ids, $ord=1)
- {
- foreach($ids as $id) {
- $item = $this->getTable()->find($id);
- $item[$ord_field] = $ord;
- $item->save();
- $ord++;
- }
- }
}
return $date2 - $date1;
}
+ static function appByModel($model)
+ {
+ foreach (IPF_Project::getInstance()->appList() as $app)
+ foreach ($app->modelList() as $m)
+ if ($model == $m)
+ return $app;
+ return null;
+ }
+
static function appLabelByModel($model)
{
- foreach (IPF_Project::getInstance()->appList() as $app) {
- foreach($app->modelList() as $m) {
- if ($model==$m)
- return strtolower($app->getLabel());
- }
- }
- return '';
+ $app = self::appByModel($model);
+ if ($app)
+ return strtolower($app->getLabel());
+ else
+ return '';
}
public static function insertDirectory($path, $directory)