Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Convert multitag to use eZJSCore

Also fix bug where variable "index" in JavaScript was used without being initialized
Added IndexedException class for this purpose
  • Loading branch information...
commit f5b9af5c32219350e7a32d739b67961feb39779f 1 parent 288f6bf
@lastorset authored
View
19 classes/ntags_server.php
@@ -7,16 +7,24 @@
// TODO: Needs to check access rights
+class IndexedException extends Exception {
+ function __construct($index, $msg) {
+ parent::__construct("Element ". $index .": ". $msg);
+ }
+}
+
class nTagsServer extends ezjscServerFunctions {
public static function multitag( $args ) {
// Check input
$http = eZHTTPTool::instance();
+ $index = $http->postVariable( "index" );
+
if( !$http->hasPostVariable( "attrID" ) ) {
- return "error: ". ezpI18n::tr( "ntags/ajax", "No attrID specified" );
+ throw new IndexedException( $index, ezpI18n::tr( "ntags/ajax", "No attrID specified" ) );
} else if( !$http->hasPostVariable( "version" ) ) {
- return "error: ". ezpI18n::tr( "ntags/ajax", "No version number specified" );
+ throw new IndexedException( $index, ezpI18n::tr( "ntags/ajax", "No version number specified" ) );
} else if( !$http->hasPostVariable( "tags" ) && !$http->hasPostVariable( "removeAll" ) ) {
- return "error: ". ezpI18n::tr( "ntags/ajax", "'tags' and 'removeAll' not specified: nothing to do" );
+ throw new IndexedException( $index, ezpI18n::tr( "ntags/ajax", "'tags' and 'removeAll' not specified: nothing to do" ) );
}
// Fetch node
@@ -24,12 +32,11 @@ public static function multitag( $args ) {
$version = $http->postVariable( "version" );
$attr = eZContentObjectAttribute::fetch( $attrID, $version );
if( $attr == null ) {
- return "error: Could not fetch attribute with id '$attrID' and version '$version'";
+ throw new IndexedException( $index, "Could not fetch attribute with id '$attrID' and version '$version'" );
}
// Retrieve keyword attribute and new keywords
$tags = $attr->content();
- //$newTags = $_POST["tags"];
$newTags = $http->postVariable( "tags" );
// Store attribute
@@ -40,7 +47,7 @@ public static function multitag( $args ) {
eZContentCacheManager::clearObjectViewCache( $attr->ContentObjectID );
// Return success and the index of the given element
- return "success: ". $http->postVariable( "index" );
+ return $http->postVariable( "index" );
}
public static function saveTaglistSort( $args ) {
View
21 design/standard/javascript/ntags_multitag.js
@@ -8,6 +8,7 @@ nTags.multi.saveTags = function() {
this.labels = labels;
};
var dirtyObjects = new Array();
+
// Traverse all tags and determine whether they need storing
$(".nTagsEdit tr td.tags").each( function() {
// Find version and attribute
@@ -45,21 +46,25 @@ nTags.multi.saveTags = function() {
}
});
// Mark dirty rows visually while saving
- for(i = 0; i < dirtyObjects.length; i++) {
+ for(var i = 0; i < dirtyObjects.length; i++) {
var dirty = dirtyObjects[i];
- var options = {attrID: dirty.attr, version: dirty.version, index: i, "tags[]": dirty.labels, removeAll: (dirty.labels.length == 0 ? true : false)};
- $.post(ntags.rootURL +"/ntags/multitag_ajax", options, function(response) {
- if (response.substr(0,7) == "success") {
- var index = response.substr(9);
+ var args = {attrID: dirty.attr, version: dirty.version, index: i, "tags[]": dirty.labels, removeAll: (dirty.labels.length == 0 ? true : false)};
+ $.ez('nTagsServer::multitag', args, function(response) {
+ if (response.error_text) {
+ alert(response);
+ if (response.error_text.substr(0,8) == "Element ")
+ {
+ var index = response.error_text.charAt(9);
+ dirtyObjects[index].tr.find("img.saving").remove();
+ }
+ } else {
+ var index = response.content;
dirtyObjects[index].tr.find("td.tags label.new").each( function() {
$(this).removeClass("new");
$(this).addClass("saved");
});
dirtyObjects[index].tr.find("td.tags label.delete").remove();
dirtyObjects[index].tr.find("img.saving").remove();
- } else {
- alert(response);
- dirtyObjects[index].tr.find("img.saving").remove();
}
});
}
Please sign in to comment.
Something went wrong with that request. Please try again.