# HG changeset patch # User Thierry Florac # Date 1519291099 -3600 # Node ID 8e88640f4ef299f77aa6652e9555c8517ed60bad # Parent 9e3db98ce306c176b8275681c6e611c008aa4e65 Added change helper for Select2 plug-in diff -r 9e3db98ce306 -r 8e88640f4ef2 src/pyams_skin/resources/js/myams.js --- a/src/pyams_skin/resources/js/myams.js Tue Feb 20 11:56:27 2018 +0100 +++ b/src/pyams_skin/resources/js/myams.js Thu Feb 22 10:18:19 2018 +0100 @@ -2,7 +2,7 @@ * MyAMS * « My Application Management Skin » * - * $Tag: 0.1.13.1 $ (rev. 1) + * $Tag$ (rev. 1) * A bootstrap based application/administration skin * * Custom administration and application skin tools @@ -2545,21 +2545,16 @@ /** Select2 selection formatter */ select2FormatSelection: function(object, container) { - if (object instanceof Array) { - $(object).each(function() { - if (typeof(this) === 'object') { - container.append(this.text); - } else { - container.append(this); - } - }); - } else { - if (typeof(object) === 'object') { - container.append(object.text); + if (!(object instanceof Array)) { + object = [object]; + } + $(object).each(function() { + if (typeof(this) === 'object') { + container.append(this.text); } else { - container.append(object); + container.append(this); } - } + }); }, /** Select2 'select-all' helper */ @@ -2624,6 +2619,48 @@ } }, + /** Select2 helper to automate selection change */ + select2ChangeHelper: function() { + var source = $(this); + var data = source.data(); + var target = $(data.amsSelect2HelperTarget); + switch (data.amsSelect2HelperType) { + case 'html': + target.html('
'); + var params = {}; + params[data.amsSelect2HelperArgument || 'value'] = source.val(); + $.get(data.amsSelect2HelperUrl, params, + ams.getFunctionByName(data.amsSelect2HelperCallback) || function(result) { + if (result) { + target.html(result); + ams.initContent(target); + } else { + target.empty(); + } + }); + break; + case 'json-rpc': + target.html('
'); + ams.jsonrpc.post(data.amsSelect2HelperMethod, + {value: source.val()}, + {url: data.amsSelect2HelperUrl}, + ams.getFunctionByName(data.amsSelect2HelperCallback) || function(result) { + if (result.result) { + target.html(result.result); + ams.initContent(target); + } else { + target.empty(); + } + }); + break; + default: + var callback = data.amsSelect2HelperCallback; + if (callback) { + ams.executeFunctionByName(callback, source, data); + } + } + }, + /** Context menu handler */ contextMenuHandler: function(target, menu) { var menuData = menu.data(); @@ -3374,7 +3411,7 @@ var selects = $('.select2', element); if (selects.length > 0) { ams.ajax.check($.fn.select2, - ams.baseURL + 'ext/jquery-select2-3.5.2' + ams.devext + '.js', + ams.baseURL + 'ext/jquery-select2-3.5.4' + ams.devext + '.js', function() { selects.each(function() { var select = $(this); @@ -5917,6 +5954,9 @@ } var data = source.data(); if (data.amsChangeHandler) { + if ((data.amsStopPropagation === true) || (data.amsChangeStopPropagation === true)) { + event.stopPropagation(); + } if (data.amsChangeKeepDefault !== true) { event.preventDefault(); } diff -r 9e3db98ce306 -r 8e88640f4ef2 src/pyams_skin/resources/js/myams.min.js --- a/src/pyams_skin/resources/js/myams.min.js Tue Feb 20 11:56:27 2018 +0100 +++ b/src/pyams_skin/resources/js/myams.min.js Thu Feb 22 10:18:19 2018 +0100 @@ -1,1 +1,1 @@ -"use strict";!function(e,a){var t=a.console;String.prototype.startsWith=function(e){var a=this.length,t=e.length;return!(a0},void 0===e.scrollbarWidth&&(e.scrollbarWidth=function(){var a=e('
').appendTo("body"),t=a.children(),n=t.innerWidth()-t.height(99).innerWidth();return a.remove(),n}),e.fn.extend({exists:function(){return e(this).length>0},objectOrParentWithClass:function(e){return this.hasClass(e)?this:this.parents("."+e)},listattr:function(a){var t=[];return this.each(function(){t.push(e(this).attr(a))}),t},style:function(e,a,t){if(void 0!==this.get(0)){var n=this.get(0).style;return void 0!==e?void 0!==a?(t=void 0!==t?t:"",n.setProperty(e,a,t),this):n.getPropertyValue(e):n}},removeClassPrefix:function(a){return this.each(function(t,n){var s=n.className.split(" ").map(function(e){return e.startsWith(a)?"":e});n.className=e.trim(s.join(" "))}),this},contextMenu:function(a){function t(t,n,s){var i=e(window)[n](),o=e(a.menuSelector)[n](),r=t;return t+o>i&&o',openedSign:''},a),n=e(this);n.find("LI").each(function(){var a=e(this);if(a.find("UL").size()>0){a.find("A:first").append(""+t.closedSign+"");var n=a.find("A:first");"#"===n.attr("href")&&n.click(function(){return!1})}}),n.find("LI.active").each(function(){var a=e(this).parents("UL"),n=a.parent("LI");a.slideDown(t.speed),n.find("b:first").html(t.openedSign),n.addClass("open")}),n.find("LI A").on("click",function(){var a=e(this);if(!a.hasClass("active")){var s=a.attr("href").replace(/^#/,""),i=a.parent().find("UL");if(t.accordion){var o=a.parent().parents("UL"),r=n.find("UL:visible");r.each(function(a){var n=!0;if(o.each(function(e){if(o[e]===r[a])return n=!1,!1}),n&&i!==r[a]){var c=e(r[a]);!s&&c.hasClass("active")||c.slideUp(t.speed,function(){e(this).parent("LI").removeClass("open").find("B:first").delay(t.speed).html(t.closedSign)})}})}var c=a.parent().find("UL:first");s||!c.is(":visible")||c.hasClass("active")?c.slideDown(t.speed,function(){a.parent("LI").addClass("open").find("B:first").delay(t.speed).html(t.openedSign)}):c.slideUp(t.speed,function(){a.parent("LI").removeClass("open").find("B:first").delay(t.speed).html(t.closedSign)})}})}}),e.UTF8={encode:function(e){e=e.replace(/\r\n/g,"\n");for(var a="",t=0;t127&&n<2048?(a+=String.fromCharCode(n>>6|192),a+=String.fromCharCode(63&n|128)):(a+=String.fromCharCode(n>>12|224),a+=String.fromCharCode(n>>6&63|128),a+=String.fromCharCode(63&n|128))}return a},decode:function(e){for(var a="",t=0,n=0,s=0,i=0;t191&&n<224?(s=e.charCodeAt(t+1),a+=String.fromCharCode((31&n)<<6|63&s),t+=2):(s=e.charCodeAt(t+1),i=e.charCodeAt(t+2),a+=String.fromCharCode((15&n)<<12|(63&s)<<6|63&i),t+=3);return a}},void 0===a.MyAMS&&(a.MyAMS={devmode:!0,devext:"",lang:"en",throttleDelay:350,menuSpeed:235,navbarHeight:49,ajaxNav:!0,safeMethods:["GET","HEAD","OPTIONS","TRACE"],csrfCookieName:"csrf_token",csrfHeaderName:"X-CSRF-Token",enableWidgets:!0,enableMobile:!1,enableFastclick:!1,warnOnFormChange:!1,ismobile:/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase())});var n=a.MyAMS,s=n;n.baseURL=function(){var a=e('script[src*="/myams.js"], script[src*="/myams.min.js"]').attr("src");return s.devmode=a.indexOf(".min.js")<0,s.devext=s.devmode?"":".min",a.substring(0,a.lastIndexOf("/")+1)}(),n.log=function(){t&&t.debug&&t.debug(this,arguments)},n.getQueryVar=function(e,a){if(e.indexOf("?")<0)return!1;e.endsWith("&")||(e+="&");var t=new RegExp(".*?[&\\?]"+a+"=(.*?)&.*"),n=e.replace(t,"$1");return n!==e&&n},n.rgb2hex=function(a){return"#"+e.map(a.match(/\b(\d+)\b/g),function(e){return("0"+parseInt(e).toString(16)).slice(-2)}).join("")},n.generateId=function(){function e(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}return e()+e()+e()+e()},n.generateUUID=function(){var e=(new Date).getTime();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var t=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"===a?t:3&t|8).toString(16)})},n.getObject=function(e,a){if(e){if("string"!=typeof e)return e;var t=e.split(".");a=void 0===a||null===a?window:a;for(var n=0;n").attr("data-ams-id",t).text('@import "'+s.getSource(a)+'";'),n)var c=setInterval(function(){try{r[0].sheet.cssRules;n.call(window,!0,i),clearInterval(c)}catch(e){}},10);r.appendTo(o)}else n&&n.call(window,!1,i)},n.event={stop:function(e){e||(e=window.event),e&&(e.stopPropagation?(e.stopPropagation(),e.preventDefault()):(e.cancelBubble=!0,e.returnValue=!1))}},n.browser={getInternetExplorerVersion:function(){var e=-1;if("Microsoft Internet Explorer"===navigator.appName){var a=navigator.userAgent;null!==new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})").exec(a)&&(e=parseFloat(RegExp.$1))}return e},checkVersion:function(){var e="You're not using Windows Internet Explorer.",t=this.getInternetExplorerVersion();t>-1&&(e=t>=8?"You're using a recent copy of Windows Internet Explorer.":"You should upgrade your copy of Windows Internet Explorer."),a.alert&&a.alert(e)},isIE8orlower:function(){var e="0",a=this.getInternetExplorerVersion();return a>-1&&(e=a>=9?0:1),e},copyToClipboard:function(i){function o(i){var o=!1;if(window.clipboardData&&window.clipboardData.setData)o=clipboardData.setData("Text",i);else if(document.queryCommandSupported&&document.queryCommandSupported("copy")){var r=e("