# HG changeset patch # User ymh # Date 1310558702 -7200 # Node ID 743a4511d93c3996751ed9d6faebc31073899426 # Parent 8cf915e2324ebad58c960d442122aa60bea9cd1c correction bug #21 et update to latest version of jeditable diff -r 8cf915e2324e -r 743a4511d93c web/hdabo/static/hdabo/js/hdabo.js --- a/web/hdabo/static/hdabo/js/hdabo.js Tue Jul 12 18:25:07 2011 +0200 +++ b/web/hdabo/static/hdabo/js/hdabo.js Wed Jul 13 14:05:02 2011 +0200 @@ -35,7 +35,7 @@ datasheet_id:$('#datasheet_id').val(), num_page:$('#num_page').val(), nb_by_page:$('#nb_by_page').val(), - alpha:$('#alpha').val(), + sort:$('#sort').val(), searched:$('#searched_str').val() }, callback : function(value, settings) { @@ -91,7 +91,7 @@ datasheet_id:$('#datasheet_id').val(), num_page:$('#num_page').val(), nb_by_page:$('#nb_by_page').val(), - alpha:$('#alpha').val(), + sort:$('#sort').val(), searched:$('#searched_str').val() }, callback : function(value, settings) { @@ -113,7 +113,7 @@ datasheet_id:$('#datasheet_id').val(), num_page:$('#num_page').val(), nb_by_page:$('#nb_by_page').val(), - alpha:$('#alpha').val(), + sort:$('#sort').val(), searched:$('#searched_str').val() }, callback : function(value, settings) { @@ -261,7 +261,7 @@ datasheet_id:$('#datasheet_id').val(), num_page:$('#num_page').val(), nb_by_page:$('#nb_by_page').val(), - alpha:$('#alpha').val(), + sort:$('#sort').val(), searched:$('#searched_str').val(), tag_id:id_tag, activated:new_checked diff -r 8cf915e2324e -r 743a4511d93c web/hdabo/static/hdabo/js/jquery.jeditable.js --- a/web/hdabo/static/hdabo/js/jquery.jeditable.js Tue Jul 12 18:25:07 2011 +0200 +++ b/web/hdabo/static/hdabo/js/jquery.jeditable.js Wed Jul 13 14:05:02 2011 +0200 @@ -1,7 +1,7 @@ /* * Jeditable - jQuery in place edit plugin * - * Copyright (c) 2006-2008 Mika Tuupola, Dylan Verheul + * Copyright (c) 2006-2009 Mika Tuupola, Dylan Verheul * * Licensed under the MIT license: * http://www.opensource.org/licenses/mit-license.php @@ -15,7 +15,7 @@ */ /** - * Version 1.6.2 + * Version 1.7.2-dev * * ** means there is basic unit tests for this parameter. * @@ -60,28 +60,25 @@ (function($) { $.fn.editable = function(target, options) { - - var settings = { - target : target, - name : 'value', - id : 'id', - type : 'text', - width : 'auto', - height : 'auto', - event : 'click', - onblur : 'cancel', - loadtype : 'GET', - loadtext : 'Loading...', - placeholder: 'Click to edit', - loaddata : {}, - submitdata : {}, - ajaxoptions: {} - }; + + if ('disable' == target) { + $(this).data('disabled.editable', true); + return; + } + if ('enable' == target) { + $(this).data('disabled.editable', false); + return; + } + if ('destroy' == target) { + $(this) + .unbind($(this).data('event.editable')) + .removeData('disabled.editable') + .removeData('event.editable'); + return; + } - if(options) { - $.extend(settings, options); - } - + var settings = $.extend({}, $.fn.editable.defaults, {target:target}, options); + /* setup some functions */ var plugin = $.editable.types[settings.type].plugin || function() { }; var submit = $.editable.types[settings.type].submit || function() { }; @@ -94,52 +91,66 @@ var reset = $.editable.types[settings.type].reset || $.editable.types['defaults'].reset; var callback = settings.callback || function() { }; + var onedit = settings.onedit || function() { }; var onsubmit = settings.onsubmit || function() { }; var onreset = settings.onreset || function() { }; var onerror = settings.onerror || reset; - - /* add custom event if it does not exist */ - if (!$.isFunction($(this)[settings.event])) { - $.fn[settings.event] = function(fn){ - return fn ? this.bind(settings.event, fn) : this.trigger(settings.event); - } + + /* Show tooltip. */ + if (settings.tooltip) { + $(this).attr('title', settings.tooltip); } - - /* show tooltip */ - $(this).attr('title', settings.tooltip); settings.autowidth = 'auto' == settings.width; settings.autoheight = 'auto' == settings.height; - + return this.each(function() { - /* save this to self because this changes when scope changes */ + /* Save this to self because this changes when scope changes. */ var self = this; - /* inlined block elements lose their width and height after first edit */ - /* save them for later use as workaround */ + /* Inlined block elements lose their width and height after first edit. */ + /* Save them for later use as workaround. */ var savedwidth = $(self).width(); var savedheight = $(self).height(); + + /* Save so it can be later used by $.editable('destroy') */ + $(this).data('event.editable', settings.event); - /* if element is empty add something clickable (if requested) */ + /* If element is empty add something clickable (if requested) */ if (!$.trim($(this).html())) { $(this).html(settings.placeholder); } - $(this)[settings.event](function(e) { - - /* prevent throwing an exeption if edit field is clicked again */ + $(this).bind(settings.event, function(e) { + + /* Abort if element is disabled. */ + if (true === $(this).data('disabled.editable')) { + return; + } + + /* Prevent throwing an exeption if edit field is clicked again. */ if (self.editing) { return; } - - /* remove tooltip */ - $(self).removeAttr('title'); + + /* Abort if onedit hook returns false. */ + if (false === onedit.apply(this, [settings, self])) { + return; + } - /* figure out how wide and tall we are, saved width and height */ - /* are workaround for http://dev.jquery.com/ticket/2190 */ + /* Prevent default action and bubbling. */ + e.preventDefault(); + e.stopPropagation(); + + /* Remove tooltip. */ + if (settings.tooltip) { + $(self).removeAttr('title'); + } + + /* Figure out how wide and tall we are, saved width and height. */ + /* Workaround for http://dev.jquery.com/ticket/2190 */ if (0 == $(self).width()) { - //$(self).css('visibility', 'hidden'); settings.width = savedwidth; settings.height = savedheight; } else { @@ -152,11 +163,10 @@ settings.autoheight ? $(self).height() : settings.height; } } - //$(this).css('visibility', ''); - /* remove placeholder text, replace is here because of IE */ - if ($(this).html().toLowerCase().replace(/;/, '') == - settings.placeholder.toLowerCase().replace(/;/, '')) { + /* Remove placeholder text, replace is here because of IE. */ + if ($(this).html().toLowerCase().replace(/(;|"|\/)/g, '') == + settings.placeholder.toLowerCase().replace(/(;|"|\/)/g, '')) { $(this).html(''); } @@ -164,10 +174,10 @@ self.revert = $(self).html(); $(self).html(''); - /* create the form object */ + /* Create the form object. */ var form = $('
'); - /* apply css or style or both */ + /* Apply css or style or both. */ if (settings.cssclass) { if ('inherit' == settings.cssclass) { form.attr('class', $(self).attr('class')); @@ -179,17 +189,17 @@ if (settings.style) { if ('inherit' == settings.style) { form.attr('style', $(self).attr('style')); - /* IE needs the second line or display wont be inherited */ + /* IE needs the second line or display wont be inherited. */ form.css('display', $(self).css('display')); } else { form.attr('style', settings.style); } } - /* add main input element to form and store it in input */ + /* Add main input element to form and store it in input. */ var input = element.apply(form, [settings, self]); - /* set input content via POST, GET, given data or existing value */ + /* Set input content via POST, GET, given data or existing value. */ var input_content; if (settings.loadurl) { @@ -228,19 +238,19 @@ input.attr('name', settings.name); - /* add buttons to the form */ + /* Add buttons to the form. */ buttons.apply(form, [settings, self]); - /* add created form to self */ + /* Add created form to self. */ $(self).append(form); - /* attach 3rd party plugin if requested */ + /* Attach 3rd party plugin if requested. */ plugin.apply(form, [settings, self]); - /* focus to first visible form element */ + /* Focus to first visible form element. */ $(':input:visible:enabled:first', form).focus(); - /* highlight input contents when requested */ + /* Highlight input contents when requested. */ if (settings.select) { input.select(); } @@ -249,24 +259,23 @@ input.keydown(function(e) { if (e.keyCode == 27) { e.preventDefault(); - //self.reset(); reset.apply(form, [settings, self]); } }); - /* discard, submit or nothing with changes when clicking outside */ - /* do nothing is usable when navigating with tab */ + /* Discard, submit or nothing with changes when clicking outside. */ + /* Do nothing is usable when navigating with tab. */ var t; if ('cancel' == settings.onblur) { input.blur(function(e) { - /* prevent canceling if submit was clicked */ + /* Prevent canceling if submit was clicked. */ t = setTimeout(function() { reset.apply(form, [settings, self]); }, 500); }); } else if ('submit' == settings.onblur) { input.blur(function(e) { - /* prevent double submit if submit was clicked */ + /* Prevent double submit if submit was clicked. */ t = setTimeout(function() { form.submit(); }, 200); @@ -287,17 +296,17 @@ clearTimeout(t); } - /* do no submit */ + /* Do no submit. */ e.preventDefault(); - /* call before submit hook. */ - /* if it returns false abort submitting */ + /* Call before submit hook. */ + /* If it returns false abort submitting. */ if (false !== onsubmit.apply(form, [settings, self])) { - /* custom inputs call before submit hook. */ - /* if it returns false abort submitting */ + /* Custom inputs call before submit hook. */ + /* If it returns false abort submitting. */ if (false !== submit.apply(form, [settings, self])) { - /* check if given target is function */ + /* Check if given target is function */ if ($.isFunction(settings.target)) { var str = settings.target.apply(self, [input.val(), settings]); $(self).html(str); @@ -308,34 +317,37 @@ $(self).html(settings.placeholder); } } else { - /* add edited content and id of edited element to POST */ + /* Add edited content and id of edited element to POST. */ var submitdata = {}; submitdata[settings.name] = input.val(); submitdata[settings.id] = self.id; - /* add extra data to be POST:ed */ + /* Add extra data to be POST:ed. */ if ($.isFunction(settings.submitdata)) { $.extend(submitdata, settings.submitdata.apply(self, [self.revert, settings])); } else { $.extend(submitdata, settings.submitdata); } - /* quick and dirty PUT support */ + /* Quick and dirty PUT support. */ if ('PUT' == settings.method) { submitdata['_method'] = 'put'; } - /* show the saving indicator */ + /* Show the saving indicator. */ $(self).html(settings.indicator); - /* defaults for ajaxoptions */ + /* Defaults for ajaxoptions. */ var ajaxoptions = { type : 'POST', data : submitdata, + dataType: 'html', url : settings.target, success : function(result, status) { - $(self).html(result); + if (ajaxoptions.dataType == 'html') { + $(self).html(result); + } self.editing = false; - callback.apply(self, [self.innerHTML, settings]); + callback.apply(self, [result, settings]); if (!$.trim($(self).html())) { $(self).html(settings.placeholder); } @@ -343,9 +355,9 @@ error : function(xhr, status, error) { onerror.apply(form, [settings, self, xhr]); } - } + }; - /* override with what is given in settings.ajaxoptions */ + /* Override with what is given in settings.ajaxoptions. */ $.extend(ajaxoptions, settings.ajaxoptions); $.ajax(ajaxoptions); @@ -353,29 +365,31 @@ } } - /* show tooltip again */ + /* Show tooltip again. */ $(self).attr('title', settings.tooltip); return false; }); }); - /* privileged methods */ + /* Privileged methods */ this.reset = function(form) { - /* prevent calling reset twice when blurring */ + /* Prevent calling reset twice when blurring. */ if (this.editing) { - /* before reset hook, if it returns false abort reseting */ + /* Before reset hook, if it returns false abort reseting. */ if (false !== onreset.apply(form, [settings, self])) { $(self).html(self.revert); self.editing = false; if (!$.trim($(self).html())) { $(self).html(settings.placeholder); } - /* show tooltip again */ - $(self).attr('title', settings.tooltip); + /* Show tooltip again. */ + if (settings.tooltip) { + $(self).attr('title', settings.tooltip); + } } } - } + }; }); }; @@ -398,14 +412,14 @@ buttons : function(settings, original) { var form = this; if (settings.submit) { - /* if given html string use that */ + /* If given html string use that. */ if (settings.submit.match(/>$/)) { var submit = $(settings.submit).click(function() { if (submit.attr("type") != "submit") { form.submit(); } }); - /* otherwise use button with given string as text */ + /* Otherwise use button with given string as text. */ } else { var submit = $('