MDL-48493 admin: Add icon to repeat permission check in plugin installer
authorDavid Mudrák <david@moodle.com>
Fri, 12 Dec 2014 15:25:06 +0000 (16:25 +0100)
committerDavid Mudrák <david@moodle.com>
Thu, 15 Jan 2015 11:58:14 +0000 (12:58 +0100)
admin/tool/installaddon/lang/en/tool_installaddon.php
admin/tool/installaddon/renderer.php
admin/tool/installaddon/yui/permcheck/permcheck.js

index 236ad00..76d27b9 100644 (file)
@@ -50,6 +50,7 @@ $string['permcheckerror'] = 'Error while checking for write permission';
 $string['permcheckprogress'] = 'Checking for write permission ...';
 $string['permcheckresultno'] = 'Plugin type location <em>{$a->path}</em> is not writable';
 $string['permcheckresultyes'] = 'Plugin type location <em>{$a->path}</em> is writable';
+$string['permcheckrepeat'] = 'Check again';
 $string['pluginname'] = 'Plugin installer';
 $string['remoterequestalreadyinstalled'] = 'There is a request to install plugin {$a->name} ({$a->component}) version {$a->version} from the Moodle plugins directory on this site. However, this plugin is <strong>already installed</strong> on the site.';
 $string['remoterequestconfirm'] = 'There is a request to install plugin <strong>{$a->name}</strong> ({$a->component}) version {$a->version} from the Moodle plugins directory on this site. If you continue, the plugin ZIP package will be downloaded for validation. Nothing will be installed yet.';
index c4c9706..51e298f 100644 (file)
@@ -83,7 +83,8 @@ class tool_installaddon_renderer extends plugin_renderer_base {
         $this->page->requires->yui_module('moodle-tool_installaddon-permcheck', 'M.tool_installaddon.permcheck.init',
             array(array('permcheckurl' => $permcheckurl->out())));
         $this->page->requires->strings_for_js(
-            array('permcheckprogress', 'permcheckresultno', 'permcheckresultyes', 'permcheckerror'), 'tool_installaddon');
+            array('permcheckprogress', 'permcheckresultno', 'permcheckresultyes', 'permcheckerror', 'permcheckrepeat'),
+            'tool_installaddon');
 
         $out = $this->output->header();
         $out .= $this->index_page_heading();
index 97578b8..700f064 100644 (file)
@@ -22,16 +22,25 @@ YUI.add('moodle-tool_installaddon-permcheck', function(Y) {
             this.config = config;
             var plugintypesel = Y.one('#tool_installaddon_installfromzip_plugintype');
             if (plugintypesel) {
-                plugintypesel.on('change', this.check_for_permission, this);
+                plugintypesel.on('change', function() {
+                    this.check_for_permission(plugintypesel);
+                }, this);
+                this.repeat_permcheck_icon = Y.Node.create('<div><a href="#repeat-permcheck"><img src="' + M.util.image_url('i/reload') + '" /> ' +
+                    M.util.get_string('permcheckrepeat', 'tool_installaddon') + '</a></div>');
+                this.repeat_permcheck_icon.one('a').on('click', function(e) {
+                    e.preventDefault();
+                    this.check_for_permission(plugintypesel);
+                }, this);
             }
         },
 
         /**
          * @method check_for_permission
-         * @param {Event} e
+         * @param {Node} plugintypesel Plugin type selector node
          */
-        check_for_permission : function(e) {
-            var plugintype = e.currentTarget.get('value');
+        check_for_permission : function(plugintypesel) {
+            var plugintype = plugintypesel.get('value');
+
             if (plugintype == '') {
                 return;
             }
@@ -42,27 +51,10 @@ YUI.add('moodle-tool_installaddon-permcheck', function(Y) {
                     'sesskey' : M.cfg.sesskey,
                     'plugintype' : plugintype
                 },
-                'arguments' : {
-                    'plugintypeselector' : e.currentTarget,
-                    'showresult' : function(msg, status) {
-                        var resultline = Y.one('#tool_installaddon_installfromzip_permcheck');
-                        if (resultline) {
-                            if (status === 'success') {
-                                resultline.setContent('<span class="success"><img src="' + M.util.image_url('i/valid') + '" /> ' +
-                                    msg + '</span>');
-                            } else if (status === 'progress') {
-                                resultline.setContent('<span class="progress"><img src="' + M.cfg.loadingicon + '" /> ' +
-                                    msg + '</span>');
-                            } else {
-                                resultline.setContent('<span class="error"><img src="' + M.util.image_url('i/invalid') + '" /> ' +
-                                    msg + '</span>');
-                            }
-                        }
-                    }
-                },
+                'context' : this,
                 'on' : {
                     'start' : function(transid, args) {
-                        args.showresult(M.util.get_string('permcheckprogress', 'tool_installaddon'), 'progress');
+                        this.showresult(M.util.get_string('permcheckprogress', 'tool_installaddon'), 'progress');
                     },
                     'success': function(transid, outcome, args) {
                         var response;
@@ -70,29 +62,56 @@ YUI.add('moodle-tool_installaddon-permcheck', function(Y) {
                             response = Y.JSON.parse(outcome.responseText);
                             if (response.error) {
                                 Y.log(response.error, 'error', 'moodle-tool_installaddon-permcheck');
-                                args.showresult(M.util.get_string('permcheckerror', 'tool_installaddon', response), 'error');
+                                this.showresult(M.util.get_string('permcheckerror', 'tool_installaddon', response), 'error');
                             } else if (response.path && response.writable == 1) {
-                                args.showresult(M.util.get_string('permcheckresultyes', 'tool_installaddon', response), 'success');
+                                this.showresult(M.util.get_string('permcheckresultyes', 'tool_installaddon', response), 'success');
                             } else if (response.path && response.writable == 0) {
-                                args.showresult(M.util.get_string('permcheckresultno', 'tool_installaddon', response), 'error');
+                                this.showresult(M.util.get_string('permcheckresultno', 'tool_installaddon', response), 'error');
                             } else {
                                 Y.log(response, 'debug', 'moodle-tool_installaddon-permcheck');
-                                args.showresult(M.util.get_string('permcheckerror', 'tool_installaddon', response), 'error');
+                                this.showresult(M.util.get_string('permcheckerror', 'tool_installaddon', response), 'error');
                             }
 
                         } catch (e) {
                             Y.log(e, 'error', 'moodle-tool_installaddon-permcheck');
-                            args.showresult(M.util.get_string('permcheckerror', 'tool_installaddon'), 'error');
+                            this.showresult(M.util.get_string('permcheckerror', 'tool_installaddon'), 'error');
                         }
                     },
                     'failure': function(transid, outcome, args) {
                         Y.log(outcome.statusText, 'error', 'moodle-tool_installaddon-permcheck');
-                        args.showresult(M.util.get_string('permcheckerror', 'tool_installaddon'));
+                        this.showresult(M.util.get_string('permcheckerror', 'tool_installaddon'));
                     }
                 }
             });
         },
 
+        /**
+         * @method showresult
+         * @param {String} msg Message to display
+         * @param {String} status Message status
+         */
+        showresult : function(msg, status) {
+            var resultline = Y.one('#tool_installaddon_installfromzip_permcheck');
+            if (resultline) {
+                if (status === 'success') {
+                    resultline.setHTML('<span class="success"><img src="' + M.util.image_url('i/valid') + '" /> ' +
+                        msg + '</span>');
+                } else if (status === 'progress') {
+                    resultline.setHTML('<span class="progress"><img src="' + M.cfg.loadingicon + '" /> ' +
+                        msg + '</span>');
+                } else {
+                    resultline.setHTML('<span class="error"><img src="' + M.util.image_url('i/invalid') + '" /> ' +
+                        msg + '</span>').append(this.repeat_permcheck_icon);
+                }
+            }
+        },
+
+        /**
+         * @property
+         * @type {Y.Node}
+         */
+        repeat_permcheck_icon : null,
+
         /**
          * @property
          * @type {Object}