Merge branch 'MDL-59784-32' of git://github.com/andrewnicols/moodle into MOODLE_32_STABLE

This commit is contained in:
Eloy Lafuente (stronk7)
2017-08-22 12:29:01 +02:00
6 changed files with 63 additions and 37 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)}}});
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1 +1 @@
define(["jquery","core/modal_events","core/modal","core/modal_save_cancel","core/modal_confirm","core/modal_cancel","core/templates","core/notification","core/custom_interaction_events"],function(a,b,c,d,e,f,g,h,i){var j={DEFAULT:"core/modal",SAVE_CANCEL:"core/modal_save_cancel",CONFIRM:"core/modal_confirm",CANCEL:"core/modal_cancel"},k={DEFAULT:c,SAVE_CANCEL:d,CONFIRM:e,CANCEL:f},l={DEFAULT:"DEFAULT",SAVE_CANCEL:"SAVE_CANCEL",CONFIRM:"CONFIRM",CANCEL:"CANCEL"},m=function(a,c){"undefined"!=typeof c&&(i.define(c,[i.events.activate]),c.on(i.events.activate,function(b,c){a.show(),c.originalEvent.preventDefault()}),a.getRoot().on(b.hidden,function(){c.focus()}))},n=function(b,c,d){c=a(c);var e=k[b],f=new e(c);return m(f,d),f},o=function(b,c){var d=j[b];return g.render(d,{}).then(function(d){var e=a(d);return n(b,e,c)}).fail(h.exception)},p=function(a,b){var c=a.type||l.DEFAULT,d=!!a.large;return l[c]||(c=l.DEFAULT),o(c,b).then(function(b){return"undefined"!=typeof a.title&&b.setTitle(a.title),"undefined"!=typeof a.body&&b.setBody(a.body),"undefined"!=typeof a.footer&&b.setFooter(a.footer),d&&b.setLarge(),b})};return{create:p,types:l}});
define(["jquery","core/modal_events","core/modal","core/modal_save_cancel","core/modal_confirm","core/modal_cancel","core/templates","core/notification","core/custom_interaction_events"],function(a,b,c,d,e,f,g,h,i){var j={DEFAULT:"core/modal",SAVE_CANCEL:"core/modal_save_cancel",CONFIRM:"core/modal_confirm",CANCEL:"core/modal_cancel"},k={DEFAULT:c,SAVE_CANCEL:d,CONFIRM:e,CANCEL:f},l={DEFAULT:"DEFAULT",SAVE_CANCEL:"SAVE_CANCEL",CONFIRM:"CONFIRM",CANCEL:"CANCEL"},m=function(a,c){"undefined"!=typeof c&&(i.define(c,[i.events.activate]),c.on(i.events.activate,function(b,c){a.then(function(a){return a.show(),a}),c.originalEvent.preventDefault()}),a.then(function(a){return a.getRoot().on(b.hidden,function(){c.focus()}),a}))},n=function(b,c){c=a(c);var d=k[b],e=new d(c);return e},o=function(b,c){var d=j[b],e=g.render(d,{}).then(function(c){var d=a(c);return n(b,d)}).fail(h.exception);return m(e,c),e},p=function(a,b){var c=a.type||l.DEFAULT,d=!!a.large;return l[c]||(c=l.DEFAULT),o(c,b).then(function(b){return"undefined"!=typeof a.title&&b.setTitle(a.title),"undefined"!=typeof a.body&&b.setBody(a.body),"undefined"!=typeof a.footer&&b.setFooter(a.footer),d&&b.setLarge(),b})};return{create:p,types:l}});
+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);
}
};
});
+15 -6
View File
@@ -215,23 +215,32 @@ define(['jquery', 'core/templates', 'core/notification', 'core/key_codes',
/**
* Set the modal title element.
*
* This method is overloaded to take either a string value for the title or a jQuery promise that is resolved with
* HTML most commonly from a Str.get_string call.
*
* @method setTitle
* @param {string} value The title string
* @param {(string|object)} value The title string or jQuery promise which resolves to the title.
*/
Modal.prototype.setTitle = function(value) {
var title = this.getTitle();
title.html(value);
if (typeof value === 'string') {
title.html(value);
} else {
value.then(function(content) {
return title.html(content);
});
}
};
/**
* Set the modal body element.
*
* This method is overloaded to take either a string
* value for the body or a jQuery promise that is resolved with HTML and Javascript
* most commonly from a Templates.render call.
* This method is overloaded to take either a string value for the body or a jQuery promise that is resolved with
* HTML and Javascript most commonly from a Templates.render call.
*
* @method setBody
* @param {(string|object)} value The body string or jQuery promise
* @param {(string|object)} value The body string or jQuery promise which resolves to the body.
*/
Modal.prototype.setBody = function(value) {
var body = this.getBody();
+20 -9
View File
@@ -55,19 +55,27 @@ define(['jquery', 'core/modal_events', 'core/modal', 'core/modal_save_cancel', '
* is closed.
*
* @method setUpTrigger
* @param {object} modal The modal instance
* @param {Promise} modalPromise The modal instance
* @param {object} triggerElement The jQuery element to open the modal
*/
var setUpTrigger = function(modal, triggerElement) {
var setUpTrigger = function(modalPromise, triggerElement) {
if (typeof triggerElement != 'undefined') {
CustomEvents.define(triggerElement, [CustomEvents.events.activate]);
triggerElement.on(CustomEvents.events.activate, function(e, data) {
modal.show();
modalPromise.then(function(modal) {
modal.show();
return modal;
});
data.originalEvent.preventDefault();
});
modal.getRoot().on(ModalEvents.hidden, function() {
triggerElement.focus();
modalPromise.then(function(modal) {
modal.getRoot().on(ModalEvents.hidden, function() {
triggerElement.focus();
});
return modal;
});
}
};
@@ -82,11 +90,10 @@ define(['jquery', 'core/modal_events', 'core/modal', 'core/modal_save_cancel', '
* @param {object} triggerElement The trigger HTML jQuery object
* @return {object} Modal instance
*/
var createFromElement = function(type, modalElement, triggerElement) {
var createFromElement = function(type, modalElement) {
modalElement = $(modalElement);
var ClassName = CLASSES[type];
var modal = new ClassName(modalElement);
setUpTrigger(modal, triggerElement);
return modal;
};
@@ -104,12 +111,16 @@ define(['jquery', 'core/modal_events', 'core/modal', 'core/modal_save_cancel', '
var createFromType = function(type, triggerElement) {
var templateName = TEMPLATES[type];
return Templates.render(templateName, {})
var modalPromise = Templates.render(templateName, {})
.then(function(html) {
var modalElement = $(html);
return createFromElement(type, modalElement, triggerElement);
return createFromElement(type, modalElement);
})
.fail(Notification.exception);
setUpTrigger(modalPromise, triggerElement);
return modalPromise;
};
/**