[dev] [commit] r1021 - phplib/models wwwbase/ajax wwwbase/js

automailer at dexonline.ro automailer at dexonline.ro
Sat Oct 12 20:42:53 EEST 2013


Author: grigoroiualex
Date: Sat Oct 12 20:42:53 2013
New Revision: 1021

Log:
Completed Todos promised in revision 1018. Tags information is editable within the table
on row double click or on edit button.
Table pager is now working as I've corrected the way data is loaded.

Modified:
   phplib/models/VisualTag.php
   wwwbase/ajax/getSavedTags.php
   wwwbase/ajax/visualTagsEdit.php
   wwwbase/js/visualTag.js

Modified: phplib/models/VisualTag.php
==============================================================================
--- phplib/models/VisualTag.php	Wed Oct  9 01:09:14 2013	(r1020)
+++ phplib/models/VisualTag.php	Sat Oct 12 20:42:53 2013	(r1021)
@@ -10,6 +10,11 @@
       $tag->delete();
     }
   }
+
+  /** Paris filter functionality to access the limit query */
+  public static function limit($orm, $from, $quantity) {
+  	return $orm->limit($quantity)->offset($from);
+  }
 }
 
 ?>

Modified: wwwbase/ajax/getSavedTags.php
==============================================================================
--- wwwbase/ajax/getSavedTags.php	Wed Oct  9 01:09:14 2013	(r1020)
+++ wwwbase/ajax/getSavedTags.php	Sat Oct 12 20:42:53 2013	(r1021)
@@ -3,15 +3,21 @@
 require_once("../../phplib/util.php");
 
 $imageId = util_getRequestParameter('imageId');
-$resp = array();
-$lines = VisualTag::get_all_by_imageId($imageId);
+$page = util_getRequestParameter('page');
+$limit = util_getRequestParameter('rows');
+$rows = array();
+$total = VisualTag::factory('VisualTag')->where('imageId', $imageId)->count();
+$lines = VisualTag::factory('VisualTag')->where('imageId', $imageId)
+										->filter('limit', ($page - 1) * $limit, $limit)->find_many();
 
 foreach ($lines as $line) {
   $row = Lexem::get_by_id($line->lexemeId);
-  $resp[] = array('id' => $line->id, 'label' => $line->label, 'xTag' => $line->textXCoord,
+  $rows[] = array('id' => $line->id, 'label' => $line->label, 'xTag' => $line->textXCoord,
                   'yTag' => $line->textYCoord, 'xImg' => $line->imgXCoord,
                   'yImg' => $line->imgYCoord, 'lexeme' => !empty($row) ? $row->formUtf8General : '');
 }
 
+$resp = array('total' => ceil($total / $limit), 'page' => $page, 'records' => $total, 'rows' => $rows);
+
 echo json_encode($resp);
 ?>
\ No newline at end of file

Modified: wwwbase/ajax/visualTagsEdit.php
==============================================================================
--- wwwbase/ajax/visualTagsEdit.php	Wed Oct  9 01:09:14 2013	(r1020)
+++ wwwbase/ajax/visualTagsEdit.php	Sat Oct 12 20:42:53 2013	(r1021)
@@ -5,13 +5,33 @@
 $id = util_getRequestParameter('id');
 
 switch ($oper) {
-  case 'del' :
+  case 'del':
     $line = VisualTag::get_by_id($id);
-    if(!empty($line)) {
+    
+    if(!empty($line)){
       $line->delete();
     }   
     break;
   
+  case 'edit':
+    $xTag = util_getRequestParameter('xTag');
+    $yTag = util_getRequestParameter('yTag');
+    $xImg = util_getRequestParameter('xImg');
+    $yImg = util_getRequestParameter('yImg');
+    $label = util_getRequestParameter('label');
+
+    $line = VisualTag::get_by_id($id);
+  	
+    if(!empty($line)){
+      $line->textXCoord = $xTag;
+      $line->textYCoord = $yTag;
+      $line->imgXCoord = $xImg;
+      $line->imgYCoord = $yImg;
+      $line->label = $label;
+      $line->save();
+  	}
+    break;
+
   default:
     break;
 }

Modified: wwwbase/js/visualTag.js
==============================================================================
--- wwwbase/js/visualTag.js	Wed Oct  9 01:09:14 2013	(r1020)
+++ wwwbase/js/visualTag.js	Sat Oct 12 20:42:53 2013	(r1021)
@@ -4,12 +4,17 @@
   var coords = new Object();
   var gridOptions = {
     add: false,
-    edit: false,
     search: false,
-    deltitle: 'Șterge',
-    refreshtitle: 'Actualizează'
+    edittitle: 'editează',
+    deltitle: 'șterge',
+    refreshtitle: 'reîncarcă'
+  };
+  var editOptions = {
+    reloadAfterSubmit: true,
+    closeAfterEdit: true,
+    closeOnEscape: true,
+    afterSubmit: checkServerResponse
   };
-  var editOptions = {};
   var addOptions = {};
   var delOptions = {
     afterSubmit: checkServerResponse,
@@ -29,19 +34,19 @@
     }, function() {
       jcrop_api = this;
     });
-  };
+  }
 
   function setCoords(c) {
     calculateCentre(c);
 
     $('#x').val(coords.cx);
     $('#y').val(coords.cy);
-  };
+  }
 
   function calculateCentre(c) {
     coords.cx = Math.round((2 * c.x + c.w) / 2);
     coords.cy = Math.round((2 * c.y + c.h) / 2);
-  };
+  }
 
   /** Clears the actual selection */
   $('#clrSel').click(function(e) {
@@ -56,7 +61,7 @@
 
     $('#x').val('');
     $('#y').val('');
-  };
+  }
 
   $('#setCoordTag').click(function() {
     $('#xTag').val(coords.cx);
@@ -92,27 +97,27 @@
     url: wwwRoot + 'ajax/getSavedTags.php',
     postData: {imageId: $('#imageId').val()},
     datatype: 'json',
+    cmTemplate: {sortable: false},
     colNames: ['Id', 'Lexem', 'Text afișat', 'X Etichetă', 'Y Etichetă', 'X Imagine', 'Y Imagine'],
     colModel: [
       {name: 'id', index: 'id', hidden: true},
       {name: 'lexeme', index: 'lexeme', width: 80, align: 'center'},
-      {name: 'label', index: 'label', width: 100, align: 'center'},
-      {name: 'xTag', index: 'xTag', width: 55, align: 'center'},
-      {name: 'yTag', index: 'yTag', width: 55, align: 'center'},
-      {name: 'xImg', index: 'yImg', width: 55, align: 'center'},
-      {name: 'yImg', index: 'yImg', width: 55, align: 'center'}
+      {name: 'label', index: 'label', width: 120, align: 'center', editable: true},
+      {name: 'xTag', index: 'xTag', width: 55, align: 'center', editable: true},
+      {name: 'yTag', index: 'yTag', width: 55, align: 'center', editable: true},
+      {name: 'xImg', index: 'yImg', width: 55, align: 'center', editable: true},
+      {name: 'yImg', index: 'yImg', width: 55, align: 'center', editable: true}
     ],
     rowNum: 20,
     recreateForm: true,
-    width: '430px',
+    width: '450px',
     height: '100%',
     rowList: [20, 50, 100, 200],
-    sortname: 'id',
     pager: $('#tagsPaging'),
     viewrecords: true,
-    sortorder: 'desc',
     caption: 'Etichete salvate',
-    editurl: wwwRoot + 'ajax/visualTagsEdit.php'
+    editurl: wwwRoot + 'ajax/visualTagsEdit.php',
+    ondblClickRow: function(rowid) { $(this).jqGrid('editGridRow', rowid, editOptions); }
   })
   .navGrid('#tagsPaging', gridOptions, editOptions, addOptions, delOptions);
 });
@@ -151,7 +156,7 @@
     alert('Ai uitat să completezi câmpurile Coordonatele zonei etichetate');
     return false;
   }
-};
+}
 
 function validateLexeme() {
   var lexeme = $('#imgLexemeId').val();
@@ -160,7 +165,7 @@
     alert('Ai uitat să completezi ce lexem descrie cel mai bine imaginea');
     return false;
   }
-};
+}
 
 function checkServerResponse(response, postData) {
   if (response.responseText) {


More information about the Dev mailing list