MDL-59784 core: Refactor addblock to listen earlier

This commit is contained in:
Andrew Nicols
2017-08-18 09:37:17 +08:00
parent fca5d3d71d
commit 2f8dec8a00
2 changed files with 26 additions and 20 deletions
+1 -1
View File
@@ -1 +1 @@
define(["jquery","core/modal_factory","core/templates","core/str","core/notification"],function(a,b,c,d,e){return{init:function(f){var g=a("[data-key=addblock]");d.get_string("addblock").done(function(e){var h=[];a.each(f.blocks,function(a,b){h[h.length]={key:"pluginname",component:"block_"+b}});var i=[];d.get_strings(h).done(function(d){a.each(d,function(a,b){i[i.length]={name:f.blocks[a],title:b}}),f.blocks=i,b.create({title:e,body:c.render("core/add_block_body",f),type:"CANCEL"},g)})}).fail(e.exception)}}});
define(["jquery","core/modal_factory","core/templates","core/str","core/notification"],function(a,b,c,d,e){return{init:function(f){var g=a("[data-key=addblock]"),h=[];a.each(f.blocks,function(a,b){h[h.length]={key:"pluginname",component:"block_"+b}});var i=d.get_strings(h).then(function(a){return a.map(function(a,b){return{name:f.blocks[b],title:a}})}).then(function(a){return f.blocks=a,c.render("core/add_block_body",f)}).fail(e.exception),j=d.get_string("addblock").fail(e.exception);b.create({title:j,body:i,type:"CANCEL"},g)}}});
+25 -19
View File
@@ -37,28 +37,34 @@ define(['jquery', 'core/modal_factory', 'core/templates', 'core/str', 'core/noti
var addblocklink = $('[data-key=addblock]');
// We need the fetch the names of the blocks. It was too much to send in the page.
Str.get_string('addblock').done(function(title) {
var titlerequests = [];
$.each(context.blocks, function(index, key) {
titlerequests[titlerequests.length] = {key: 'pluginname', component: 'block_' + key};
});
var titlerequests = [];
$.each(context.blocks, function(index, key) {
titlerequests[titlerequests.length] = {key: 'pluginname', component: 'block_' + key};
});
var blocks = [];
Str.get_strings(titlerequests).done(function(titles) {
$.each(titles, function(index, title) {
blocks[blocks.length] = {name: context.blocks[index], title: title};
});
context.blocks = blocks;
ModalFactory.create({
var bodyPromise = Str.get_strings(titlerequests)
.then(function(titles) {
return titles.map(function(title, index) {
return {
name: context.blocks[index],
title: title,
body: Templates.render('core/add_block_body', context),
type: 'CANCEL',
}, addblocklink);
};
});
}).fail(Notification.exception);
})
.then(function(blocks) {
context.blocks = blocks;
return Templates.render('core/add_block_body', context);
})
.fail(Notification.exception);
var titlePromise = Str.get_string('addblock')
.fail(Notification.exception);
ModalFactory.create({
title: titlePromise,
body: bodyPromise,
type: 'CANCEL',
}, addblocklink);
}
};
});