Updated default widgets attributes and buttons
authorThierry Florac <thierry.florac@onf.fr>
Fri, 08 Dec 2017 11:40:56 +0100
changeset 247 9f1dded7e725
parent 246 4df479f75e07
child 248 86b71518e457
Updated default widgets attributes and buttons
src/pyams_skin/resources/js/myams-widgets.js
src/pyams_skin/resources/js/myams-widgets.min.js
--- a/src/pyams_skin/resources/js/myams-widgets.js	Sun Nov 26 10:14:42 2017 +0100
+++ b/src/pyams_skin/resources/js/myams-widgets.js	Fri Dec 08 11:40:56 2017 +0100
@@ -703,10 +703,10 @@
 		settingsKeyLabel: MyAMSWidget.i18n.SETTINGS_KEY_LABEL,
 		deletePositionKey: '',
 		positionKeyLabel: MyAMSWidget.i18n.POSITION_KEY_LABEL,
-		sortable: true,
+		sortable: false,
 		hiddenButtons: false,
 		// Toggle button
-		toggleButton: true,
+		toggleButton: false,
 		toggleClass: 'fa fa-minus|fa fa-plus',
 		toggleSpeed: 200,
 		onToggle: null,
--- a/src/pyams_skin/resources/js/myams-widgets.min.js	Sun Nov 26 10:14:42 2017 +0100
+++ b/src/pyams_skin/resources/js/myams-widgets.min.js	Fri Dec 08 11:40:56 2017 +0100
@@ -1,1 +1,1 @@
-(function(f,e){function c(h){if(h<10){h="0"+h}return h}function a(o,p){var h=new Date(o);var j=c(h.getMonth()+1);var l=c(h.getDate());var k=c(h.getFullYear());var m=c(h.getHours());var i=c(h.getMinutes());var n=c(h.getSeconds());return p.timestampFormat.replace(/%d%/g,l).replace(/%m%/g,j).replace(/%y%/g,k).replace(/%h%/g,m).replace(/%i%/g,i).replace(/%s%/g,n)}var g=e.MyAMS;function d(i,h){this.widget=i;this.options=f.extend({},b.defaults,h);this.grid=this.widget.parents(this.options.grid);this.hasGrid=this.grid.exists();this.gridId=this.grid.attr("id");this.controls=this.options.controls;this.toggleClass=this.options.toggleClass.split("|");this.editClass=this.options.editClass.split("|");this.fullscreenClass=this.options.fullscreenClass.split("|");this.customClass=this.options.customClass.split("|");this.init()}d.prototype={init:function(){var p=this;var j;if(p.options.rtl===true){f("body").addClass("rtl")}p.grid.each(function(){f(this).addClass("sortable-grid")});p._getSettings();if(p.hasGrid&&p.storage){var E;if(p.position){var C=JSON.parse(p.position);for(E in C.grid){if(!C.grid.hasOwnProperty(E)){continue}var A=p.grid.find(p.options.subgrid+".sortable-grid").eq(E);for(var B in C.grid[E].section){if(!C.grid[E].section.hasOwnProperty(B)){continue}A.append(f("#"+C.grid[E].section[B].id))}}}if(p.settings){var z=JSON.parse(p.settings);for(E in z.widget){if(!z.widget.hasOwnProperty(E)){continue}j=z.widget[E];if(!j.id){continue}var x=f("#"+j.id);if(!x.exists()){continue}if(j.style){x.removeClassPrefix("ams-widget-color-").addClass(j.style).attr("data-widget-attstyle",j.style)}if(j.hidden===1){x.hide(1)}else{x.show(1).removeAttr("data-widget-hidden")}if(j.collapsed===1){x.addClass("ams-widget-collapsed").children("div").hide(1)}var F=x.children("header").children("h2");if(F.text()!==j.title){F.text(j.title)}}}}j=p.widget;var D=j.data();var q={grid:D.amsWidgetGrid,subgrid:D.amsWudgetSubgrid,widgets:D.amsWidgetWidgets,controls:D.amsWidgetControls,storage:D.amsWidgetStorage,deleteSettingsKey:D.amsWidgetDeleteSettingsKey,deletePositionKey:D.amsWidgetDeletePositionKey,sortable:D.amsWidgetSortable,hiddenButtons:D.amsWidgetHiddenButtons,toggleButton:D.amsWidgetToggleButton,toggleClass:D.amsWidgetToggleClass,onToggle:g.getFunctionByName(D.amsWidgetToggleCallback),deleteButton:D.amsWidgetDeleteButton,deleteClass:D.amsWidgetDeleteClass,onDelete:g.getFunctionByName(D.amsWidgetDeleteCallback),editButton:D.amsWidgetEditButton,editPlaceholder:D.amsWidgetEditPlaceholder,editClass:D.amsWidgetEditClass,onEdit:g.getFunctionByName(D.amsWidgetEditCallback),fullscreenButton:D.amsWidgetFullscreenButton,fullscreenClass:D.amsWidgetFullscreenClass,fullscreenDiff:D.amsWidgetFullscreenDiff,onFullscreen:g.getFunctionByName(D.amsWidgetFullscreenCallback),customButton:D.amsWidgetCustomButton,customClass:D.amsWidgetCustomClass,customStart:g.getFunctionByName(D.amsWidgetCustomStartCallback),customEnd:g.getFunctionByName(D.amsWidgetCustomEndCallback),buttonsOrder:D.amsWidgetButtonsOrder,opacity:D.amsWidgetOpacity,dragHandle:D.amsWidgetDragHandle,placeholderClass:D.amsWidgetPlaceholderClass,indicator:D.amsWidgetIndicator,indicatorTime:D.amsWidgetIndicatorTime,ajax:D.amsWidgetAjax,timestampPlaceholder:D.amsWidgetTimestampPlaceholder,timestampFormat:D.amsWidgetTimestampFormat,refreshButton:D.amsWidgetRefreshButton,refreshClass:D.amsWidgetRefreshClass,errorLabel:D.amsWidgetErrorLabel,updatedLabel:D.amsWidgetUpdatedLabel,refreshLabel:D.amsWidgetRefreshLabel,deleteLabel:D.amsWidgetDeleteLabel,afterLoad:g.getFunctionByName(D.amsWidgetAfterLoadCallback),rtl:D.amsWidgetRtl,onChange:g.getFunctionByName(D.amsWidgetChangeCallback),onSave:g.getFunctionByName(D.amsWidgetSaveCallback),ajax_nav:g.ajax_nav};var y=f.extend({},p.options,q);var v=j.children("header");if(!v.parent().attr("role")){var u,r,m,i,o,t;if(D.widgetHidden===true){j.hide()}if(D.widgetCollapsed===true){j.addClass("ams-widget-collapsed").children("div").hide()}if(y.customButton&&(D.widgetCustombutton===undefined)&&(p.customClass[0].length!==0)){u='<a href="#" class="button-icon ams-widget-custom-btn"><i class="'+p.customClass[0]+'"></i></a>'}else{u=""}if(y.deleteButton&&(D.widgetDeleteButton===undefined)){r='<a href="#" class="button-icon ams-widget-delete-btn hint" title="'+b.i18n.DELETE_BTN+'" data-ams-hint-gravity="se"><i class="'+y.deleteClass+'"></i></a>'}else{r=""}if(y.editButton&&(D.widgetEditButton===undefined)){var k=y.editClass.split("|")[0];m='<a href="#" class="button-icon ams-widget-edit-btn hint" title="'+b.i18n.EDIT_BTN+'" data-ams-hint-gravity="se"><i class="'+k+'"></i></a>'}else{m=""}if(y.fullscreenButton&&(D.widgetFullscreenButton===undefined)){var n=y.fullscreenClass.split("|")[0];i='<a href="#" class="button-icon ams-widget-fullscreen-btn hint" title="'+b.i18n.FULLSCREEN_BTN+'" data-ams-hint-gravity="se"><i class="'+n+'"></i></a>'}else{i=""}if(y.toggleButton&&(D.widgetToggleButton===undefined)){var s=y.toggleClass.split("|");var h;if((j.dataWidgetCollapsed===true)||j.hasClass("ams-widget-collapsed")){h=s[1]}else{h=s[0]}o='<a href="#" class="button-icon ams-widget-toggle-btn hint" title="'+b.i18n.COLLAPSE_BTN+'" data-ams-hint-gravity="se"><i class="'+h+'"></i></a>'}else{o=""}if(y.refreshButton&&(D.widgetRefreshButton===undefined)&&D.widgetLoad){t='<a href="#" class="button-icon ams-widget-refresh-btn hint" title="'+b.i18n.REFRESH_BTN+'" data-loading-text="&nbsp;&nbsp;'+b.i18n.LOADING_MSG+'&nbsp;" data-ams-hint-gravity="se"><i class="'+y.refreshClass+'"></i></a>'}else{t=""}var w=y.buttonsOrder.replace(/%refresh%/,t).replace(/%custom%/,u).replace(/%edit%/,m).replace(/%toggle%/,o).replace(/%fullscreen%/,i).replace(/%delete%/,r);if(t||u||m||o||i||r){v.prepend('<div class="ams-widget-ctrls">'+w+"</div>")}if(y.sortable&&(D.widgetSortable===undefined)){j.addClass("ams-widget-sortable")}var l=j.find(y.editPlaceholder);if(l.length>0){l.find("input").val(f.trim(v.children("h2").text()))}v.append('<span class="ams-widget-loader"><i class="fa fa-refresh fa-spin"></i></span>');j.attr("role","widget").children("div").attr("role","content").prev("header").attr("role","heading").children("div").attr("role","menu");g.plugins.enabled.hint(v)}j.data("widget-options",y);if(p.options.hiddenButtons){f(p.controls).hide()}j.find("[data-widget-load]").each(function(){var I=f(this),K=I.children(),J=I.data("widget-load"),H=I.data("widget-refresh")*1000,G=K;if(I.find(".ams-widget-ajax-placeholder").length<=0){I.children("widget-body").append('<div class="ams-widget-ajax-placeholder">'+p.options.loadingLabel+"</div>");if(H>0){p.loadAjaxFile(I,J,K);setInterval(function(){p._loadAjaxFile(I,J,K)},H)}else{p._loadAjaxFile(I,J,K)}}});if(p.options.hiddenButtons){p.widget.children("header").hover(function(){f(this).children(p.controls).stop(true,true).fadeTo(100,1)},function(){f(this).children(p.controls).stop(true,true).fadeTo(100,0)})}p._setClickEvents();f(p.options.deleteSettingsKey).on(p.clickEvent,this,function(H){if(p.storage&&e.confirm){var G=e.confirm(p.options.settingsKeyLabel);if(G){p.storage.removeItem(p.settingsKey)}}H.preventDefault()});f(p.options.deletePositionKey).on(p.clickEvent,this,function(H){if(p.storage&&e.confirm){var G=e.confirm(p.options.positionKeyLabel);if(G){p.storage.removeItem(p.positionKey)}}H.preventDefault()});if(p.storage){if(p.settingsKey===null||p.settingsKey.length<1){p._saveWidgetSettings()}if(p.positionKey===null||p.positionKey.length<1){p._saveWidgetPosition()}}p.grid.data("ams-widgets-loaded",true)},destroy:function(){var h=this;h.widgets.off("click",h._setClickEvents());h.element.removeData("AMSWidget")},_getSettings:function(){var i=this;if(!i.hasGrid||!i.gridId){i.storage=null}else{switch(i.options.storage){case"local":i.storage=localStorage;break;case"session":i.storage=sessionStorage;break;default:i.storage=null}}var h=(i.storage!==null)&&function(){var j,k=+new Date();try{i.storage.setItem(k,k);j=parseInt(i.storage.getItem(k))===k;i.storage.removeItem(k);return j}catch(l){}}();if(h){i.settingsKey="AMS_settings_"+location.pathname+location.hash+"_"+i.gridId;i.settings=i.storage.getItem(i.settingsKey);i.positionKey="AMS_position_"+location.pathname+location.hash+"_"+i.gridId;i.position=i.storage.getItem(i.positionKey)}if(("ontouchstart" in e)||e.DocumentTouch&&e.document instanceof e.DocumentTouch){i.clickEvent="touchstart"}else{i.clickEvent="click"}},_runLoaderWidget:function(i){var h=this;if(h.options.indicator){i.find(".ams-widget-loader").stop(true,true).fadeIn(100).delay(h.options.indicatorTime).fadeOut(100)}},_loadAjaxFile:function(i,j,h){g.skin.loadURL(i,j.find(".widget-body"))},_saveWidgetSettings:function(){var i=this;i._getSettings();if(i.storage){var h=[];i.grid.find(i.options.widgets).each(function(){var l=f(this);var k={};k.id=l.attr("id");k.style=l.attr("data-widget-attstyle");k.title=l.children("header").children("h2").text();k.hidden=l.is(":hidden")?1:0;k.collapsed=l.hasClass("ams-widget-collapsed")?1:0;h.push(k)});var j=JSON.stringify({widget:h});if(i.settings!==j){i.storage.setItem(i.settingsKey,j)}if(typeof(i.options.onSave)==="function"){i.options.onSave.call(this,null,h)}}},_saveWidgetPosition:function(){var i=this;i._getSettings();if(i.storage){var j=[];i.grid.find(i.options.subgrid+".sortable-grid").each(function(){var k=[];f(this).children(i.options.widgets).each(function(){var m={};m.id=f(this).attr("id");k.push(m)});var l={section:k};j.push(l)});var h=JSON.stringify({grid:j});if(i.position!==h){i.storage.setItem(i.positionKey,h)}if(typeof(i.options.onSave)==="function"){i.options.onSave.call(this,null,j)}}},_setClickEvents:function(){function i(){var l=f("#ams-widget-fullscreen-mode");if(l.length>0){var k=l.find(h.options.widgets);var m=f(window).height();var j=k.children("header").height();k.children("div").height(m-j-15)}}var h=this;h._getSettings();h.widget.on(h.clickEvent,".ams-widget-toggle-btn",function(n){n.preventDefault();var k=f(this);var l=k.parents(h.options.widgets).first();var o=l.data("widget-options");var j=o.toggleClass.split("|");h._runLoaderWidget(l);var m=true;if(l.hasClass("ams-widget-collapsed")){if(o.onToggle){m=o.onToggle.call(this,l,"expand")}if(m!==false){k.children().removeClass(j[1]).addClass(j[0]);l.removeClass("ams-widget-collapsed").children("[role=content]").slideDown(o.toggleSpeed,function(){h._saveWidgetSettings()})}}else{if(o.onToggle){m=o.onToggle.call(this,l,"collapse")}if(m!==false){k.children().removeClass(j[0]).addClass(j[1]);l.addClass("ams-widget-collapsed").children("[role=content]").slideUp(o.toggleSpeed,function(){h._saveWidgetSettings()})}}});h.widget.on("dblclick","header",function(j){f(".ams-widget-toggle-btn",this).click()});h.widget.on(h.clickEvent,".ams-widget-fullscreen-btn",function(n){n.preventDefault();var k=f(this);var m=k.parents(h.options.widgets);var o=m.data("widget-options");var j=o.fullscreenClass.split("|");var l=m.children("div");h._runLoaderWidget(m);if(f("#ams-widget-fullscreen-mode").length>0){f(".nooverflow").removeClass("nooverflow");m.unwrap("<div>").children("div").removeAttr("style").end().find(".ams-widget-fullscreen-btn").children().removeClass(j[1]).addClass(j[0]).parents(h.controls).children("a").show();if(l.hasClass("ams-widget-visible")){l.hide().removeClass("ams-widget-visible")}}else{f("body").addClass("nooverflow");m.wrap('<div id="ams-widget-fullscreen-mode"></div>').parent().find(".ams-widget-fullscreen-btn").children().removeClass(j[0]).addClass(j[1]).parents(h.controls).children("a:not(.ams-widget-fullscreen-btn)").hide();if(l.is(":hidden")){l.show().addClass("ams-widget-visible")}}i();if(typeof(o.onFullscreen)==="function"){o.onFullscreen.call(this,m)}});f(window).resize(function(){i()});h.widget.on(h.clickEvent,".ams-widget-edit-btn",function(m){m.preventDefault();var k=f(this);var l=k.parents(h.options.widgets);var o=l.data("widget-options");var j=o.editClass.split("|");h._runLoaderWidget(l);var n=l.find(o.editPlaceholder);if(n.is(":visible")){k.children().removeClass(j[1]).addClass(j[0]);n.slideUp(o.editSpeed,function(){h._saveWidgetSettings()})}else{k.children().removeClass(j[0]).addClass(j[1]);n.slideDown(o.editSpeed)}if(typeof(o.onEdit)==="function"){o.onEdit.call(this,l)}});f(h.options.editPlaceholder).find("input").keyup(function(){f(this).parents(h.options.widgets).children("header").children("h2").text(f(this).val())});h.widget.on(h.clickEvent,".ams-widget-custom-btn",function(m){m.preventDefault();var j=f(this);var l=j.parents(h.options.widgets);var n=l.data("widget-options");var k=n.customClass.split("|");h._runLoaderWidget(l);if(j.children("."+k[0]).length>0){j.children().removeClass(k[0]).addClass(k[1]);if(typeof(n.customStart)==="function"){n.customStart.call(this,l)}}else{j.children("."+k[1]).addClass(k[0]);if(typeof(n.customEnd)==="function"){n.customEnd.call(this,l)}}h._saveWidgetSettings()});h.widget.on(h.clickEvent,".ams-widget-delete-btn",function(l){l.preventDefault();var j=f(this);var k=j.parents(h.options.widgets);var o=k.data("widget-options");var n=k.attr("id");var m=k.children("header").children("h2").text();g.ajax.check(g.notify,g.baseURL+"myams-notify"+(g.devmode?".js":".min.js"),function(){g.notify.messageBox({title:'<i class="fa fa-times" style="color: #ed1c24;"></i> '+o.deleteLabel+' "'+m+'"',content:b.i18n.DELETE_MSG,buttons:"["+g.i18n.BTN_OK+"]["+g.i18n.BTN_CANCEL+"]"},function(p){if(p===g.i18n.BTN_OK){h._runLoaderWidget(k);f("#"+n).fadeOut(o.deleteSpeed,function(){j.remove();if(typeof(o.onDelete)==="function"){o.onDelete.call(this,k)}})}})})});h.widget.on(h.clickEvent,".ams-widget-refresh-btn",function(n){n.preventDefault();var k=f(this);var l=k.parents(h.options.widgets);var m=l.data("widget-load");var j=l.children();k.button("loading");j.addClass("widget-body-ajax-loading");setTimeout(function(){k.button("reset");j.removeClass("widget-body-ajax-loading");h._loadAjaxFile(l,m,j)},1000)})}};var b={i18n:f.extend({SETTINGS_KEY_LABEL:"Reset settings?",POSITION_KEY_LABEL:"Reset position?",TIMESTAMP_FORMAT:"Last update: %d%/%m%/%y% %h%:%i%:%s",ERROR_LABEL:"An error occured: ",UPDATED_LABEL:"Last update: ",REFRESH_LABEL:"Refresh",EDIT_BTN:"Edit title",DELETE_BTN:"Delete",DELETE_LABEL:"Remove component: ",DELETE_MSG:"WARNING: this action can't be undone!",FULLSCREEN_BTN:"Fullscreen",COLLAPSE_BTN:"Collapse",REFRESH_BTN:"Reload content",LOADING_MSG:"Loading..."},g.plugins.i18n.widgets),initWidgetsGrid:function(i){if(!i.exists()){return}var h=f(".ams-widget:first",i).data("AMSWidget").options;if(h.sortable&&f.ui){var j=i.find(".sortable-grid").not("[data-widget-excludegrid]");j.sortable({items:j.find(".ams-widget-sortable"),connectWith:j,placeholder:h.placeholderClass,cursor:"move",revert:true,opacity:h.opacity,delay:200,cancel:".button-icon, #ams-widget-fullscreen-mode >div",zIndex:10000,handle:h.dragHandle,forcePlaceholderSize:true,forceHelperSize:true,update:function(k,m){var l=m.item.data("AMSWidget");l._runLoaderWidget(l.widget);l._saveWidgetPosition();if(typeof(h.onChange)==="function"){h.onChange.call(this,m.item)}}})}}};b.defaults={grid:".ams-widget-grid",subgrid:"section",widgets:".ams-widget",controls:".ams-widget-ctrls",storage:"local",deleteSettingsKey:"",settingsKeyLabel:b.i18n.SETTINGS_KEY_LABEL,deletePositionKey:"",positionKeyLabel:b.i18n.POSITION_KEY_LABEL,sortable:true,hiddenButtons:false,toggleButton:true,toggleClass:"fa fa-minus|fa fa-plus",toggleSpeed:200,onToggle:null,deleteButton:false,deleteClass:"fa fa-times",deleteSpeed:200,onDelete:null,editButton:false,editPlaceholder:".ams-widget-editbox",editClass:"fa fa-cog|fa fa-save",editSpeed:200,onEdit:null,fullscreenButton:false,fullscreenClass:"fa fa-expand|fa fa-compress",fullscreenDiff:3,onFullscreen:null,customButton:false,customClass:"folder-10|next-10",customStart:null,customEnd:null,buttonsOrder:"%refresh% %custom% %edit% %toggle% %fullscreen% %delete%",opacity:1,dragHandle:"> header",placeholderClass:"ams-widget-placeholder",indicator:true,indicatorTime:600,ajax:true,timestampPlaceholder:".ams-widget-timestamp",timestampFormat:b.i18n.TIMESTAMP_FORMAT,refreshButton:true,refreshButtonClass:"fa fa-refresh",errorLabel:b.i18n.ERROR_LABEL,updatedLabel:b.i18n.UPDATED_LABEL,refreshLabel:b.i18n.REFRESH_LABEL,deleteLabel:b.i18n.DELETE_LABEL,afterLoad:null,rtl:false,onChange:null,onSave:null,ajax_nav:g.ajax_nav};e.MyAMSWidget=b;f.fn.extend({MyAMSWidget:function(h){return this.each(function(){var n=f(this);var m=n.data("AMSWidget");if(!m){var j=n.parents(h.grid||b.defaults.grid);var l={};if(j.exists()){var i=j.data();l={grid:i.amsWidgetGrid,subgrid:i.amsWidgetSubgrid,controls:i.amsWidgetControls,storage:i.amsWidgetStorage,deleteSettingsKey:i.amsWidgetDeleteSettingsKey,deletePositionKey:i.amsWidgetDeletePositionKey,sortable:i.amsWidgetSortable,hiddenButtons:i.amsWidgetHiddenButtons,toggleButton:i.amsWidgetToggleButton,toggleClass:i.amsWidgetToggleClass,onToggle:g.getFunctionByName(i.amsWidgetToggleCallback),deleteButton:i.amsWidgetDeleteButton,deleteClass:i.amsWidgetDeleteClass,onDelete:g.getFunctionByName(i.amsWidgetDeleteCallback),editButton:i.amsWidgetEditButton,editPlaceholder:i.amsWidgetEditPlaceholder,editClass:i.amsWidgetEditClass,onEdit:g.getFunctionByName(i.amsWidgetEditCallback),fullscreenButton:i.amsWidgetFullscreenButton,fullscreenClass:i.amsWidgetFullscreenClass,fullscreenDiff:i.amsWidgetFullscreenDiff,onFullscreen:g.getFunctionByName(i.amsWidgetFullscreenCallback),customButton:i.amsWidgetCustomButton,customClass:i.amsWidgetCustomClass,customStart:g.getFunctionByName(i.amsWidgetCustomStartCallback),customEnd:g.getFunctionByName(i.amsWidgetCustomStartCallback),buttonsOrder:i.amsWidgetButtonsOrder,opacity:i.amsWidgetOpacity,dragHandle:i.amsWidgetDragHandle,placeholderClass:i.amsWidgetPlaceholderClass,indicator:i.amsWidgetIndicator,indicatorTime:i.amsWidgetIndicatorTime,ajax:i.amsWidgetAjax,timestampPlaceholder:i.amsWidgetTimestampPlaceholder,timestampFormat:i.amsWidgetTimestampFormat,refreshButton:i.amsWidgetRefreshButton,refreshClass:i.amsWidgetRefreshClass,errorLabel:i.amsWidgetErrorLabel,updatedLabel:i.amsWidgetUpdatedLabel,refreshLabel:i.amsWidgetRefreshLabel,deleteLabel:i.amsWidgetDeleteLabel,afterLoad:g.getFunctionByName(i.amsWidgetAfterLoadCallback),rtl:i.amsWidgetRtl,onChange:g.getFunctionByName(i.amsWidgetChangeCallback),onSave:g.getFunctionByName(i.amsWidgetSaveCallback),ajax_nav:g.ajax_nav}}var k=f.fn.extend({},l,n.data("ams-widget-options")||{},h);n.data("AMSWidget",new d(n,k))}})}})})(jQuery,this);
\ No newline at end of file
+!function(e,t){"use strict";function i(t,i){this.widget=t,this.options=e.extend({},a.defaults,i),this.grid=this.widget.parents(this.options.grid),this.hasGrid=this.grid.exists(),this.gridId=this.grid.attr("id"),this.controls=this.options.controls,this.toggleClass=this.options.toggleClass.split("|"),this.editClass=this.options.editClass.split("|"),this.fullscreenClass=this.options.fullscreenClass.split("|"),this.customClass=this.options.customClass.split("|"),this.init()}var s=t.MyAMS;i.prototype={init:function(){var i,n=this;if(!0===n.options.rtl&&e("body").addClass("rtl"),n.grid.each(function(){e(this).addClass("sortable-grid")}),n._getSettings(),n.hasGrid&&n.storage){var d;if(n.position){var o=JSON.parse(n.position);for(d in o.grid)if(o.grid.hasOwnProperty(d)){var l=n.grid.find(n.options.subgrid+".sortable-grid").eq(d);for(var r in o.grid[d].section)o.grid[d].section.hasOwnProperty(r)&&l.append(e("#"+o.grid[d].section[r].id))}}if(n.settings){var g=JSON.parse(n.settings);for(d in g.widget)if(g.widget.hasOwnProperty(d)&&(i=g.widget[d]).id){var c=e("#"+i.id);if(c.exists()){i.style&&c.removeClassPrefix("ams-widget-color-").addClass(i.style).attr("data-widget-attstyle",i.style),1===i.hidden?c.hide(1):c.show(1).removeAttr("data-widget-hidden"),1===i.collapsed&&c.addClass("ams-widget-collapsed").children("div").hide(1);var m=c.children("header").children("h2");m.text()!==i.title&&m.text(i.title)}}}}var u=(i=n.widget).data(),h={grid:u.amsWidgetGrid,subgrid:u.amsWudgetSubgrid,widgets:u.amsWidgetWidgets,controls:u.amsWidgetControls,storage:u.amsWidgetStorage,deleteSettingsKey:u.amsWidgetDeleteSettingsKey,deletePositionKey:u.amsWidgetDeletePositionKey,sortable:u.amsWidgetSortable,hiddenButtons:u.amsWidgetHiddenButtons,toggleButton:u.amsWidgetToggleButton,toggleClass:u.amsWidgetToggleClass,onToggle:s.getFunctionByName(u.amsWidgetToggleCallback),deleteButton:u.amsWidgetDeleteButton,deleteClass:u.amsWidgetDeleteClass,onDelete:s.getFunctionByName(u.amsWidgetDeleteCallback),editButton:u.amsWidgetEditButton,editPlaceholder:u.amsWidgetEditPlaceholder,editClass:u.amsWidgetEditClass,onEdit:s.getFunctionByName(u.amsWidgetEditCallback),fullscreenButton:u.amsWidgetFullscreenButton,fullscreenClass:u.amsWidgetFullscreenClass,fullscreenDiff:u.amsWidgetFullscreenDiff,onFullscreen:s.getFunctionByName(u.amsWidgetFullscreenCallback),customButton:u.amsWidgetCustomButton,customClass:u.amsWidgetCustomClass,customStart:s.getFunctionByName(u.amsWidgetCustomStartCallback),customEnd:s.getFunctionByName(u.amsWidgetCustomEndCallback),buttonsOrder:u.amsWidgetButtonsOrder,opacity:u.amsWidgetOpacity,dragHandle:u.amsWidgetDragHandle,placeholderClass:u.amsWidgetPlaceholderClass,indicator:u.amsWidgetIndicator,indicatorTime:u.amsWidgetIndicatorTime,ajax:u.amsWidgetAjax,timestampPlaceholder:u.amsWidgetTimestampPlaceholder,timestampFormat:u.amsWidgetTimestampFormat,refreshButton:u.amsWidgetRefreshButton,refreshClass:u.amsWidgetRefreshClass,errorLabel:u.amsWidgetErrorLabel,updatedLabel:u.amsWidgetUpdatedLabel,refreshLabel:u.amsWidgetRefreshLabel,deleteLabel:u.amsWidgetDeleteLabel,afterLoad:s.getFunctionByName(u.amsWidgetAfterLoadCallback),rtl:u.amsWidgetRtl,onChange:s.getFunctionByName(u.amsWidgetChangeCallback),onSave:s.getFunctionByName(u.amsWidgetSaveCallback),ajax_nav:s.ajax_nav},f=e.extend({},n.options,h),p=i.children("header");if(!p.parent().attr("role")){var v,C,w,W,b,y;if(!0===u.widgetHidden&&i.hide(),!0===u.widgetCollapsed&&i.addClass("ams-widget-collapsed").children("div").hide(),v=f.customButton&&void 0===u.widgetCustombutton&&0!==n.customClass[0].length?'<a href="#" class="button-icon ams-widget-custom-btn"><i class="'+n.customClass[0]+'"></i></a>':"",C=f.deleteButton&&void 0===u.widgetDeleteButton?'<a href="#" class="button-icon ams-widget-delete-btn hint" title="'+a.i18n.DELETE_BTN+'" data-ams-hint-gravity="se"><i class="'+f.deleteClass+'"></i></a>':"",f.editButton&&void 0===u.widgetEditButton){var B=f.editClass.split("|")[0];w='<a href="#" class="button-icon ams-widget-edit-btn hint" title="'+a.i18n.EDIT_BTN+'" data-ams-hint-gravity="se"><i class="'+B+'"></i></a>'}else w="";if(f.fullscreenButton&&void 0===u.widgetFullscreenButton){var E=f.fullscreenClass.split("|")[0];W='<a href="#" class="button-icon ams-widget-fullscreen-btn hint" title="'+a.i18n.FULLSCREEN_BTN+'" data-ams-hint-gravity="se"><i class="'+E+'"></i></a>'}else W="";if(f.toggleButton&&void 0===u.widgetToggleButton){var S,L=f.toggleClass.split("|");S=!0===i.dataWidgetCollapsed||i.hasClass("ams-widget-collapsed")?L[1]:L[0],b='<a href="#" class="button-icon ams-widget-toggle-btn hint" title="'+a.i18n.COLLAPSE_BTN+'" data-ams-hint-gravity="se"><i class="'+S+'"></i></a>'}else b="";y=f.refreshButton&&void 0===u.widgetRefreshButton&&u.widgetLoad?'<a href="#" class="button-icon ams-widget-refresh-btn hint" title="'+a.i18n.REFRESH_BTN+'" data-loading-text="&nbsp;&nbsp;'+a.i18n.LOADING_MSG+'&nbsp;" data-ams-hint-gravity="se"><i class="'+f.refreshClass+'"></i></a>':"";var _=f.buttonsOrder.replace(/%refresh%/,y).replace(/%custom%/,v).replace(/%edit%/,w).replace(/%toggle%/,b).replace(/%fullscreen%/,W).replace(/%delete%/,C);(y||v||w||b||W||C)&&p.prepend('<div class="ams-widget-ctrls">'+_+"</div>"),f.sortable&&void 0===u.widgetSortable&&i.addClass("ams-widget-sortable");var T=i.find(f.editPlaceholder);T.length>0&&T.find("input").val(e.trim(p.children("h2").text())),p.append('<span class="ams-widget-loader"><i class="fa fa-refresh fa-spin"></i></span>'),i.attr("role","widget").children("div").attr("role","content").prev("header").attr("role","heading").children("div").attr("role","menu"),s.plugins.enabled.hint(p)}i.data("widget-options",f),n.options.hiddenButtons&&e(n.controls).hide(),i.find("[data-widget-load]").each(function(){var t=e(this),i=t.children(),s=t.data("widget-load"),a=1e3*t.data("widget-refresh");t.find(".ams-widget-ajax-placeholder").length<=0&&(t.children("widget-body").append('<div class="ams-widget-ajax-placeholder">'+n.options.loadingLabel+"</div>"),a>0?(n.loadAjaxFile(t,s,i),setInterval(function(){n._loadAjaxFile(t,s,i)},a)):n._loadAjaxFile(t,s,i))}),n.options.hiddenButtons&&n.widget.children("header").hover(function(){e(this).children(n.controls).stop(!0,!0).fadeTo(100,1)},function(){e(this).children(n.controls).stop(!0,!0).fadeTo(100,0)}),n._setClickEvents(),e(n.options.deleteSettingsKey).on(n.clickEvent,this,function(e){n.storage&&t.confirm&&t.confirm(n.options.settingsKeyLabel)&&n.storage.removeItem(n.settingsKey),e.preventDefault()}),e(n.options.deletePositionKey).on(n.clickEvent,this,function(e){n.storage&&t.confirm&&t.confirm(n.options.positionKeyLabel)&&n.storage.removeItem(n.positionKey),e.preventDefault()}),n.storage&&((null===n.settingsKey||n.settingsKey.length<1)&&n._saveWidgetSettings(),(null===n.positionKey||n.positionKey.length<1)&&n._saveWidgetPosition()),n.grid.data("ams-widgets-loaded",!0)},destroy:function(){var e=this;e.widgets.off("click",e._setClickEvents()),e.element.removeData("AMSWidget")},_getSettings:function(){var e=this;if(e.hasGrid&&e.gridId)switch(e.options.storage){case"local":e.storage=localStorage;break;case"session":e.storage=sessionStorage;break;default:e.storage=null}else e.storage=null;null!==e.storage&&function(){var t,i=+new Date;try{return e.storage.setItem(i,i),t=parseInt(e.storage.getItem(i))===i,e.storage.removeItem(i),t}catch(e){}}()&&(e.settingsKey="AMS_settings_"+location.pathname+location.hash+"_"+e.gridId,e.settings=e.storage.getItem(e.settingsKey),e.positionKey="AMS_position_"+location.pathname+location.hash+"_"+e.gridId,e.position=e.storage.getItem(e.positionKey)),"ontouchstart"in t||t.DocumentTouch&&t.document instanceof t.DocumentTouch?e.clickEvent="touchstart":e.clickEvent="click"},_runLoaderWidget:function(e){var t=this;t.options.indicator&&e.find(".ams-widget-loader").stop(!0,!0).fadeIn(100).delay(t.options.indicatorTime).fadeOut(100)},_loadAjaxFile:function(e,t,i){s.skin.loadURL(e,t.find(".widget-body"))},_saveWidgetSettings:function(){var t=this;if(t._getSettings(),t.storage){var i=[];t.grid.find(t.options.widgets).each(function(){var t=e(this),s={};s.id=t.attr("id"),s.style=t.attr("data-widget-attstyle"),s.title=t.children("header").children("h2").text(),s.hidden=t.is(":hidden")?1:0,s.collapsed=t.hasClass("ams-widget-collapsed")?1:0,i.push(s)});var s=JSON.stringify({widget:i});t.settings!==s&&t.storage.setItem(t.settingsKey,s),"function"==typeof t.options.onSave&&t.options.onSave.call(this,null,i)}},_saveWidgetPosition:function(){var t=this;if(t._getSettings(),t.storage){var i=[];t.grid.find(t.options.subgrid+".sortable-grid").each(function(){var s=[];e(this).children(t.options.widgets).each(function(){var t={};t.id=e(this).attr("id"),s.push(t)});var a={section:s};i.push(a)});var s=JSON.stringify({grid:i});t.position!==s&&t.storage.setItem(t.positionKey,s),"function"==typeof t.options.onSave&&t.options.onSave.call(this,null,i)}},_setClickEvents:function(){function t(){var t=e("#ams-widget-fullscreen-mode");if(t.length>0){var s=t.find(i.options.widgets),a=e(window).height(),n=s.children("header").height();s.children("div").height(a-n-15)}}var i=this;i._getSettings(),i.widget.on(i.clickEvent,".ams-widget-toggle-btn",function(t){t.preventDefault();var s=e(this),a=s.parents(i.options.widgets).first(),n=a.data("widget-options"),d=n.toggleClass.split("|");i._runLoaderWidget(a);var o=!0;a.hasClass("ams-widget-collapsed")?(n.onToggle&&(o=n.onToggle.call(this,a,"expand")),!1!==o&&(s.children().removeClass(d[1]).addClass(d[0]),a.removeClass("ams-widget-collapsed").children("[role=content]").slideDown(n.toggleSpeed,function(){i._saveWidgetSettings()}))):(n.onToggle&&(o=n.onToggle.call(this,a,"collapse")),!1!==o&&(s.children().removeClass(d[0]).addClass(d[1]),a.addClass("ams-widget-collapsed").children("[role=content]").slideUp(n.toggleSpeed,function(){i._saveWidgetSettings()})))}),i.widget.on("dblclick","header",function(t){e(".ams-widget-toggle-btn",this).click()}),i.widget.on(i.clickEvent,".ams-widget-fullscreen-btn",function(s){s.preventDefault();var a=e(this).parents(i.options.widgets),n=a.data("widget-options"),d=n.fullscreenClass.split("|"),o=a.children("div");i._runLoaderWidget(a),e("#ams-widget-fullscreen-mode").length>0?(e(".nooverflow").removeClass("nooverflow"),a.unwrap("<div>").children("div").removeAttr("style").end().find(".ams-widget-fullscreen-btn").children().removeClass(d[1]).addClass(d[0]).parents(i.controls).children("a").show(),o.hasClass("ams-widget-visible")&&o.hide().removeClass("ams-widget-visible")):(e("body").addClass("nooverflow"),a.wrap('<div id="ams-widget-fullscreen-mode"></div>').parent().find(".ams-widget-fullscreen-btn").children().removeClass(d[0]).addClass(d[1]).parents(i.controls).children("a:not(.ams-widget-fullscreen-btn)").hide(),o.is(":hidden")&&o.show().addClass("ams-widget-visible")),t(),"function"==typeof n.onFullscreen&&n.onFullscreen.call(this,a)}),e(window).resize(function(){t()}),i.widget.on(i.clickEvent,".ams-widget-edit-btn",function(t){t.preventDefault();var s=e(this),a=s.parents(i.options.widgets),n=a.data("widget-options"),d=n.editClass.split("|");i._runLoaderWidget(a);var o=a.find(n.editPlaceholder);o.is(":visible")?(s.children().removeClass(d[1]).addClass(d[0]),o.slideUp(n.editSpeed,function(){i._saveWidgetSettings()})):(s.children().removeClass(d[0]).addClass(d[1]),o.slideDown(n.editSpeed)),"function"==typeof n.onEdit&&n.onEdit.call(this,a)}),e(i.options.editPlaceholder).find("input").keyup(function(){e(this).parents(i.options.widgets).children("header").children("h2").text(e(this).val())}),i.widget.on(i.clickEvent,".ams-widget-custom-btn",function(t){t.preventDefault();var s=e(this),a=s.parents(i.options.widgets),n=a.data("widget-options"),d=n.customClass.split("|");i._runLoaderWidget(a),s.children("."+d[0]).length>0?(s.children().removeClass(d[0]).addClass(d[1]),"function"==typeof n.customStart&&n.customStart.call(this,a)):(s.children("."+d[1]).addClass(d[0]),"function"==typeof n.customEnd&&n.customEnd.call(this,a)),i._saveWidgetSettings()}),i.widget.on(i.clickEvent,".ams-widget-delete-btn",function(t){t.preventDefault();var n=e(this),d=n.parents(i.options.widgets),o=d.data("widget-options"),l=d.attr("id"),r=d.children("header").children("h2").text();s.ajax.check(s.notify,s.baseURL+"myams-notify"+(s.devmode?".js":".min.js"),function(){s.notify.messageBox({title:'<i class="fa fa-times" style="color: #ed1c24;"></i> '+o.deleteLabel+' "'+r+'"',content:a.i18n.DELETE_MSG,buttons:"["+s.i18n.BTN_OK+"]["+s.i18n.BTN_CANCEL+"]"},function(t){t===s.i18n.BTN_OK&&(i._runLoaderWidget(d),e("#"+l).fadeOut(o.deleteSpeed,function(){n.remove(),"function"==typeof o.onDelete&&o.onDelete.call(this,d)}))})})}),i.widget.on(i.clickEvent,".ams-widget-refresh-btn",function(t){t.preventDefault();var s=e(this),a=s.parents(i.options.widgets),n=a.data("widget-load"),d=a.children();s.button("loading"),d.addClass("widget-body-ajax-loading"),setTimeout(function(){s.button("reset"),d.removeClass("widget-body-ajax-loading"),i._loadAjaxFile(a,n,d)},1e3)})}};var a={i18n:e.extend({SETTINGS_KEY_LABEL:"Reset settings?",POSITION_KEY_LABEL:"Reset position?",TIMESTAMP_FORMAT:"Last update: %d%/%m%/%y% %h%:%i%:%s",ERROR_LABEL:"An error occured: ",UPDATED_LABEL:"Last update: ",REFRESH_LABEL:"Refresh",EDIT_BTN:"Edit title",DELETE_BTN:"Delete",DELETE_LABEL:"Remove component: ",DELETE_MSG:"WARNING: this action can't be undone!",FULLSCREEN_BTN:"Fullscreen",COLLAPSE_BTN:"Collapse",REFRESH_BTN:"Reload content",LOADING_MSG:"Loading..."},s.plugins.i18n.widgets),initWidgetsGrid:function(t){if(t.exists()){var i=e(".ams-widget:first",t).data("AMSWidget").options;if(i.sortable&&e.ui){var s=t.find(".sortable-grid").not("[data-widget-excludegrid]");s.sortable({items:s.find(".ams-widget-sortable"),connectWith:s,placeholder:i.placeholderClass,cursor:"move",revert:!0,opacity:i.opacity,delay:200,cancel:".button-icon, #ams-widget-fullscreen-mode >div",zIndex:1e4,handle:i.dragHandle,forcePlaceholderSize:!0,forceHelperSize:!0,update:function(e,t){var s=t.item.data("AMSWidget");s._runLoaderWidget(s.widget),s._saveWidgetPosition(),"function"==typeof i.onChange&&i.onChange.call(this,t.item)}})}}}};a.defaults={grid:".ams-widget-grid",subgrid:"section",widgets:".ams-widget",controls:".ams-widget-ctrls",storage:"local",deleteSettingsKey:"",settingsKeyLabel:a.i18n.SETTINGS_KEY_LABEL,deletePositionKey:"",positionKeyLabel:a.i18n.POSITION_KEY_LABEL,sortable:!1,hiddenButtons:!1,toggleButton:!1,toggleClass:"fa fa-minus|fa fa-plus",toggleSpeed:200,onToggle:null,deleteButton:!1,deleteClass:"fa fa-times",deleteSpeed:200,onDelete:null,editButton:!1,editPlaceholder:".ams-widget-editbox",editClass:"fa fa-cog|fa fa-save",editSpeed:200,onEdit:null,fullscreenButton:!1,fullscreenClass:"fa fa-expand|fa fa-compress",fullscreenDiff:3,onFullscreen:null,customButton:!1,customClass:"folder-10|next-10",customStart:null,customEnd:null,buttonsOrder:"%refresh% %custom% %edit% %toggle% %fullscreen% %delete%",opacity:1,dragHandle:"> header",placeholderClass:"ams-widget-placeholder",indicator:!0,indicatorTime:600,ajax:!0,timestampPlaceholder:".ams-widget-timestamp",timestampFormat:a.i18n.TIMESTAMP_FORMAT,refreshButton:!0,refreshButtonClass:"fa fa-refresh",errorLabel:a.i18n.ERROR_LABEL,updatedLabel:a.i18n.UPDATED_LABEL,refreshLabel:a.i18n.REFRESH_LABEL,deleteLabel:a.i18n.DELETE_LABEL,afterLoad:null,rtl:!1,onChange:null,onSave:null,ajax_nav:s.ajax_nav},t.MyAMSWidget=a,e.fn.extend({MyAMSWidget:function(t){return this.each(function(){var n=e(this);if(!n.data("AMSWidget")){var d=n.parents(t.grid||a.defaults.grid),o={};if(d.exists()){var l=d.data();o={grid:l.amsWidgetGrid,subgrid:l.amsWidgetSubgrid,controls:l.amsWidgetControls,storage:l.amsWidgetStorage,deleteSettingsKey:l.amsWidgetDeleteSettingsKey,deletePositionKey:l.amsWidgetDeletePositionKey,sortable:l.amsWidgetSortable,hiddenButtons:l.amsWidgetHiddenButtons,toggleButton:l.amsWidgetToggleButton,toggleClass:l.amsWidgetToggleClass,onToggle:s.getFunctionByName(l.amsWidgetToggleCallback),deleteButton:l.amsWidgetDeleteButton,deleteClass:l.amsWidgetDeleteClass,onDelete:s.getFunctionByName(l.amsWidgetDeleteCallback),editButton:l.amsWidgetEditButton,editPlaceholder:l.amsWidgetEditPlaceholder,editClass:l.amsWidgetEditClass,onEdit:s.getFunctionByName(l.amsWidgetEditCallback),fullscreenButton:l.amsWidgetFullscreenButton,fullscreenClass:l.amsWidgetFullscreenClass,fullscreenDiff:l.amsWidgetFullscreenDiff,onFullscreen:s.getFunctionByName(l.amsWidgetFullscreenCallback),customButton:l.amsWidgetCustomButton,customClass:l.amsWidgetCustomClass,customStart:s.getFunctionByName(l.amsWidgetCustomStartCallback),customEnd:s.getFunctionByName(l.amsWidgetCustomStartCallback),buttonsOrder:l.amsWidgetButtonsOrder,opacity:l.amsWidgetOpacity,dragHandle:l.amsWidgetDragHandle,placeholderClass:l.amsWidgetPlaceholderClass,indicator:l.amsWidgetIndicator,indicatorTime:l.amsWidgetIndicatorTime,ajax:l.amsWidgetAjax,timestampPlaceholder:l.amsWidgetTimestampPlaceholder,timestampFormat:l.amsWidgetTimestampFormat,refreshButton:l.amsWidgetRefreshButton,refreshClass:l.amsWidgetRefreshClass,errorLabel:l.amsWidgetErrorLabel,updatedLabel:l.amsWidgetUpdatedLabel,refreshLabel:l.amsWidgetRefreshLabel,deleteLabel:l.amsWidgetDeleteLabel,afterLoad:s.getFunctionByName(l.amsWidgetAfterLoadCallback),rtl:l.amsWidgetRtl,onChange:s.getFunctionByName(l.amsWidgetChangeCallback),onSave:s.getFunctionByName(l.amsWidgetSaveCallback),ajax_nav:s.ajax_nav}}var r=e.fn.extend({},o,n.data("ams-widget-options")||{},t);n.data("AMSWidget",new i(n,r))}})}})}(jQuery,this);