diff --git a/JQueryPlugin/lib/Foswiki/Plugins/JQueryPlugin/TEXTBOXLIST.pm b/JQueryPlugin/lib/Foswiki/Plugins/JQueryPlugin/TEXTBOXLIST.pm index 7390259..ed38541 100644 --- a/JQueryPlugin/lib/Foswiki/Plugins/JQueryPlugin/TEXTBOXLIST.pm +++ b/JQueryPlugin/lib/Foswiki/Plugins/JQueryPlugin/TEXTBOXLIST.pm @@ -23,29 +23,36 @@ Constructor =cut sub new { - my $class = shift; - my $session = shift || $Foswiki::Plugins::SESSION; - - my $this = bless( - $class->SUPER::new( - $session, - name => 'TextboxList', - version => '0.2', - author => 'Michael Daum', - homepage => 'http://foswiki.org/Extensions/JQueryPlugin', - css => ['jquery.textboxlist.css'], - javascript => - [ 'jquery.textboxlist.js', 'jquery.textboxlist.init.js' ], - dependencies => [ 'autocomplete', 'metadata', 'livequery' ], - ), - $class - ); - - return $this; + my $class = shift; + my $session = shift || $Foswiki::Plugins::SESSION; + + my $this = bless($class->SUPER::new( + $session, + name => 'Textboxlist', + version => '0.3.0', + author => 'Michael Daum, Temi Varghese', + homepage => 'http://foswiki.org/Extensions/JQueryPlugin', + javascript => [ 'jquery.ui.mouse.js', 'jquery.ui.sortable.js', 'jquery.ui.widget.js', 'jquery.textboxlist.js', 'jquery.textboxlist.init.js'], + css => ['jquery.textboxlist.css'], + dependencies => [ 'autocomplete', 'metadata', 'livequery', 'ui', 'themeswitcher' ] + ), $class); + + Foswiki::Func::addToZone('script', 'JQUERYPLUGIN::UI::MOUSE', <<"HERE", 'JQUERYPLUGIN::UI'); + +HERE + Foswiki::Func::addToZone('script', 'JQUERYPLUGIN::UI::SORTABLE', <<"HERE", 'JQUERYPLUGIN::UI'); + +HERE + Foswiki::Func::addToZone('script', 'JQUERYPLUGIN::UI::WIDGET', <<"HERE", 'JQUERYPLUGIN::UI'); + +HERE + + return $this; } 1; + __END__ Foswiki - The Free and Open Source Wiki, http://foswiki.org/ @@ -69,3 +76,4 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. As per the GPL, removal of this notice is prohibited. + diff --git a/JQueryPlugin/pub/System/JQueryPlugin/plugins/textboxlist/jquery.textboxlist.init.uncompressed.js b/JQueryPlugin/pub/System/JQueryPlugin/plugins/textboxlist/jquery.textboxlist.init.uncompressed.js index 7861f9c..067cfa9 100644 --- a/JQueryPlugin/pub/System/JQueryPlugin/plugins/textboxlist/jquery.textboxlist.init.uncompressed.js +++ b/JQueryPlugin/pub/System/JQueryPlugin/plugins/textboxlist/jquery.textboxlist.init.uncompressed.js @@ -3,6 +3,25 @@ jQuery(function($) { var $this = $(this); $this.addClass("jqInitedTextboxList"); var opts = $.extend({}, $this.metadata()); - $this.textboxlist(opts); + opts.name = $this.attr("name"); + //set the variables if not defined + var subscript = "textboxlist"+foswiki.web+foswiki.topic; + var name = $this.attr("name"); + subscript = subscript.replace(/\//g,"")+name; + if(!opts.inputCookie) + opts.inputCookie = subscript+"Input"; + if(!opts.radioCookie) + opts.radioCookie = subscript + "Radio"; + if(!opts.sortableID) + opts.sortableID = subscript + "SortableID"; + if(!opts.orderID) + opts.orderID = subscript + "RadioID"; + if(!opts.radioName) + opts.radioName = subscript + "RadioName"; + + var o = $this.textboxlist(opts); }); }); +/*$("document").ready(function(){ + $(getCookie("jqTextboxRadio")+":eq(0)").click();//.attr("checked","true") +});*/ \ No newline at end of file diff --git a/JQueryPlugin/pub/System/JQueryPlugin/plugins/textboxlist/jquery.textboxlist.uncompressed.js b/JQueryPlugin/pub/System/JQueryPlugin/plugins/textboxlist/jquery.textboxlist.uncompressed.js index d573e95..14b1b55 100644 --- a/JQueryPlugin/pub/System/JQueryPlugin/plugins/textboxlist/jquery.textboxlist.uncompressed.js +++ b/JQueryPlugin/pub/System/JQueryPlugin/plugins/textboxlist/jquery.textboxlist.uncompressed.js @@ -2,6 +2,7 @@ * jQuery textbox list plugin 1.0 * * Copyright (c) 2009-2010 Michael Daum http://michaeldaumconsulting.com + * Copyright (c) 2011 Temi Varghese http://trin.org.au * * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php @@ -44,9 +45,18 @@ } // wrap + if(self.opts.sortable){ +self.container = self.input.wrap("
") +.parent().append("
Order Fields:\ +Ascending  \ +Descending  \ +Custom \ +"); + } + else{ self.container = self.input.wrap("
") - .parent().append(""); - + .parent().append(""); + } // clear button if (self.opts.clearControl) { $(self.opts.clearControl).click(function() { @@ -64,9 +74,10 @@ return false; }); } - + // autocompletion if (self.opts.autocomplete) { + self.input.attr('autocomplete', 'off').autocomplete(self.opts.autocomplete, self.opts). result(function(event, data, value) { //$.log("TEXTBOXLIST: result data="+data+" formatted="+formatted); @@ -97,7 +108,7 @@ } }); - // add event + // add event self.input.bind("DeleteValue", function(e, val) { if (val) { self.deselect([val]); @@ -114,18 +125,91 @@ self.clear(); }); + // refresh event + self.input.bind("Refresh", function(e) { + + + self.select(self.currentValues,true); + }); + + //update radioCookie + self.input.bind("Update", function(e,val) { + self.updateRadio(val); + }); + // init self.currentValues = []; self.titleOfValue = []; + if(!self.opts.name) + $.log("Name variable should be defined! Otherwise multiple textboxList on the same page will have problems."); + + // set the value stored in foswiki preference + if(foswiki.Pref.getPref(self.opts.inputCookie)){ + self.input.attr("value",foswiki.Pref.getPref(self.opts.inputCookie)); + } if (self.input.val()) { - self.select(self.input.val().split(/\s*,\s*/).sort(), true); + var list = self.input.val().split(/\s*,\s*/); + if(foswiki.Pref.getPref(self.opts.radioCookie)){ + if(self.opts.sortable){ + $(foswiki.Pref.getPref(self.opts.radioCookie)+":eq(0)").click(); + } + self.select(list, true); + + + } else{ + + switch(self.opts.doSort) + { + case true: + case "Asc": + self.select(list.sort(), true); + $("span#"+self.opts.orderID+">input#"+self.opts.radioName+"jqTextboxRadioASC").click(); + break; + case "Dsc": + self.select(list.sort().reverse(), true); + $("span#"+self.opts.orderID+">input#"+self.opts.radioName+"jqTextboxRadioDSC").click(); + break; + case false: + case "Custom": + self.select(list, true); + $("span#"+self.opts.orderID+">input#"+self.opts.radioName+"jqTextboxRadioCustom").click(); + break; + } + } } + self.initialValues = self.currentValues.slice(); self.input.removeClass('foswikiHidden').show(); return this; }; - + + // update according to the radio button selection ************************************* + $.TextboxLister.prototype.updateRadio = function(id){ + var self = this; + $("."+self.opts.inputClass).trigger("Refresh"); + foswiki.Pref.setPref(self.opts.radioCookie,id); + if(id.indexOf("Custom")!=-1){ + $("#"+self.opts.sortableID).sortable({ + disabled:false, + update:function(event,ui){ + var orderedList =[]; + $("div#"+self.opts.sortableID+">span."+self.opts.listValueClass+">input").each(function(){ + orderedList.push($(this).attr("value")); + }); + $(self).trigger("Clear"); + self.currentValues = []; + self.select(orderedList, true); + } + }); + } + else{ + $("#"+self.opts.sortableID).sortable({ + disabled:true + }); + } + }; + // clear selection ***************************************************** $.TextboxLister.prototype.clear = function() { $.log("TEXTBOXLIST: called clear"); @@ -141,6 +225,10 @@ } }; +// $.TextboxLister.prototype.setSorting = function (sortable) { +// alert('sortable: ' + sortable); +// }; + // reset selection ***************************************************** $.TextboxLister.prototype.reset = function() { $.log("TEXTBOXLIST: called reset"); @@ -158,13 +246,13 @@ // add values to the selection ****************************************** $.TextboxLister.prototype.select = function(values, suppressCallback) { $.log("TEXTBOXLIST: called select("+values+") "+typeof(values)); - var self = this, i, j, val, title, found, currentVal, input, close; + var self = this, i, j, val, title, found, currentVal, input, close, values; if (typeof(values) === 'object') { values = values.join(','); } if (typeof(values) !== 'undefined' && typeof(values) !== 'null') { - values = values.split(/\s*,\s*/).sort(); + values = values.split(/\s*,\s*/); } else { values = ''; } @@ -212,8 +300,23 @@ } } - if (self.opts.doSort) { - self.currentValues = self.currentValues.sort(); + if($("span#"+self.opts.orderID+">input#"+self.opts.radioName+"jqTextboxRadioASC").is(':checked')){ + self.currentValues = self.currentValues.sort(); + } + else if($("span#"+self.opts.orderID+">input#"+self.opts.radioName+"jqTextboxRadioDSC").is(':checked')){ + self.currentValues = self.currentValues.sort().reverse(); + }else if(!$("span#"+self.opts.orderID+">input#"+self.opts.radioName+"jqTextboxRadioCustom").is(':checked') && self.opts.doSort) { + + switch(self.opts.doSort) + { + case true: + case "Asc": + self.currentValues = self.currentValues.sort(); + break; + case "Dsc": + self.currentValues = self.currentValues.sort().reverse(); + break; + } } $.log("TEXTBOXLIST: self.currentValues="+self.currentValues+" length="+self.currentValues.length); @@ -242,10 +345,12 @@ } self.input.val(''); - + foswiki.Pref.setPref(self.opts.inputCookie,self.currentValues.join(',')); + // onSelect callback if (!suppressCallback && typeof(self.opts.onSelect) == 'function') { $.log("TEXTBOXLIST: calling onSelect handler"); + self.values = values; self.opts.onSelect(self); } self.input.trigger("SelectedValue", values); @@ -255,7 +360,7 @@ $.TextboxLister.prototype.deselect = function(values) { $.log("TEXTBOXLIST: called deselect("+values+")"); - var self = this, newValues = [], i, j, currentVal, found, val; + var self = this, newValues = [], i, j, currentVal, found, val, values; if (typeof(values) == 'object') { values = values.join(','); @@ -287,22 +392,42 @@ // onDeselect callback if (typeof(self.opts.onDeselect) == 'function') { $.log("TEXTBOXLIST: calling onDeselect handler"); + self.values = values; self.opts.onDeselect(self); } +// //call event when list changes +// if (typeof(self.opts.onHideCol) == 'function') { +// $.log("TEXTBOXLIST: calling onDeselect handler"); +// //alert(values); +// self.opts.onHideCol(values); +// } +//alert(this.innerHTML); self.select(newValues, true); }; + // default settings **************************************************** $.TextboxLister.defaults = { containerClass: 'jqTextboxListContainer', listValueClass: 'jqTextboxListValue', closeClass: 'jqTextboxListClose', + inputClass: 'foswikiInputField', doSort: false, + sortable: true, + //fields:undefined, + radioName: undefined, + sortableID: undefined, + orderID: undefined, + radioCookie: undefined, + inputCookie: undefined, + name: undefined, + //inputCookie: "textboxlist"+foswiki.web+foswiki.topic+, inputName: undefined, resetControl: undefined, clearControl: undefined, autocomplete: undefined, + autocompleteOpts: undefined, onClear: undefined, onReset: undefined, onSelect: undefined, @@ -315,3 +440,4 @@ }; })(jQuery); +