MDL-57690 js: fix core modal uses in amd
[moodle.git] / lib / amd / src / tag.js
index 68324fc..8e546f5 100644 (file)
@@ -22,8 +22,8 @@
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  * @since      3.0
  */
-define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str'],
-        function($, ajax, templates, notification, str) {
+define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str', 'core/yui'],
+        function($, ajax, templates, notification, str, Y) {
     return /** @alias module:core/tag */ {
 
         /**
@@ -158,24 +158,27 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str'
                         fldset.append($('<input type="radio" name="maintag" id="combinetags_maintag_' + tagid + '" value="' +
                             tagid + '"/><label for="combinetags_maintag_' + tagid + '">' + tagname + '</label><br>'));
                     });
-                    var panel = new M.core.dialogue({
-                        draggable: true,
-                        modal: true,
-                        closeButton: true,
-                        headerContent: s[0],
-                        bodyContent: el.html()
-                    });
-                    panel.show();
-                    $('#combinetags_form input[type=radio]').first().focus().prop('checked', true);
-                    $('#combinetags_form #combinetags_cancel').on('click', function() {
-                        panel.destroy();
-                    });
-                    $('#combinetags_form').on('submit', function() {
-                        tempElement.appendTo(form);
-                        var maintag = $('input[name=maintag]:checked', '#combinetags_form').val();
-                        $("<input type='hidden'/>").attr('name', 'maintag').attr('value', maintag).appendTo(form);
-                        form.submit();
-                        return false;
+                    // TODO: MDL-57778 Convert to core/modal.
+                    Y.use('moodle-core-notification-dialogue', function() {
+                        var panel = new M.core.dialogue({
+                            draggable: true,
+                            modal: true,
+                            closeButton: true,
+                            headerContent: s[0],
+                            bodyContent: el.html()
+                        });
+                        panel.show();
+                        $('#combinetags_form input[type=radio]').first().focus().prop('checked', true);
+                        $('#combinetags_form #combinetags_cancel').on('click', function() {
+                            panel.destroy();
+                        });
+                        $('#combinetags_form').on('submit', function() {
+                            tempElement.appendTo(form);
+                            var maintag = $('input[name=maintag]:checked', '#combinetags_form').val();
+                            $("<input type='hidden'/>").attr('name', 'maintag').attr('value', maintag).appendTo(form);
+                            form.submit();
+                            return false;
+                        });
                     });
                 });
             });
@@ -221,17 +224,20 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str'
                     el.find('#addtags_form').attr('action', window.location.href);
                     el.find('#addtags_submit').attr('value', s[2]);
                     el.find('#addtags_cancel').attr('value', s[3]);
-                    var panel = new M.core.dialogue({
-                        draggable: true,
-                        modal: true,
-                        closeButton: true,
-                        headerContent: s[0],
-                        bodyContent: el.html()
-                    });
-                    panel.show();
-                    $('#addtags_form input[type=text]').focus();
-                    $('#addtags_form #addtags_cancel').on('click', function() {
-                        panel.destroy();
+                    // TODO: MDL-57778 Convert to core/modal.
+                    Y.use('moodle-core-notification-dialogue', function() {
+                        var panel = new M.core.dialogue({
+                            draggable: true,
+                            modal: true,
+                            closeButton: true,
+                            headerContent: s[0],
+                            bodyContent: el.html()
+                        });
+                        panel.show();
+                        $('#addtags_form input[type=text]').focus();
+                        $('#addtags_form #addtags_cancel').on('click', function() {
+                            panel.destroy();
+                        });
                     });
                 });
             });
@@ -291,25 +297,28 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str'
                         el.find('label[for="addtagcoll_searchable"]').html(s[2]);
                         el.find('#addtagcoll_submit').attr('value', s[3]);
                         el.find('#addtagcoll_cancel').attr('value', s[4]);
-                        var panel = new M.core.dialogue({
-                            draggable: true,
-                            modal: true,
-                            closeButton: true,
-                            headerContent: s[0],
-                            bodyContent: el.html()
-                        });
-                        panel.show();
-                        $('#addtagcoll_form #addtagcoll_name').focus();
-                        $('#addtagcoll_form #addtagcoll_cancel').on('click', function() {
-                            panel.destroy();
-                        });
-                        $('#addtagcoll_form').on('submit', function() {
-                            var name = $('#addtagcoll_form #addtagcoll_name').val();
-                            var searchable = $('#addtagcoll_form #addtagcoll_searchable').prop('checked') ? 1 : 0;
-                            if (String(name).length > 0) {
-                                window.location.href = href + "&name=" + encodeURIComponent(name) + "&searchable=" + searchable;
-                            }
-                            return false;
+                        // TODO: MDL-57778 Convert to core/modal.
+                        Y.use('moodle-core-notification-dialogue', function() {
+                            var panel = new M.core.dialogue({
+                                draggable: true,
+                                modal: true,
+                                closeButton: true,
+                                headerContent: s[0],
+                                bodyContent: el.html()
+                            });
+                            panel.show();
+                            $('#addtagcoll_form #addtagcoll_name').focus();
+                            $('#addtagcoll_form #addtagcoll_cancel').on('click', function() {
+                                panel.destroy();
+                            });
+                            $('#addtagcoll_form').on('submit', function() {
+                                var name = $('#addtagcoll_form #addtagcoll_name').val();
+                                var searchable = $('#addtagcoll_form #addtagcoll_searchable').prop('checked') ? 1 : 0;
+                                if (String(name).length > 0) {
+                                    window.location.href = href + "&name=" + encodeURIComponent(name) + "&searchable=" + searchable;
+                                }
+                                return false;
+                            });
                         });
                     }
                 );