MDL-59784 core: Refactor addblock to listen earlier
This commit is contained in:
Vendored
+1
-1
@@ -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)}}});
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user