diff --git a/customfield/amd/build/form.min.js b/customfield/amd/build/form.min.js index 84d91f9336b..c4febc1e874 100644 --- a/customfield/amd/build/form.min.js +++ b/customfield/amd/build/form.min.js @@ -1,2 +1,2 @@ -define ("core_customfield/form",["jquery","core/str","core/notification","core/ajax","core/templates","core/sortable_list","core/inplace_editable"],function(a,b,c,d,e,f){var g=function(f,g,h,i,j){b.get_strings([{key:"confirm"},{key:"confirmdelete"+g,component:"core_customfield"},{key:"yes"},{key:"no"}]).done(function(b){c.confirm(b[0],b[1],b[2],b[3],function(){var b="field"===g?"core_customfield_delete_field":"core_customfield_delete_category";d.call([{methodname:b,args:{id:f}},{methodname:"core_customfield_reload_template",args:{component:h,area:i,itemid:j}}])[1].then(function(a){return e.render("core_customfield/list",a)}).then(function(b,c){e.replaceNode(a("[data-region=\"list-page\"]"),b,c);return null}).fail(c.exception)})}).fail(c.exception)},h=function(b,f,g){var h=d.call([{methodname:"core_customfield_create_category",args:{component:b,area:f,itemid:g}},{methodname:"core_customfield_reload_template",args:{component:b,area:f,itemid:g}}]),i;h[0].then(function(a){i=a;return null}).fail(c.exception);h[1].then(function(a){return e.render("core_customfield/list",a)}).then(function(b,c){e.replaceNode(a("[data-region=\"list-page\"]"),b,c);window.location.href="#category-"+i;return null}).fail(c.exception)};return{init:function init(){var e=a("#customfield_catlist"),i=e.attr("data-component"),j=e.attr("data-area"),k=e.attr("data-itemid");a("[data-role=deletefield]").on("click",function(b){g(a(this).attr("data-id"),"field",i,j,k);b.preventDefault()});a("[data-role=deletecategory]").on("click",function(b){g(a(this).attr("data-id"),"category",i,j,k);b.preventDefault()});a("[data-role=addnewcategory]").on("click",function(){h(i,j,k)});var l=function(a){return a.closest("[data-category-id]").find("[data-inplaceeditable][data-itemtype=category][data-component=core_customfield]").attr("data-value")},m=new f(a("#customfield_catlist .categorieslist"),{moveHandlerSelector:".movecategory [data-drag-type=move]"});m.getElementName=function(b){return a.Deferred().resolve(l(b))};a("[data-category-id]").on("sortablelist-drop",function(a,b){if(b.positionChanged){var e=d.call([{methodname:"core_customfield_move_category",args:{id:b.element.data("category-id"),beforeid:b.targetNextElement.data("category-id")}}]);e[0].fail(c.exception)}a.stopPropagation()});var n=new f(a("#customfield_catlist .fieldslist tbody"),{moveHandlerSelector:".movefield [data-drag-type=move]"});n.getDestinationName=function(c,d){if(!d.length){return b.get_string("totopofcategory","customfield",l(c))}else if(d.attr("data-field-name")){return b.get_string("afterfield","customfield",d.attr("data-field-name"))}else{return a.Deferred().resolve("")}};a("[data-field-name]").on("sortablelist-drop",function(a,b){a.stopPropagation();if(b.positionChanged){var e=d.call([{methodname:"core_customfield_move_field",args:{id:b.element.data("field-id"),beforeid:b.targetNextElement.data("field-id"),categoryid:+b.targetList.closest("[data-category-id]").attr("data-category-id")}}]);e[0].fail(c.exception)}}).on("sortablelist-drag",function(d){d.stopPropagation();b.get_string("therearenofields","core_customfield").then(function(b){a("#customfield_catlist .categorieslist").children().each(function(){var c=a(this).find(a(".field")),d=a(this).find(a(".nofields"));if(!c.length&&!d.length){a(this).find("tbody").append(""+b+"")}if(c.length&&d.length){d.remove()}});return null}).fail(c.exception)});a("[data-category-id], [data-field-name]").on("sortablelist-dragstart",function(b,c){setTimeout(function(){a(".sortable-list-is-dragged").width(c.element.width())},501)})}}}); +define ("core_customfield/form",["jquery","core/str","core/notification","core/ajax","core/templates","core/sortable_list","core/pending","core/inplace_editable"],function(a,b,c,d,e,f,g){var h=function(f,h,i,j,k){var l=new g("core_customfield/form:confirmDelete");b.get_strings([{key:"confirm"},{key:"confirmdelete"+h,component:"core_customfield"},{key:"yes"},{key:"no"}]).then(function(b){c.confirm(b[0],b[1],b[2],b[3],function(){var b=new g("core_customfield/form:confirmDelete"),l="field"===h?"core_customfield_delete_field":"core_customfield_delete_category";d.call([{methodname:l,args:{id:f}},{methodname:"core_customfield_reload_template",args:{component:i,area:j,itemid:k}}])[1].then(function(a){return e.render("core_customfield/list",a)}).then(function(b,c){e.replaceNode(a("[data-region=\"list-page\"]"),b,c);return null}).then(b.resolve).catch(c.exception)})}).then(l.resolve).catch(c.exception)},i=function(b,f,h){var i=new g("core_customfield/form:confirmDelete"),j=d.call([{methodname:"core_customfield_create_category",args:{component:b,area:f,itemid:h}},{methodname:"core_customfield_reload_template",args:{component:b,area:f,itemid:h}}]),k;j[0].then(function(a){k=a;return null}).catch(c.exception);j[1].then(function(a){return e.render("core_customfield/list",a)}).then(function(b,c){e.replaceNode(a("[data-region=\"list-page\"]"),b,c);window.location.href="#category-"+k;return null}).catch(c.exception);Promise.all(j).then(i.resolve).catch()};return{init:function init(){var e=a("#customfield_catlist"),j=e.attr("data-component"),k=e.attr("data-area"),l=e.attr("data-itemid");a("[data-role=deletefield]").on("click",function(b){h(a(this).attr("data-id"),"field",j,k,l);b.preventDefault()});a("[data-role=deletecategory]").on("click",function(b){h(a(this).attr("data-id"),"category",j,k,l);b.preventDefault()});a("[data-role=addnewcategory]").on("click",function(){i(j,k,l)});var m=function(a){return a.closest("[data-category-id]").find("[data-inplaceeditable][data-itemtype=category][data-component=core_customfield]").attr("data-value")},n=new f(a("#customfield_catlist .categorieslist"),{moveHandlerSelector:".movecategory [data-drag-type=move]"});n.getElementName=function(b){return a.Deferred().resolve(m(b))};a("[data-category-id]").on("sortablelist-drop",function(a,b){if(b.positionChanged){var e=new g("core_customfield/form:categoryid:on:sortablelist-drop");d.call([{methodname:"core_customfield_move_category",args:{id:b.element.data("category-id"),beforeid:b.targetNextElement.data("category-id")}}])[0].then(e.resolve).catch(c.exception)}a.stopPropagation()});var o=new f(a("#customfield_catlist .fieldslist tbody"),{moveHandlerSelector:".movefield [data-drag-type=move]"});o.getDestinationName=function(c,d){if(!d.length){return b.get_string("totopofcategory","customfield",m(c))}else if(d.attr("data-field-name")){return b.get_string("afterfield","customfield",d.attr("data-field-name"))}else{return a.Deferred().resolve("")}};a("[data-field-name]").on("sortablelist-drop",function(a,b){a.stopPropagation();if(b.positionChanged){var e=new g("core_customfield/form:fieldname:on:sortablelist-drop");d.call([{methodname:"core_customfield_move_field",args:{id:b.element.data("field-id"),beforeid:b.targetNextElement.data("field-id"),categoryid:+b.targetList.closest("[data-category-id]").attr("data-category-id")}}])[0].then(e.resolve).catch(c.exception)}});a("[data-field-name]").on("sortablelist-drag",function(d){var e=new g("core_customfield/form:fieldname:on:sortablelist-drag");d.stopPropagation();b.get_string("therearenofields","core_customfield").then(function(b){a("#customfield_catlist .categorieslist").children().each(function(){var c=a(this).find(a(".field")),d=a(this).find(a(".nofields"));if(!c.length&&!d.length){a(this).find("tbody").append(""+b+"")}if(c.length&&d.length){d.remove()}});return null}).then(e.resolve).catch(c.exception)});a("[data-category-id], [data-field-name]").on("sortablelist-dragstart",function(b,c){setTimeout(function(){a(".sortable-list-is-dragged").width(c.element.width())},501)})}}}); //# sourceMappingURL=form.min.js.map diff --git a/customfield/amd/build/form.min.js.map b/customfield/amd/build/form.min.js.map index 70d8bd3fba1..fb1d01906e0 100644 --- a/customfield/amd/build/form.min.js.map +++ b/customfield/amd/build/form.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/form.js"],"names":["define","$","Str","Notification","Ajax","Templates","SortableList","confirmDelete","id","type","component","area","itemid","get_strings","done","s","confirm","func","call","methodname","args","then","response","render","html","js","replaceNode","fail","exception","createNewCategory","promises","categoryid","window","location","href","init","mainlist","attr","on","e","preventDefault","categoryName","element","closest","find","sortCat","moveHandlerSelector","getElementName","el","Deferred","resolve","evt","info","positionChanged","data","beforeid","targetNextElement","stopPropagation","sort","getDestinationName","parentElement","afterElement","length","get_string","targetList","children","each","fields","nofields","append","remove","setTimeout","width"],"mappings":"AAuBAA,OAAM,yBAAC,CAAC,QAAD,CAAW,UAAX,CAAuB,mBAAvB,CAA4C,WAA5C,CAAyD,gBAAzD,CAA2E,oBAA3E,CAAiG,uBAAjG,CAAD,CACF,SACIC,CADJ,CACOC,CADP,CACYC,CADZ,CAC0BC,CAD1B,CACgCC,CADhC,CAC2CC,CAD3C,CACyD,IAWrDC,CAAAA,CA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N,MAAhC,CAAwC,CACpC7D,CAAC,CAAC,IAAD,CAAD,CAAQ2C,IAAR,CAAa,OAAb,EAAsByB,MAAtB,CACI,4CAA0CtD,CAA1C,CAA8C,YADlD,CAGH,CACD,GAAIoD,CAAM,CAACL,MAAP,EAAiBM,CAAQ,CAACN,MAA9B,CAAsC,CAClCM,CAAQ,CAACE,MAAT,EACH,CACJ,CAXD,EAYA,MAAO,KACV,CAdD,EAcG3C,IAdH,CAcQxB,CAAY,CAACyB,SAdrB,CAeH,CAjCD,EAmCA3B,CAAC,CAAC,uCAAD,CAAD,CAA2CqC,EAA3C,CAA8C,wBAA9C,CACI,SAASa,CAAT,CAAcC,CAAd,CAAoB,CAChBmB,UAAU,CAAC,UAAW,CAClBtE,CAAC,CAAC,2BAAD,CAAD,CAA+BuE,KAA/B,CAAqCpB,CAAI,CAACV,OAAL,CAAa8B,KAAb,EAArC,CACH,CAFS,CAEP,GAFO,CAGb,CALL,CAQH,CAlHE,CAoHV,CAnLK,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * This module depends on the real jquery - and returns the non-global version of it.\n *\n * @module core_customfield/form\n * @package core_customfield\n * @copyright 2018 Toni Barbera\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery', 'core/str', 'core/notification', 'core/ajax', 'core/templates', 'core/sortable_list', 'core/inplace_editable'],\n function(\n $, Str, Notification, Ajax, Templates, SortableList) {\n\n /**\n * Display confirmation dialogue\n *\n * @param {Number} id\n * @param {String} type\n * @param {String} component\n * @param {String} area\n * @param {Number} itemid\n */\n var confirmDelete = function(id, type, component, area, itemid) {\n Str.get_strings([\n {'key': 'confirm'},\n {'key': 'confirmdelete' + type, component: 'core_customfield'},\n {'key': 'yes'},\n {'key': 'no'},\n ]).done(function(s) {\n Notification.confirm(s[0], s[1], s[2], s[3], function() {\n var func = (type === 'field') ? 'core_customfield_delete_field' : 'core_customfield_delete_category';\n Ajax.call([\n {methodname: func, args: {id: id}},\n {methodname: 'core_customfield_reload_template', args: {component: component, area: area, itemid: itemid}}\n ])[1].then(function(response) {\n return Templates.render('core_customfield/list', response);\n }).then(function(html, js) {\n Templates.replaceNode($('[data-region=\"list-page\"]'), html, js);\n return null;\n }).fail(Notification.exception);\n });\n }).fail(Notification.exception);\n };\n\n /**\n * Creates a new custom fields category with default name and updates the list\n *\n * @param {String} component\n * @param {String} area\n * @param {Number} itemid\n */\n var createNewCategory = function(component, area, itemid) {\n var promises = Ajax.call([\n {methodname: 'core_customfield_create_category', args: {component: component, area: area, itemid: itemid}},\n {methodname: 'core_customfield_reload_template', args: {component: component, area: area, itemid: itemid}}\n ]),\n categoryid;\n\n promises[0].then(function(response) {\n categoryid = response;\n return null;\n }).fail(Notification.exception);\n\n promises[1].then(function(response) {\n return Templates.render('core_customfield/list', response);\n }).then(function(html, js) {\n Templates.replaceNode($('[data-region=\"list-page\"]'), html, js);\n window.location.href = '#category-' + categoryid;\n return null;\n }).fail(Notification.exception);\n };\n\n return {\n /**\n * Initialise the custom fields manager\n */\n init: function() {\n var mainlist = $('#customfield_catlist'),\n component = mainlist.attr('data-component'),\n area = mainlist.attr('data-area'),\n itemid = mainlist.attr('data-itemid');\n $(\"[data-role=deletefield]\").on('click', function(e) {\n confirmDelete($(this).attr('data-id'), 'field', component, area, itemid);\n e.preventDefault();\n });\n $(\"[data-role=deletecategory]\").on('click', function(e) {\n confirmDelete($(this).attr('data-id'), 'category', component, area, itemid);\n e.preventDefault();\n });\n $('[data-role=addnewcategory]').on('click', function() {\n createNewCategory(component, area, itemid);\n });\n\n var categoryName = function(element) {\n return element\n .closest('[data-category-id]')\n .find('[data-inplaceeditable][data-itemtype=category][data-component=core_customfield]')\n .attr('data-value');\n };\n\n // Sort category.\n var sortCat = new SortableList(\n $('#customfield_catlist .categorieslist'),\n {moveHandlerSelector: '.movecategory [data-drag-type=move]'}\n );\n\n sortCat.getElementName = function(el) {\n return $.Deferred().resolve(categoryName(el));\n };\n\n $('[data-category-id]').on('sortablelist-drop', function(evt, info) {\n if (info.positionChanged) {\n var promises = Ajax.call([\n {\n methodname: 'core_customfield_move_category',\n args: {\n id: info.element.data('category-id'),\n beforeid: info.targetNextElement.data('category-id')\n }\n\n },\n ]);\n promises[0].fail(Notification.exception);\n }\n evt.stopPropagation(); // Important for nested lists to prevent multiple targets.\n });\n\n // Sort fields.\n var sort = new SortableList(\n $('#customfield_catlist .fieldslist tbody'),\n {moveHandlerSelector: '.movefield [data-drag-type=move]'}\n );\n\n sort.getDestinationName = function(parentElement, afterElement) {\n if (!afterElement.length) {\n return Str.get_string('totopofcategory', 'customfield', categoryName(parentElement));\n } else if (afterElement.attr('data-field-name')) {\n return Str.get_string('afterfield', 'customfield', afterElement.attr('data-field-name'));\n } else {\n return $.Deferred().resolve('');\n }\n };\n\n $('[data-field-name]').on('sortablelist-drop', function(evt, info) {\n evt.stopPropagation(); // Important for nested lists to prevent multiple targets.\n if (info.positionChanged) {\n var promises = Ajax.call([\n {\n methodname: 'core_customfield_move_field',\n args: {\n id: info.element.data('field-id'),\n beforeid: info.targetNextElement.data('field-id'),\n categoryid: Number(info.targetList.closest('[data-category-id]').attr('data-category-id'))\n },\n },\n ]);\n promises[0].fail(Notification.exception);\n }\n }).on('sortablelist-drag', function(evt) {\n evt.stopPropagation(); // Important for nested lists to prevent multiple targets.\n // Refreshing fields tables.\n Str.get_string('therearenofields', 'core_customfield').then(function(s) {\n $('#customfield_catlist .categorieslist').children().each(function() {\n var fields = $(this).find($('.field')),\n nofields = $(this).find($('.nofields'));\n if (!fields.length && !nofields.length) {\n $(this).find('tbody').append(\n '' + s + ''\n );\n }\n if (fields.length && nofields.length) {\n nofields.remove();\n }\n });\n return null;\n }).fail(Notification.exception);\n });\n\n $('[data-category-id], [data-field-name]').on('sortablelist-dragstart',\n function(evt, info) {\n setTimeout(function() {\n $('.sortable-list-is-dragged').width(info.element.width());\n }, 501);\n }\n );\n\n }\n };\n});\n"],"file":"form.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/form.js"],"names":["define","$","Str","Notification","Ajax","Templates","SortableList","Pending","confirmDelete","id","type","component","area","itemid","pendingPromise","get_strings","then","s","confirm","pendingDeletePromise","func","call","methodname","args","response","render","html","js","replaceNode","resolve","catch","exception","createNewCategory","promises","categoryid","window","location","href","Promise","all","init","mainlist","attr","on","e","preventDefault","categoryName","element","closest","find","sortCat","moveHandlerSelector","getElementName","el","Deferred","evt","info","positionChanged","data","beforeid","targetNextElement","stopPropagation","sort","getDestinationName","parentElement","afterElement","length","get_string","targetList","children","each","fields","nofields","append","remove","setTimeout","width"],"mappings":"AAuBAA,OAAM,yBAAC,CACH,QADG,CAEH,UAFG,CAGH,mBAHG,CAIH,WAJG,CAKH,gBALG,CAMH,oBANG,CAOH,cAPG,CAQH,uBARG,CAAD,CASH,SAASC,CAAT,CAAYC,CAAZ,CAAiBC,CAAjB,CAA+BC,CAA/B,CAAqCC,CAArC,CAAgDC,CAAhD,CAA8DC,CAA9D,CAAuE,IAWlEC,CAAAA,CAAa,CAAG,SAASC,CAAT,CAAaC,CAAb,CAAmBC,CAAnB,CAA8BC,CAA9B,CAAoCC,CAApC,CAA4C,CAC5D,GAAIC,CAAAA,CAAc,CAAG,GAAIP,CAAAA,CAAJ,CAAY,qCAAZ,CAArB,CACAL,CAAG,CAACa,WAAJ,CAAgB,CACZ,CAAC,IAAO,SAAR,CADY,CAEZ,CAAC,IAAO,gBAAkBL,CAA1B,CAAgCC,SAAS,CAAE,kBAA3C,CAFY,CAGZ,CAAC,IAAO,KAAR,CAHY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CACjE,GAAIC,CAAAA,CAAM,CAAGtE,CAAC,CAAC,IAAD,CAAD,CAAQgD,IAAR,CAAahD,CAAC,CAAC,QAAD,CAAd,CAAb,CACIuE,CAAQ,CAAGvE,CAAC,CAAC,IAAD,CAAD,CAAQgD,IAAR,CAAahD,CAAC,CAAC,WAAD,CAAd,CADf,CAEA,GAAI,CAACsE,CAAM,CAACL,MAAR,EAAkB,CAACM,CAAQ,CAACN,MAAhC,CAAwC,CACpCjE,CAAC,CAAC,IAAD,CAAD,CAAQgD,IAAR,CAAa,OAAb,EAAsBwB,MAAtB,CACI,4CAA0CxD,CAA1C,CAA8C,YADlD,CAGH,CACD,GAAIsD,CAAM,CAACL,MAAP,EAAiBM,CAAQ,CAACN,MAA9B,CAAsC,CAClCM,CAAQ,CAACE,MAAT,EACH,CACJ,CAXD,EAYA,MAAO,KACV,CAdD,EAeC1D,IAfD,CAeMF,CAAc,CAACe,OAfrB,EAgBCC,KAhBD,CAgBO3B,CAAY,CAAC4B,SAhBpB,CAiBH,CAvBD,EAyBA9B,CAAC,CAAC,uCAAD,CAAD,CAA2C0C,EAA3C,CAA8C,wBAA9C,CACI,SAASY,CAAT,CAAcC,CAAd,CAAoB,CAChBmB,UAAU,CAAC,UAAW,CAClB1E,CAAC,CAAC,2BAAD,CAAD,CAA+B2E,KAA/B,CAAqCpB,CAAI,CAACT,OAAL,CAAa6B,KAAb,EAArC,CACH,CAFS,CAEP,GAFO,CAGb,CALL,CAQH,CAhIE,CAkIV,CA1NK,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * This module depends on the real jquery - and returns the non-global version of it.\n *\n * @module core_customfield/form\n * @package core_customfield\n * @copyright 2018 Toni Barbera\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine([\n 'jquery',\n 'core/str',\n 'core/notification',\n 'core/ajax',\n 'core/templates',\n 'core/sortable_list',\n 'core/pending',\n 'core/inplace_editable',\n], function($, Str, Notification, Ajax, Templates, SortableList, Pending) {\n\n /**\n * Display confirmation dialogue\n *\n * @param {Number} id\n * @param {String} type\n * @param {String} component\n * @param {String} area\n * @param {Number} itemid\n */\n var confirmDelete = function(id, type, component, area, itemid) {\n var pendingPromise = new Pending('core_customfield/form:confirmDelete');\n Str.get_strings([\n {'key': 'confirm'},\n {'key': 'confirmdelete' + type, component: 'core_customfield'},\n {'key': 'yes'},\n {'key': 'no'},\n ])\n .then(function(s) {\n Notification.confirm(s[0], s[1], s[2], s[3], function() {\n var pendingDeletePromise = new Pending('core_customfield/form:confirmDelete');\n var func = (type === 'field') ? 'core_customfield_delete_field' : 'core_customfield_delete_category';\n Ajax.call([\n {methodname: func, args: {id: id}},\n {methodname: 'core_customfield_reload_template', args: {component: component, area: area, itemid: itemid}}\n ])[1]\n .then(function(response) {\n return Templates.render('core_customfield/list', response);\n })\n .then(function(html, js) {\n Templates.replaceNode($('[data-region=\"list-page\"]'), html, js);\n return null;\n })\n .then(pendingDeletePromise.resolve)\n .catch(Notification.exception);\n });\n\n return;\n })\n .then(pendingPromise.resolve)\n .catch(Notification.exception);\n };\n\n /**\n * Creates a new custom fields category with default name and updates the list\n *\n * @param {String} component\n * @param {String} area\n * @param {Number} itemid\n */\n var createNewCategory = function(component, area, itemid) {\n var pendingPromise = new Pending('core_customfield/form:confirmDelete');\n var promises = Ajax.call([\n {methodname: 'core_customfield_create_category', args: {component: component, area: area, itemid: itemid}},\n {methodname: 'core_customfield_reload_template', args: {component: component, area: area, itemid: itemid}}\n ]);\n var categoryid;\n\n promises[0].then(function(response) {\n categoryid = response;\n return null;\n }).catch(Notification.exception);\n\n promises[1].then(function(response) {\n return Templates.render('core_customfield/list', response);\n })\n .then(function(html, js) {\n Templates.replaceNode($('[data-region=\"list-page\"]'), html, js);\n window.location.href = '#category-' + categoryid;\n return null;\n })\n .catch(Notification.exception);\n\n Promise.all(promises)\n .then(pendingPromise.resolve)\n .catch();\n };\n\n return {\n /**\n * Initialise the custom fields manager\n */\n init: function() {\n var mainlist = $('#customfield_catlist');\n var component = mainlist.attr('data-component');\n var area = mainlist.attr('data-area');\n var itemid = mainlist.attr('data-itemid');\n\n $(\"[data-role=deletefield]\").on('click', function(e) {\n confirmDelete($(this).attr('data-id'), 'field', component, area, itemid);\n e.preventDefault();\n });\n\n $(\"[data-role=deletecategory]\").on('click', function(e) {\n confirmDelete($(this).attr('data-id'), 'category', component, area, itemid);\n e.preventDefault();\n });\n\n $('[data-role=addnewcategory]').on('click', function() {\n createNewCategory(component, area, itemid);\n });\n\n var categoryName = function(element) {\n return element\n .closest('[data-category-id]')\n .find('[data-inplaceeditable][data-itemtype=category][data-component=core_customfield]')\n .attr('data-value');\n };\n\n // Sort category.\n var sortCat = new SortableList(\n $('#customfield_catlist .categorieslist'),\n {moveHandlerSelector: '.movecategory [data-drag-type=move]'}\n );\n\n sortCat.getElementName = function(el) {\n return $.Deferred().resolve(categoryName(el));\n };\n\n $('[data-category-id]').on('sortablelist-drop', function(evt, info) {\n if (info.positionChanged) {\n var pendingPromise = new Pending('core_customfield/form:categoryid:on:sortablelist-drop');\n Ajax.call([\n {\n methodname: 'core_customfield_move_category',\n args: {\n id: info.element.data('category-id'),\n beforeid: info.targetNextElement.data('category-id')\n }\n\n },\n ])[0]\n .then(pendingPromise.resolve)\n .catch(Notification.exception);\n }\n evt.stopPropagation(); // Important for nested lists to prevent multiple targets.\n });\n\n // Sort fields.\n var sort = new SortableList(\n $('#customfield_catlist .fieldslist tbody'),\n {moveHandlerSelector: '.movefield [data-drag-type=move]'}\n );\n\n sort.getDestinationName = function(parentElement, afterElement) {\n if (!afterElement.length) {\n return Str.get_string('totopofcategory', 'customfield', categoryName(parentElement));\n } else if (afterElement.attr('data-field-name')) {\n return Str.get_string('afterfield', 'customfield', afterElement.attr('data-field-name'));\n } else {\n return $.Deferred().resolve('');\n }\n };\n\n $('[data-field-name]').on('sortablelist-drop', function(evt, info) {\n evt.stopPropagation(); // Important for nested lists to prevent multiple targets.\n if (info.positionChanged) {\n var pendingPromise = new Pending('core_customfield/form:fieldname:on:sortablelist-drop');\n Ajax.call([\n {\n methodname: 'core_customfield_move_field',\n args: {\n id: info.element.data('field-id'),\n beforeid: info.targetNextElement.data('field-id'),\n categoryid: Number(info.targetList.closest('[data-category-id]').attr('data-category-id'))\n },\n },\n ])[0]\n .then(pendingPromise.resolve)\n .catch(Notification.exception);\n }\n });\n\n $('[data-field-name]').on('sortablelist-drag', function(evt) {\n var pendingPromise = new Pending('core_customfield/form:fieldname:on:sortablelist-drag');\n\n evt.stopPropagation(); // Important for nested lists to prevent multiple targets.\n\n // Refreshing fields tables.\n Str.get_string('therearenofields', 'core_customfield').then(function(s) {\n $('#customfield_catlist .categorieslist').children().each(function() {\n var fields = $(this).find($('.field')),\n nofields = $(this).find($('.nofields'));\n if (!fields.length && !nofields.length) {\n $(this).find('tbody').append(\n '' + s + ''\n );\n }\n if (fields.length && nofields.length) {\n nofields.remove();\n }\n });\n return null;\n })\n .then(pendingPromise.resolve)\n .catch(Notification.exception);\n });\n\n $('[data-category-id], [data-field-name]').on('sortablelist-dragstart',\n function(evt, info) {\n setTimeout(function() {\n $('.sortable-list-is-dragged').width(info.element.width());\n }, 501);\n }\n );\n\n }\n };\n});\n"],"file":"form.min.js"} \ No newline at end of file diff --git a/customfield/amd/src/form.js b/customfield/amd/src/form.js index 644dc66cc84..9825728ebfe 100644 --- a/customfield/amd/src/form.js +++ b/customfield/amd/src/form.js @@ -21,9 +21,16 @@ * @copyright 2018 Toni Barbera * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -define(['jquery', 'core/str', 'core/notification', 'core/ajax', 'core/templates', 'core/sortable_list', 'core/inplace_editable'], - function( - $, Str, Notification, Ajax, Templates, SortableList) { +define([ + 'jquery', + 'core/str', + 'core/notification', + 'core/ajax', + 'core/templates', + 'core/sortable_list', + 'core/pending', + 'core/inplace_editable', +], function($, Str, Notification, Ajax, Templates, SortableList, Pending) { /** * Display confirmation dialogue @@ -35,25 +42,36 @@ define(['jquery', 'core/str', 'core/notification', 'core/ajax', 'core/templates' * @param {Number} itemid */ var confirmDelete = function(id, type, component, area, itemid) { + var pendingPromise = new Pending('core_customfield/form:confirmDelete'); Str.get_strings([ {'key': 'confirm'}, {'key': 'confirmdelete' + type, component: 'core_customfield'}, {'key': 'yes'}, {'key': 'no'}, - ]).done(function(s) { + ]) + .then(function(s) { Notification.confirm(s[0], s[1], s[2], s[3], function() { + var pendingDeletePromise = new Pending('core_customfield/form:confirmDelete'); var func = (type === 'field') ? 'core_customfield_delete_field' : 'core_customfield_delete_category'; Ajax.call([ {methodname: func, args: {id: id}}, {methodname: 'core_customfield_reload_template', args: {component: component, area: area, itemid: itemid}} - ])[1].then(function(response) { + ])[1] + .then(function(response) { return Templates.render('core_customfield/list', response); - }).then(function(html, js) { + }) + .then(function(html, js) { Templates.replaceNode($('[data-region="list-page"]'), html, js); return null; - }).fail(Notification.exception); + }) + .then(pendingDeletePromise.resolve) + .catch(Notification.exception); }); - }).fail(Notification.exception); + + return; + }) + .then(pendingPromise.resolve) + .catch(Notification.exception); }; /** @@ -64,24 +82,31 @@ define(['jquery', 'core/str', 'core/notification', 'core/ajax', 'core/templates' * @param {Number} itemid */ var createNewCategory = function(component, area, itemid) { + var pendingPromise = new Pending('core_customfield/form:confirmDelete'); var promises = Ajax.call([ - {methodname: 'core_customfield_create_category', args: {component: component, area: area, itemid: itemid}}, - {methodname: 'core_customfield_reload_template', args: {component: component, area: area, itemid: itemid}} - ]), - categoryid; + {methodname: 'core_customfield_create_category', args: {component: component, area: area, itemid: itemid}}, + {methodname: 'core_customfield_reload_template', args: {component: component, area: area, itemid: itemid}} + ]); + var categoryid; promises[0].then(function(response) { categoryid = response; return null; - }).fail(Notification.exception); + }).catch(Notification.exception); promises[1].then(function(response) { return Templates.render('core_customfield/list', response); - }).then(function(html, js) { + }) + .then(function(html, js) { Templates.replaceNode($('[data-region="list-page"]'), html, js); window.location.href = '#category-' + categoryid; return null; - }).fail(Notification.exception); + }) + .catch(Notification.exception); + + Promise.all(promises) + .then(pendingPromise.resolve) + .catch(); }; return { @@ -89,18 +114,21 @@ define(['jquery', 'core/str', 'core/notification', 'core/ajax', 'core/templates' * Initialise the custom fields manager */ init: function() { - var mainlist = $('#customfield_catlist'), - component = mainlist.attr('data-component'), - area = mainlist.attr('data-area'), - itemid = mainlist.attr('data-itemid'); + var mainlist = $('#customfield_catlist'); + var component = mainlist.attr('data-component'); + var area = mainlist.attr('data-area'); + var itemid = mainlist.attr('data-itemid'); + $("[data-role=deletefield]").on('click', function(e) { confirmDelete($(this).attr('data-id'), 'field', component, area, itemid); e.preventDefault(); }); + $("[data-role=deletecategory]").on('click', function(e) { confirmDelete($(this).attr('data-id'), 'category', component, area, itemid); e.preventDefault(); }); + $('[data-role=addnewcategory]').on('click', function() { createNewCategory(component, area, itemid); }); @@ -124,7 +152,8 @@ define(['jquery', 'core/str', 'core/notification', 'core/ajax', 'core/templates' $('[data-category-id]').on('sortablelist-drop', function(evt, info) { if (info.positionChanged) { - var promises = Ajax.call([ + var pendingPromise = new Pending('core_customfield/form:categoryid:on:sortablelist-drop'); + Ajax.call([ { methodname: 'core_customfield_move_category', args: { @@ -133,8 +162,9 @@ define(['jquery', 'core/str', 'core/notification', 'core/ajax', 'core/templates' } }, - ]); - promises[0].fail(Notification.exception); + ])[0] + .then(pendingPromise.resolve) + .catch(Notification.exception); } evt.stopPropagation(); // Important for nested lists to prevent multiple targets. }); @@ -158,7 +188,8 @@ define(['jquery', 'core/str', 'core/notification', 'core/ajax', 'core/templates' $('[data-field-name]').on('sortablelist-drop', function(evt, info) { evt.stopPropagation(); // Important for nested lists to prevent multiple targets. if (info.positionChanged) { - var promises = Ajax.call([ + var pendingPromise = new Pending('core_customfield/form:fieldname:on:sortablelist-drop'); + Ajax.call([ { methodname: 'core_customfield_move_field', args: { @@ -167,11 +198,17 @@ define(['jquery', 'core/str', 'core/notification', 'core/ajax', 'core/templates' categoryid: Number(info.targetList.closest('[data-category-id]').attr('data-category-id')) }, }, - ]); - promises[0].fail(Notification.exception); + ])[0] + .then(pendingPromise.resolve) + .catch(Notification.exception); } - }).on('sortablelist-drag', function(evt) { + }); + + $('[data-field-name]').on('sortablelist-drag', function(evt) { + var pendingPromise = new Pending('core_customfield/form:fieldname:on:sortablelist-drag'); + evt.stopPropagation(); // Important for nested lists to prevent multiple targets. + // Refreshing fields tables. Str.get_string('therearenofields', 'core_customfield').then(function(s) { $('#customfield_catlist .categorieslist').children().each(function() { @@ -187,7 +224,9 @@ define(['jquery', 'core/str', 'core/notification', 'core/ajax', 'core/templates' } }); return null; - }).fail(Notification.exception); + }) + .then(pendingPromise.resolve) + .catch(Notification.exception); }); $('[data-category-id], [data-field-name]').on('sortablelist-dragstart',