You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1 lines
3.5 KiB

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)})}}});