# HG changeset patch # User Thierry Florac # Date 1564137529 -7200 # Node ID d21c81597338f09ddb901d2a98233086fb267eb8 # Parent d787b89ba9b8abbbd1c7dd5459a6ffcc926605db Updated container update callbacks diff -r d787b89ba9b8 -r d21c81597338 src/pyams_skin/resources/js/myams-container.js --- a/src/pyams_skin/resources/js/myams-container.js Fri Jul 26 12:36:57 2019 +0200 +++ b/src/pyams_skin/resources/js/myams-container.js Fri Jul 26 12:38:49 2019 +0200 @@ -51,10 +51,10 @@ tr.remove(); } if (result.handle_json) { - ams.ajax && ams.ajax.handleJSON(result); + ams.ajax.handleJSON(result); } } else { - ams.ajax && ams.ajax.handleJSON(result); + ams.ajax.handleJSON(result); } }); } @@ -76,10 +76,14 @@ (cell.data('ams-attribute-switcher') || table.data('ams-attribute-switcher')), {object_name: row.data('ams-element-name')}, function(result, status) { - if (result.visible) { - $('i', source).attr('class', 'fa fa-fw fa-eye'); + if (result.status === 'success') { + if (result.visible) { + $('i', source).attr('class', 'fa fa-fw fa-eye'); + } else { + $('i', source).attr('class', 'fa fa-fw fa-eye-slash text-danger'); + } } else { - $('i', source).attr('class', 'fa fa-fw fa-eye-slash text-danger'); + ams.ajax.handleJSON(result); } }); } @@ -100,10 +104,14 @@ (cell.data('ams-attribute-switcher') || table.data('ams-attribute-switcher')), {object_name: row.data('ams-element-name')}, function(result, status) { - if (result[attribute] || result['on']) { - $('i', source).attr('class', table.data('ams-' + attribute + '-icon-on') || 'fa fa-fw fa-check-square-o'); + if (result.status === 'success') { + if (result[attribute] || result['on']) { + $('i', source).attr('class', table.data('ams-' + attribute + '-icon-on') || 'fa fa-fw fa-check-square-o'); + } else { + $('i', source).attr('class', table.data('ams-' + attribute + '-icon-off') || 'fa fa-fw fa-check-square txt-color-silver opacity-75'); + } } else { - $('i', source).attr('class', table.data('ams-' + attribute + '-icon-off') || 'fa fa-fw fa-check-square txt-color-silver opacity-75'); + ams.ajax.handleJSON(result); } }); } diff -r d787b89ba9b8 -r d21c81597338 src/pyams_skin/resources/js/myams-container.min.js --- a/src/pyams_skin/resources/js/myams-container.min.js Fri Jul 26 12:36:57 2019 +0200 +++ b/src/pyams_skin/resources/js/myams-container.min.js Fri Jul 26 12:38:49 2019 +0200 @@ -1,1 +1,1 @@ -!function(i,a){var f=a.MyAMS;f.container={changeOrder:function(a,t){i('input[name="'+i(this).data("ams-input-name")+'"]',i(this)).val(t.join(";"))},deleteElement:function(){return function(){var r=i(this);f.skin&&f.skin.bigBox({title:f.i18n.WARNING,content:'  '+f.i18n.DELETE_WARNING,status:"info",buttons:f.i18n.BTN_OK_CANCEL},function(a){if(a===f.i18n.BTN_OK){var e=r.parents("tr").first(),n=e.parents("table").first(),t=e.data("ams-location")||n.data("ams-location")||"";t&&(t+="/");var s=e.data("ams-delete-target")||n.data("ams-delete-target")||"delete-element.json",i=e.data("ams-element-name");f.ajax&&f.ajax.post(t+s,{object_name:i},function(a,t){"success"===a.status?(n.hasClass("datatable")?n.dataTable().fnDeleteRow(e[0]):e.remove(),a.handle_json&&f.ajax&&f.ajax.handleJSON(a)):f.ajax&&f.ajax.handleJSON(a)})}})}},switchElementVisibility:function(){return function(){var e=i(this),a=e.parents("td").first(),t=e.parents("tr").first(),n=t.parents("table");i("i",e).attr("class","fa fa-fw fa-spinner fa-pulse"),f.ajax&&f.ajax.post(n.data("ams-location")+"/"+(a.data("ams-attribute-switcher")||n.data("ams-attribute-switcher")),{object_name:t.data("ams-element-name")},function(a,t){a.visible?i("i",e).attr("class","fa fa-fw fa-eye"):i("i",e).attr("class","fa fa-fw fa-eye-slash text-danger")})}},switchElementAttribute:function(){return function(){var e=i(this),a=e.parents("td").first(),n=a.data("ams-switcher-attribute-name"),t=e.parents("tr").first(),s=t.parents("table");i("i",e).attr("class","fa fa-fw fa-spinner fa-pulse"),f.ajax&&f.ajax.post(s.data("ams-location")+"/"+(a.data("ams-attribute-switcher")||s.data("ams-attribute-switcher")),{object_name:t.data("ams-element-name")},function(a,t){a[n]||a.on?i("i",e).attr("class",s.data("ams-"+n+"-icon-on")||"fa fa-fw fa-check-square-o"):i("i",e).attr("class",s.data("ams-"+n+"-icon-off")||"fa fa-fw fa-check-square txt-color-silver opacity-75")})}},exportTableToTSV:function(){return function(){var s=i(this);f.ajax&&f.ajax.check(a.saveAs,f.baseURL+"ext/js-filesaver"+f.devext+".js",function(){var a=i("table.datatable",s.parents(".ams-widget:first")),t=a.dataTable(),e="";i("th",a).each(function(a){0  '+e.i18n.DELETE_WARNING,status:"info",buttons:e.i18n.BTN_OK_CANCEL},function(a){if(a===e.i18n.BTN_OK){var s=t.parents("tr").first(),n=s.parents("table").first(),i=s.data("ams-location")||n.data("ams-location")||"";i&&(i+="/");var r=s.data("ams-delete-target")||n.data("ams-delete-target")||"delete-element.json",f=s.data("ams-element-name");e.ajax&&e.ajax.post(i+r,{object_name:f},function(a,t){"success"===a.status?(n.hasClass("datatable")?n.dataTable().fnDeleteRow(s[0]):s.remove(),a.handle_json&&e.ajax.handleJSON(a)):e.ajax.handleJSON(a)})}})}},switchElementVisibility:function(){return function(){var t=a(this),s=t.parents("td").first(),n=t.parents("tr").first(),i=n.parents("table");a("i",t).attr("class","fa fa-fw fa-spinner fa-pulse"),e.ajax&&e.ajax.post(i.data("ams-location")+"/"+(s.data("ams-attribute-switcher")||i.data("ams-attribute-switcher")),{object_name:n.data("ams-element-name")},function(s,n){"success"===s.status?s.visible?a("i",t).attr("class","fa fa-fw fa-eye"):a("i",t).attr("class","fa fa-fw fa-eye-slash text-danger"):e.ajax.handleJSON(s)})}},switchElementAttribute:function(){return function(){var t=a(this),s=t.parents("td").first(),n=s.data("ams-switcher-attribute-name"),i=t.parents("tr").first(),r=i.parents("table");a("i",t).attr("class","fa fa-fw fa-spinner fa-pulse"),e.ajax&&e.ajax.post(r.data("ams-location")+"/"+(s.data("ams-attribute-switcher")||r.data("ams-attribute-switcher")),{object_name:i.data("ams-element-name")},function(s,i){"success"===s.status?s[n]||s.on?a("i",t).attr("class",r.data("ams-"+n+"-icon-on")||"fa fa-fw fa-check-square-o"):a("i",t).attr("class",r.data("ams-"+n+"-icon-off")||"fa fa-fw fa-check-square txt-color-silver opacity-75"):e.ajax.handleJSON(s)})}},exportTableToTSV:function(){return function(){var s=a(this);e.ajax&&e.ajax.check(t.saveAs,e.baseURL+"ext/js-filesaver"+e.devext+".js",function(){var t=a("table.datatable",s.parents(".ams-widget:first")),e=t.dataTable(),n="";a("th",t).each(function(t){t>0&&(n+="\t"),n+=a(this).text()}),n+="\n",a(e.fnGetData()).each(function(){a(this).each(function(a){a>0&&(n+="\t"),n+=this}),n+="\n"});var i=new Blob([n],{type:"text/tsv; charset=utf-8"});saveAs(i,"export.tsv")})}}}}(jQuery,this);