MDL-65564 core_customfield: fix inplace editable

This commit is contained in:
Marina Glancy 2019-05-10 11:01:18 +02:00
parent 2018f4ebc1
commit c508bedcc3
2 changed files with 7 additions and 6 deletions

View File

@ -1 +1 @@
define(["jquery","core/str","core/notification","core/ajax","core/templates","core/sortable_list"],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){return e.replaceNodeContents(a('[data-region="list-page"]'),b,c),null}).fail(c.exception)})}).fail(c.exception)},h=function(b,f,g){var h,i=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[0].then(function(a){return h=a,null}).fail(c.exception),i[1].then(function(a){return e.render("core_customfield/list",a)}).then(function(b,c){return e.replaceNodeContents(a('[data-region="list-page"]'),b,c),window.location.href="#category-"+h,null}).fail(c.exception)};return{init:function(){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("#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("#customfield_catlist .fieldslist tbody",{moveHandlerSelector:".movefield [data-drag-type=move]"});n.getDestinationName=function(c,d){return d.length?d.attr("data-field-name")?b.get_string("afterfield","customfield",d.attr("data-field-name")):a.Deferred().resolve(""):b.get_string("totopofcategory","customfield",l(c))},a("[data-field-name]").on("sortablelist-drop",function(a,b){if(a.stopPropagation(),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:Number(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){return a("#customfield_catlist .categorieslist").children().each(function(){var c=a(this).find(a(".field")),d=a(this).find(a(".nofields"));c.length||d.length||a(this).find("tbody").append('<tr class="nofields"><td colspan="5">'+b+"</td></tr>"),c.length&&d.length&&d.remove()}),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(["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){return e.replaceNode(a('[data-region="list-page"]'),b,c),null}).fail(c.exception)})}).fail(c.exception)},h=function(b,f,g){var h,i=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[0].then(function(a){return h=a,null}).fail(c.exception),i[1].then(function(a){return e.render("core_customfield/list",a)}).then(function(b,c){return e.replaceNode(a('[data-region="list-page"]'),b,c),window.location.href="#category-"+h,null}).fail(c.exception)};return{init:function(){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){return d.length?d.attr("data-field-name")?b.get_string("afterfield","customfield",d.attr("data-field-name")):a.Deferred().resolve(""):b.get_string("totopofcategory","customfield",l(c))},a("[data-field-name]").on("sortablelist-drop",function(a,b){if(a.stopPropagation(),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:Number(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){return a("#customfield_catlist .categorieslist").children().each(function(){var c=a(this).find(a(".field")),d=a(this).find(a(".nofields"));c.length||d.length||a(this).find("tbody").append('<tr class="nofields"><td colspan="5">'+b+"</td></tr>"),c.length&&d.length&&d.remove()}),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)})}}});

View File

@ -21,7 +21,8 @@
* @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'], function(
define(['jquery', 'core/str', 'core/notification', 'core/ajax', 'core/templates', 'core/sortable_list', 'core/inplace_editable'],
function(
$, Str, Notification, Ajax, Templates, SortableList) {
/**
@ -48,7 +49,7 @@ define(['jquery', 'core/str', 'core/notification', 'core/ajax', 'core/templates'
])[1].then(function(response) {
return Templates.render('core_customfield/list', response);
}).then(function(html, js) {
Templates.replaceNodeContents($('[data-region="list-page"]'), html, js);
Templates.replaceNode($('[data-region="list-page"]'), html, js);
return null;
}).fail(Notification.exception);
});
@ -77,7 +78,7 @@ define(['jquery', 'core/str', 'core/notification', 'core/ajax', 'core/templates'
promises[1].then(function(response) {
return Templates.render('core_customfield/list', response);
}).then(function(html, js) {
Templates.replaceNodeContents($('[data-region="list-page"]'), html, js);
Templates.replaceNode($('[data-region="list-page"]'), html, js);
window.location.href = '#category-' + categoryid;
return null;
}).fail(Notification.exception);
@ -113,7 +114,7 @@ define(['jquery', 'core/str', 'core/notification', 'core/ajax', 'core/templates'
// Sort category.
var sortCat = new SortableList(
'#customfield_catlist .categorieslist',
$('#customfield_catlist .categorieslist'),
{moveHandlerSelector: '.movecategory [data-drag-type=move]'}
);
@ -140,7 +141,7 @@ define(['jquery', 'core/str', 'core/notification', 'core/ajax', 'core/templates'
// Sort fields.
var sort = new SortableList(
'#customfield_catlist .fieldslist tbody',
$('#customfield_catlist .fieldslist tbody'),
{moveHandlerSelector: '.movefield [data-drag-type=move]'}
);