can3p (can3p) wrote in changelog,
can3p
can3p
changelog

[livejournal] r21556: LJSUP-11565: Ability to edit tags during...

Committer: dpetrov
LJSUP-11565: Ability to edit tags during the moderation
U   trunk/htdocs/community/moderate.bml
U   trunk/htdocs/js/basic.js
A   trunk/htdocs/js/community/
A   trunk/htdocs/js/community/moderate.js
U   trunk/htdocs/js/entry.js
A   trunk/htdocs/js/widget_ippu/selecttags.js
Modified: trunk/htdocs/community/moderate.bml
===================================================================
--- trunk/htdocs/community/moderate.bml	2012-03-27 12:25:51 UTC (rev 21555)
+++ trunk/htdocs/community/moderate.bml	2012-03-27 13:08:46 UTC (rev 21556)
@@ -9,7 +9,13 @@
     LJ::set_active_crumb('moderate');
     return LJ::server_down_html() if ($LJ::SERVER_DOWN);
     use Class::Autouse qw (LJ::Poll);
-
+ 
+    LJ::need_res(qw(
+                    stc/widgets/selecttags.css
+                    js/widget_ippu/selecttags.js
+                    js/community/moderate.js
+                    ));    
+ 
     my $ret;
     my $remote = LJ::get_remote();
 
@@ -577,7 +583,7 @@
                            raw   => "autocomplete='off'",
                        }
                     );
-                    $ret .= "$BML::ML{'entryform.selecttags'}";
+                    $ret .= '<a href="#" onclick="return selectModTags(this);">' . $BML::ML{'entryform.selecttags'} . '</a>';
                     } else {
                         $ret .= $current{$key};
                 }

Modified: trunk/htdocs/js/basic.js
===================================================================
--- trunk/htdocs/js/basic.js	2012-03-27 12:25:51 UTC (rev 21555)
+++ trunk/htdocs/js/basic.js	2012-03-27 13:08:46 UTC (rev 21556)
@@ -120,10 +120,12 @@
  *
  * @param {Function} func Function to call.
  * @param {number} wait Time in ms to wait before function will be called.
+ * @param {boolean=false} resetOnCall it true, the function will be executed only after last call + delay time
  */
-LJ.DelayedCall = function(func, wait) {
+LJ.DelayedCall = function(func, wait, resetOnCall) {
 	this._func = func;
 	this._wait = wait;
+	this._resetOnCall = !!resetOnCall;
 	this._timer = null;
 	this._args = null;
 };
@@ -139,7 +141,14 @@
  */
 LJ.DelayedCall.prototype.run = function(/* arguments */) {
 	this._args = [].slice.call(arguments, 0);
-	if (this._timer) { return; }
+	if (this._timer) {
+		if (this._resetOnCall) {
+			clearTimeout(this._timer);
+			this._timer = null;
+		} else {
+			return;
+		}
+	}
 
 	this._timer = setTimeout(this._timerCallback.bind(this), this._wait);
 };

Added: trunk/htdocs/js/community/moderate.js
===================================================================
--- trunk/htdocs/js/community/moderate.js	                        (rev 0)
+++ trunk/htdocs/js/community/moderate.js	2012-03-27 13:08:46 UTC (rev 21556)
@@ -0,0 +1,12 @@
+function selectModTags(node) {
+	var widget = new LJWidgetIPPU_SelectTags({
+		title: node.firstChild.nodeValue,
+		height: 329,
+		width: jQuery(window).width() / 2
+	}, {
+		user: jQuery(document.forms.authForm.authas).val()
+	});
+
+	return false;
+}
+

Modified: trunk/htdocs/js/entry.js
===================================================================
--- trunk/htdocs/js/entry.js	2012-03-27 12:25:51 UTC (rev 21555)
+++ trunk/htdocs/js/entry.js	2012-03-27 13:08:46 UTC (rev 21556)
@@ -665,115 +665,17 @@
 }
 
 function selectTags(node) {
-	var widget = new LJWidgetIPPU();
-
-	widget.onRefresh = function() {
-		IPPUSelectTags.widget = widget;
-		IPPUSelectTags.init();
-	};
-
-	widget.init({
+	var widget = new LJWidgetIPPU_SelectTags({
 		title: node.firstChild.nodeValue,
 		height: 329,
-		width: jQuery(window).width() / 2,
-		widgetClass: 'IPPU::SelectTags'
+		width: jQuery(window).width() / 2
 	}, {
 		user: jQuery(document.forms.updateForm.usejournal).val()
 	});
-	widget.ippu.addClass('ippu-select-tags');
-	widget.ippu.setClickToClose(false);
 
 	return false;
 }
 
-IPPUSelectTags = {
-	init: function(ippu_node) {
-		$('selecttags-all').value = $('prop_taglist').value.split(/ *, */).join(', ');
-
-		this.checkboxes = jQuery('div.b-selecttags-tags input:checkbox', ippu_node);
-		this.boxesCache = {};
-		this.checked = {};
-		var cache = this.boxesCache,
-			checked = this.checked;
-
-		this.checkboxes.each(function() {
-			cache[this.value] = this;
-
-			if (this.checked) {
-				checked[this.value] = true;
-			}
-		});
-
-		jQuery('#selecttags-all').input(this.input.bind(this)).input();
-	},
-
-	change: function(node) {
-		var inp = $('selecttags-all'),
-			ary = inp.value.replace(/ */, '') ? inp.value.split(/ *, */) : [],
-			i = -1,
-			val = node.value;
-
-		ary = jQuery.map(ary, function (val, idx) {
-			return (val.length > 0) ? val : null
-		});
-
-		if (node.checked) {
-			ary.push(val);
-			this.checked[val] = true;
-		} else {
-			while (ary[++i]) {
-				if (ary[i] == node.value) {
-					ary.splice(i, 1);
-					break;
-				}
-			}
-			delete this.checked[val];
-		}
-
-		inp.value = ary.join(', ');
-	},
-
-	input: function() {
-		var ary = $('selecttags-all').value.split(/ *, */),
-			checkboxes = IPPUSelectTags.checkboxes,
-			cache = this.boxesCache,
-			newChecked = {},
-			checked = this.checked;
-
-		ary = ary.filter(function (val, idx) { return (val.length > 0); })
-				.map(function(val){ return val.trim(); });
-
-		ary.forEach(function(keyword) {
-			keyword = keyword.trim();
-			if (!cache.hasOwnProperty(keyword)) { return; }
-
-			delete checked[keyword];
-			cache[keyword].checked = true;
-			newChecked[keyword] = true;
-		});
-
-		for(var keyword in checked) {
-			cache[keyword].checked = false;
-		}
-		this.checked = newChecked;
-	},
-
-	save_click: function() {
-		$('prop_taglist').value = $('selecttags-all').value.split(/ *, */).join(', ');
-		this.widget.close();
-	},
-
-	reset_click: function() {
-		$('selecttags-all').value = '';
-		IPPUSelectTags.checkboxes.attr('checked', false);
-		this.checked = {};
-
-		for (var keyword in this.boxesCache) {
-			this.boxesCache[keyword].checked = false;
-		}
-	}
-};
-
 function _changeOptionState(option, enable) {
 	if (option) {
 		if (enable) {

Added: trunk/htdocs/js/widget_ippu/selecttags.js
===================================================================
--- trunk/htdocs/js/widget_ippu/selecttags.js	                        (rev 0)
+++ trunk/htdocs/js/widget_ippu/selecttags.js	2012-03-27 13:08:46 UTC (rev 21556)
@@ -0,0 +1,114 @@
+LJWidgetIPPU_SelectTags = new Class( LJWidgetIPPU, {
+	init: function (opts, params) {
+		opts.widgetClass = 'IPPU::SelectTags';
+		this.width = opts.width; // Use for resizing later
+		this.height = opts.height; // Use for resizing later
+		this.endpoint= "widget";
+		this.method = "POST";
+		LJWidgetIPPU_SelectTags.superClass.init.apply( this, arguments );
+
+		this.ippu.setTitle( opts.title );
+		this.ippu.addClass( 'ippu-select-tags' );
+		this.ippu.setClickToClose(false)
+
+		this._inputcall = new LJ.DelayedCall(this.input.bind(this), 200, true);
+	},
+
+	onRefresh: function() {
+		var self = this;
+		$('selecttags-all').value = $('prop_taglist').value.split(/ *, */).join(', ');
+
+		this.checkboxes = jQuery('div.b-selecttags-tags input:checkbox', this.getWidget());
+		this.boxesCache = {};
+		this.checked = {};
+		var cache = this.boxesCache,
+			checked = this.checked;
+
+		this.checkboxes.each(function() {
+			cache[this.value] = this;
+
+			if (this.checked) {
+				checked[this.value] = true;
+			}
+		});
+
+		jQuery('#selecttags-all').input(this._inputcall.run.bind(this._inputcall)).input();
+
+		var container = jQuery(this.getWidget());
+		if (container.length > 0) {
+			container
+				.delegate('div.b-selecttags-tags input', 'click', function(ev) {
+					self.change(this);
+				})
+				.delegate('#selecttags-clear', 'click', this.reset_click.bind(this))
+				.delegate('#selecttags-select', 'click', this.save_click.bind(this));
+		}
+	},
+
+	change: function(node) {
+		var inp = $('selecttags-all'),
+			ary = inp.value.replace(/ */, '') ? inp.value.split(/ *, */) : [],
+			i = -1,
+			val = node.value;
+
+		ary = jQuery.map(ary, function (val, idx) {
+			return (val.length > 0) ? val : null
+		});
+
+		if (node.checked) {
+			ary.push(val);
+			this.checked[val] = true;
+		} else {
+			while (ary[++i]) {
+				if (ary[i] == node.value) {
+					ary.splice(i, 1);
+					break;
+				}
+			}
+			delete this.checked[val];
+		}
+
+		inp.value = ary.join(', ');
+	},
+
+	input: function() {
+		var ary = $('selecttags-all').value.split(/ *, */),
+			checkboxes = this.checkboxes,
+			cache = this.boxesCache,
+			newChecked = {},
+			checked = this.checked;
+
+		ary = ary.filter(function (val, idx) { return (val.length > 0); })
+				.map(function(val){ return val.trim(); });
+
+		ary.forEach(function(keyword) {
+			keyword = keyword.trim();
+			if (!cache.hasOwnProperty(keyword)) { return; }
+
+			delete checked[keyword];
+			cache[keyword].checked = true;
+			newChecked[keyword] = true;
+		});
+
+		for(var keyword in checked) {
+			cache[keyword].checked = false;
+		}
+		this.checked = newChecked;
+	},
+
+	save_click: function() {
+		$('prop_taglist').value = $('selecttags-all').value.split(/ *, */).join(', ');
+		this.close();
+	},
+
+	reset_click: function() {
+		$('selecttags-all').value = '';
+		this.checkboxes.attr('checked', false);
+		this.checked = {};
+
+		for (var keyword in this.boxesCache) {
+			this.boxesCache[keyword].checked = false;
+		}
+	}
+});
+

Tags: bml, can3p, dpetrov, js, livejournal
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments