MDL-44342 airnotifier: Add support for shifter in the YUI Module
authorJuan Leyva <juanleyvadelgado@gmail.com>
Mon, 7 Apr 2014 09:52:10 +0000 (11:52 +0200)
committerJuan Leyva <juanleyvadelgado@gmail.com>
Mon, 7 Apr 2014 10:14:09 +0000 (12:14 +0200)
This commit includes also some integrator review related fixes

message/output/airnotifier/db/install.php
message/output/airnotifier/externallib.php
message/output/airnotifier/requestaccesskey.php
message/output/airnotifier/settings.php
message/output/airnotifier/yui/build/moodle-message_airnotifier-toolboxes/moodle-message_airnotifier-toolboxes-debug.js [new file with mode: 0644]
message/output/airnotifier/yui/build/moodle-message_airnotifier-toolboxes/moodle-message_airnotifier-toolboxes-min.js [new file with mode: 0644]
message/output/airnotifier/yui/build/moodle-message_airnotifier-toolboxes/moodle-message_airnotifier-toolboxes.js [new file with mode: 0644]
message/output/airnotifier/yui/src/toolboxes/build.json [new file with mode: 0644]
message/output/airnotifier/yui/src/toolboxes/js/toolboxes.js [new file with mode: 0755]
message/output/airnotifier/yui/src/toolboxes/meta/toolboxes.json [new file with mode: 0644]
message/output/airnotifier/yui/toolboxes/toolboxes.js [deleted file]

index 433698b..81c0bf4 100755 (executable)
@@ -32,6 +32,7 @@ function xmldb_message_airnotifier_install() {
 
     $provider = new stdClass();
     $provider->name = 'airnotifier';
+    $provider->enabled = 0;
     $DB->insert_record('message_processors', $provider);
 
     return $result;
index b61f704..dbe89d5 100755 (executable)
@@ -56,7 +56,15 @@ class message_airnotifier_external extends external_api {
      * @since Moodle 2.7
      */
     public static function is_system_configured() {
+        global $DB;
 
+        // First, check if the plugin is disabled.
+        $processor = $DB->get_record('message_processors', array('name' => 'airnotifier'), '*', MUST_EXIST);
+        if (!$processor->enabled) {
+            return 0;
+        }
+
+        // Then, check if the plugin is completly configured.
         $manager = new message_airnotifier_manager();
         return (int) $manager->is_system_configured();
     }
@@ -97,7 +105,7 @@ class message_airnotifier_external extends external_api {
         $params = self::validate_parameters(self::are_notification_preferences_configured_parameters(),
                 array('userids' => $userids));
 
-        list($sqluserids, $params) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);
+        list($sqluserids, $params) = $DB->get_in_or_equal($params['userids'], SQL_PARAMS_NAMED);
         $uselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
         $ujoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = u.id AND ctx.contextlevel = :contextlevel)";
         $params['contextlevel'] = CONTEXT_USER;
@@ -134,8 +142,18 @@ class message_airnotifier_external extends external_api {
                 // Now we get for all the providers and all the states
                 // the user preferences to check if at least one is enabled for airnotifier plugin.
                 $providers = message_get_providers_for_user($user->id);
+                $configured = false;
+
                 foreach ($providers as $provider) {
+                    if ($configured) {
+                        break;
+                    }
+
                     foreach (array('loggedin', 'loggedoff') as $state) {
+                        if ($configured) {
+                            break;
+                        }
+
                         $prefname = 'message_provider_'.$provider->component.'_'.$provider->name.'_'.$state;
                         $linepref = get_user_preferences($prefname, '', $user->id);
                         if ($linepref == '') {
@@ -146,7 +164,8 @@ class message_airnotifier_external extends external_api {
                         foreach ($lineprefarray as $pref) {
                             if ($pref == 'airnotifier') {
                                 $preferences['configured'] = 1;
-                                break 2;
+                                $configured = true;
+                                break;
                             }
                         }
                     }
index 96cf544..457832d 100755 (executable)
@@ -31,6 +31,7 @@ $PAGE->set_url(new moodle_url('/message/output/airnotifier/requestaccesskey.php'
 $PAGE->set_context(context_system::instance());
 
 require_login();
+require_sesskey();
 require_capability('moodle/site:config', context_system::instance());
 
 $strheading = get_string('requestaccesskey', 'message_airnotifier');
index 977a17b..d788f75 100755 (executable)
@@ -41,7 +41,7 @@ if ($ADMIN->fulltree) {
                     get_string('airnotifieraccesskey', 'message_airnotifier'),
                     get_string('configairnotifieraccesskey', 'message_airnotifier'), '', PARAM_ALPHANUMEXT));
 
-    $url = new moodle_url('/message/output/airnotifier/requestaccesskey.php');
+    $url = new moodle_url('/message/output/airnotifier/requestaccesskey.php', array('sesskey' => sesskey()));
     $link = html_writer::link($url, get_string('requestaccesskey', 'message_airnotifier'));
     $settings->add(new admin_setting_heading('requestaccesskey', '', $link));
 }
diff --git a/message/output/airnotifier/yui/build/moodle-message_airnotifier-toolboxes/moodle-message_airnotifier-toolboxes-debug.js b/message/output/airnotifier/yui/build/moodle-message_airnotifier-toolboxes/moodle-message_airnotifier-toolboxes-debug.js
new file mode 100644 (file)
index 0000000..acd18da
Binary files /dev/null and b/message/output/airnotifier/yui/build/moodle-message_airnotifier-toolboxes/moodle-message_airnotifier-toolboxes-debug.js differ
diff --git a/message/output/airnotifier/yui/build/moodle-message_airnotifier-toolboxes/moodle-message_airnotifier-toolboxes-min.js b/message/output/airnotifier/yui/build/moodle-message_airnotifier-toolboxes/moodle-message_airnotifier-toolboxes-min.js
new file mode 100644 (file)
index 0000000..63e59ca
Binary files /dev/null and b/message/output/airnotifier/yui/build/moodle-message_airnotifier-toolboxes/moodle-message_airnotifier-toolboxes-min.js differ
diff --git a/message/output/airnotifier/yui/build/moodle-message_airnotifier-toolboxes/moodle-message_airnotifier-toolboxes.js b/message/output/airnotifier/yui/build/moodle-message_airnotifier-toolboxes/moodle-message_airnotifier-toolboxes.js
new file mode 100644 (file)
index 0000000..acd18da
Binary files /dev/null and b/message/output/airnotifier/yui/build/moodle-message_airnotifier-toolboxes/moodle-message_airnotifier-toolboxes.js differ
diff --git a/message/output/airnotifier/yui/src/toolboxes/build.json b/message/output/airnotifier/yui/src/toolboxes/build.json
new file mode 100644 (file)
index 0000000..6a1b51a
--- /dev/null
@@ -0,0 +1,10 @@
+{
+  "name": "moodle-message_airnotifier-toolboxes",
+  "builds": {
+    "moodle-message_airnotifier-toolboxes": {
+      "jsfiles": [
+        "toolboxes.js"
+      ]
+    }
+  }
+}
diff --git a/message/output/airnotifier/yui/src/toolboxes/js/toolboxes.js b/message/output/airnotifier/yui/src/toolboxes/js/toolboxes.js
new file mode 100755 (executable)
index 0000000..fcb362a
--- /dev/null
@@ -0,0 +1,247 @@
+/**
+ * Provides a tool for enabling/disabling elements using AJAX/REST.
+ *
+ * @module moodle-message_airnotifier-toolboxes
+ */
+
+WAITICON = {
+    'pix':"i/loading_small",
+    'component':'moodle'
+};
+// The CSS selectors we use.
+var CSS = {
+    AIRNOTIFIERCONTENT : 'fieldset#messageprocessor_airnotifier',
+    HIDEDEVICE : 'a.hidedevice',
+    DEVICELI : 'li.airnotifierdevice',
+    DIMCLASS : 'dimmed',
+    DIMMEDTEXT : 'dimmed_text',
+    DEVICEIDPREFIX : 'deviceid-'
+};
+
+/**
+ * The toolbox classes
+ *
+ * TOOLBOX is a generic class which should never be directly instantiated
+ * DEVICETOOLBOX is a class extending TOOLBOX containing code specific to devices
+ */
+var TOOLBOX = function() {
+    TOOLBOX.superclass.constructor.apply(this, arguments);
+};
+
+Y.extend(TOOLBOX, Y.Base, {
+    /**
+     * Replace the button click at the selector with the specified
+     * callback
+     *
+     * @param toolboxtarget The selector of the working area
+     * @param selector The 'button' to replace
+     * @param callback The callback to apply
+     * @param cursor An optional cursor style to apply
+     */
+    replace_button : function(toolboxtarget, selector, callback, cursor) {
+        if (!cursor) {
+            // Set the default cursor type to pointer to match the anchor.
+            cursor = 'pointer';
+        }
+        var button = Y.one(toolboxtarget).all(selector)
+        .setStyle('cursor', cursor);
+
+        // On isn't chainable and will return an event.
+        button.on('click', callback, this);
+
+        return button;
+    },
+    /**
+     * Toggle the visibility and availability for the specified
+     * device show/hide button
+     */
+    toggle_hide_device_ui : function(button) {
+
+        var element = button.ancestor(CSS.DEVICELI);
+        var hideicon = button.one('img');
+
+        var toggle_class = CSS.DIMMEDTEXT;
+
+        var status = '';
+        if (element.hasClass(toggle_class)) {
+            status = 'hide';
+        } else {
+            status = 'show';
+        }
+
+        // Change the UI.
+        element.toggleClass(toggle_class);
+        // We need to toggle dimming on the description too element.all(CSS.CONTENTAFTERLINK).toggleClass(CSS.DIMMEDTEXT);.
+        var newstring = M.util.get_string(status, 'moodle');
+        hideicon.setAttrs({
+            'alt' : newstring,
+            'title' : newstring,
+            'src'   : M.util.image_url('t/' + status)
+        });
+        button.set('title', newstring);
+        button.set('className', 'editing_' + status);
+    },
+    /**
+     * Send a request using the REST API
+     *
+     * @param data The data to submit
+     * @param statusspinner (optional) A statusspinner which may contain a section loader
+     * @param callbacksuccess Call back on success
+     * @return response responseText field from responce
+     */
+    send_request : function(data, statusspinner, callbacksuccess) {
+        // Default data structure
+        if (!data) {
+            data = {};
+        }
+        // Handle any variables which we must pass back through to.
+        var pageparams = this.get('config').pageparams;
+        for (varname in pageparams) {
+            data[varname] = pageparams[varname];
+        }
+
+        if (statusspinner) {
+            statusspinner.show();
+        }
+
+        data.sesskey = M.cfg.sesskey;
+
+        var uri = M.cfg.wwwroot + this.get('ajaxurl');
+
+        // Define the configuration to send with the request.
+        var responsetext = [];
+        var config = {
+            method: 'POST',
+            data: data,
+            on: {
+                success: function(tid, response) {
+                    try {
+                        responsetext = Y.JSON.parse(response.responseText);
+                        if (responsetext.error) {
+                            Y.use('moodle-core-notification-ajaxexception', function() {
+                                return new M.core.ajaxException(responsetext).show();
+                            });
+                        } else if (responsetext.success) {
+                            callbacksuccess();
+                        }
+                    } catch (e) {}
+                    if (statusspinner) {
+                        statusspinner.hide();
+                    }
+                },
+                failure : function(tid, response) {
+                    if (statusspinner) {
+                        statusspinner.hide();
+                    }
+                    Y.use('moodle-core-notification-ajaxexception', function() {
+                        return new M.core.ajaxException(response).show();
+                    });
+                }
+            },
+            context: this,
+            sync: false
+        };
+
+        // Send the request.
+        Y.io(uri, config);
+        return responsetext;
+    },
+    /**
+     * Return the module ID for the specified element
+     *
+     * @param element The <li> element to determine a module-id number for
+     * @return string The module ID
+     */
+    get_element_id : function(element) {
+        return element.get('id').replace(CSS.DEVICEIDPREFIX, '');
+    }
+},
+{
+    NAME : 'device-toolbox',
+    ATTRS : {
+        ajaxurl : {
+            'value' : 0
+        },
+        config : {
+            'value' : 0
+        }
+    }
+}
+);
+
+var DEVICETOOLBOX = function() {
+    DEVICETOOLBOX.superclass.constructor.apply(this, arguments);
+};
+
+Y.extend(DEVICETOOLBOX, TOOLBOX, {
+
+    /**
+     * Initialize the device toolbox
+     *
+     * Updates all span.commands with relevant handlers and other required changes
+     */
+    initializer : function(config) {
+        this.setup_for_device();
+    },
+    /**
+     * Update any span.commands within the scope of the specified
+     * selector with AJAX equivelants
+     *
+     * @param baseselector The selector to limit scope to
+     * @return void
+     */
+    setup_for_device : function(baseselector) {
+        if (!baseselector) {
+            var baseselector = CSS.AIRNOTIFIERCONTENT;
+        }
+
+        Y.all(baseselector).each(this._setup_for_device, this);
+    },
+    _setup_for_device : function(toolboxtarget) {
+
+        // Show/Hide.
+        var showhide = this.replace_button(toolboxtarget, CSS.HIDEDEVICE, this.toggle_hide_device);
+    },
+    toggle_hide_device : function(e) {
+        // Prevent the default button action.
+        e.preventDefault();
+
+        // Get the element we're working on.
+        var element = e.target.ancestor(CSS.DEVICELI);
+
+        var button = e.target.ancestor('a', true);
+
+        var value;
+        // Enable the device in case the CSS is dimmed.
+        if (element.hasClass(CSS.DIMMEDTEXT)) {
+            value = 1;
+        } else {
+            value = 0;
+        }
+
+        // Send the request.
+        var data = {
+            'field' : 'enable',
+            'enable' : value,
+            'id'    : this.get_element_id(element)
+        };
+        var spinner = M.util.add_spinner(Y, element);
+
+        var context = this;
+        var callback = function() {
+            context.toggle_hide_device_ui(button);
+        };
+        this.send_request(data, spinner, callback);
+    }
+}, {
+    NAME : 'message-device-toolbox',
+    ATTRS : {
+}
+});
+
+M.message = M.message || {};
+
+M.message.init_device_toolbox = function(config) {
+    return new DEVICETOOLBOX(config);
+};
+
diff --git a/message/output/airnotifier/yui/src/toolboxes/meta/toolboxes.json b/message/output/airnotifier/yui/src/toolboxes/meta/toolboxes.json
new file mode 100644 (file)
index 0000000..402d910
--- /dev/null
@@ -0,0 +1,9 @@
+{
+  "moodle-message_airnotifier-toolboxes": {
+    "requires": [
+        "base",
+        "node",
+        "io"
+    ]
+  }
+}
diff --git a/message/output/airnotifier/yui/toolboxes/toolboxes.js b/message/output/airnotifier/yui/toolboxes/toolboxes.js
deleted file mode 100755 (executable)
index 6d46fe9..0000000
+++ /dev/null
@@ -1,247 +0,0 @@
-YUI.add('moodle-message_airnotifier-toolboxes', function(Y) {
-    WAITICON = {
-        'pix':"i/loading_small",
-        'component':'moodle'
-    };
-    // The CSS selectors we use.
-    var CSS = {
-        AIRNOTIFIERCONTENT : 'fieldset#messageprocessor_airnotifier',
-        HIDEDEVICE : 'a.hidedevice',
-        DEVICELI : 'li.airnotifierdevice',
-        DIMCLASS : 'dimmed',
-        DIMMEDTEXT : 'dimmed_text',
-        DEVICEIDPREFIX : 'deviceid-'
-    };
-
-    /**
-     * The toolbox classes
-     *
-     * TOOLBOX is a generic class which should never be directly instantiated
-     * DEVICETOOLBOX is a class extending TOOLBOX containing code specific to devices
-     */
-    var TOOLBOX = function() {
-        TOOLBOX.superclass.constructor.apply(this, arguments);
-    }
-
-    Y.extend(TOOLBOX, Y.Base, {
-        /**
-         * Replace the button click at the selector with the specified
-         * callback
-         *
-         * @param toolboxtarget The selector of the working area
-         * @param selector The 'button' to replace
-         * @param callback The callback to apply
-         * @param cursor An optional cursor style to apply
-         */
-        replace_button : function(toolboxtarget, selector, callback, cursor) {
-            if (!cursor) {
-                // Set the default cursor type to pointer to match the anchor.
-                cursor = 'pointer';
-            }
-            var button = Y.one(toolboxtarget).all(selector)
-            .setStyle('cursor', cursor);
-
-            // On isn't chainable and will return an event.
-            button.on('click', callback, this);
-
-            return button;
-        },
-        /**
-           * Toggle the visibility and availability for the specified
-           * device show/hide button
-           */
-        toggle_hide_device_ui : function(button) {
-
-            var element = button.ancestor(CSS.DEVICELI);
-            var hideicon = button.one('img');
-
-            var toggle_class = CSS.DIMMEDTEXT;
-
-            var status = '';
-            if (element.hasClass(toggle_class)) {
-                status = 'hide';
-            } else {
-                status = 'show';
-            }
-
-            // Change the UI.
-            element.toggleClass(toggle_class);
-            // We need to toggle dimming on the description too element.all(CSS.CONTENTAFTERLINK).toggleClass(CSS.DIMMEDTEXT);.
-            var newstring = M.util.get_string(status, 'moodle');
-            hideicon.setAttrs({
-                'alt' : newstring,
-                'title' : newstring,
-                'src'   : M.util.image_url('t/' + status)
-            });
-            button.set('title', newstring);
-            button.set('className', 'editing_' + status);
-        },
-        /**
-         * Send a request using the REST API
-         *
-         * @param data The data to submit
-         * @param statusspinner (optional) A statusspinner which may contain a section loader
-         * @param callbacksuccess Call back on success
-         * @return response responseText field from responce
-         */
-        send_request : function(data, statusspinner, callbacksuccess) {
-            // Default data structure
-            if (!data) {
-                data = {};
-            }
-            // Handle any variables which we must pass back through to.
-            var pageparams = this.get('config').pageparams;
-            for (varname in pageparams) {
-                data[varname] = pageparams[varname];
-            }
-
-            if (statusspinner) {
-                statusspinner.show();
-            }
-
-            data.sesskey = M.cfg.sesskey;
-
-            var uri = M.cfg.wwwroot + this.get('ajaxurl');
-
-            // Define the configuration to send with the request.
-            var responsetext = [];
-            var config = {
-                method: 'POST',
-                data: data,
-                on: {
-                    success: function(tid, response) {
-                        try {
-                            responsetext = Y.JSON.parse(response.responseText);
-                            if (responsetext.error) {
-                                Y.use('moodle-core-notification-ajaxexception', function() {
-                                    return new M.core.ajaxException(responsetext).show();
-                                });
-                            } else if (responsetext.success) {
-                                callbacksuccess();
-                            }
-                        } catch (e) {}
-                        if (statusspinner) {
-                            statusspinner.hide();
-                        }
-                    },
-                    failure : function(tid, response) {
-                        if (statusspinner) {
-                            statusspinner.hide();
-                        }
-                        Y.use('moodle-core-notification-ajaxexception', function() {
-                            return new M.core.ajaxException(response).show();
-                        });
-                    }
-                },
-                context: this,
-                sync: false
-            },
-
-            // Send the request.
-            Y.io(uri, config);
-            return responsetext;
-        },
-        /**
-         * Return the module ID for the specified element
-         *
-         * @param element The <li> element to determine a module-id number for
-         * @return string The module ID
-         */
-        get_element_id : function(element) {
-            return element.get('id').replace(CSS.DEVICEIDPREFIX, '');
-        }
-    },
-    {
-        NAME : 'device-toolbox',
-        ATTRS : {
-            ajaxurl : {
-                'value' : 0
-            },
-            config : {
-                'value' : 0
-            }
-        }
-    }
-    );
-
-    var DEVICETOOLBOX = function() {
-        DEVICETOOLBOX.superclass.constructor.apply(this, arguments);
-    }
-
-    Y.extend(DEVICETOOLBOX, TOOLBOX, {
-
-        /**
-         * Initialize the device toolbox
-         *
-         * Updates all span.commands with relevant handlers and other required changes
-         */
-        initializer : function(config) {
-            this.setup_for_device();
-        },
-        /**
-         * Update any span.commands within the scope of the specified
-         * selector with AJAX equivelants
-         *
-         * @param baseselector The selector to limit scope to
-         * @return void
-         */
-        setup_for_device : function(baseselector) {
-            if (!baseselector) {
-                var baseselector = CSS.AIRNOTIFIERCONTENT;
-            }
-
-            Y.all(baseselector).each(this._setup_for_device, this);
-        },
-        _setup_for_device : function(toolboxtarget) {
-
-            // Show/Hide.
-            var showhide = this.replace_button(toolboxtarget, CSS.HIDEDEVICE, this.toggle_hide_device);
-        },
-        toggle_hide_device : function(e) {
-            // Prevent the default button action.
-            e.preventDefault();
-
-            // Get the element we're working on.
-            var element = e.target.ancestor(CSS.DEVICELI);
-
-            var button = e.target.ancestor('a', true);
-
-            var value;
-            // Enable the device in case the CSS is dimmed.
-            if (element.hasClass(CSS.DIMMEDTEXT)) {
-                value = 1;
-            } else {
-                value = 0;
-            }
-
-            // Send the request.
-            var data = {
-                'field' : 'enable',
-                'enable' : value,
-                'id'    : this.get_element_id(element)
-            };
-            var spinner = M.util.add_spinner(Y, element);
-
-            var context = this;
-            var callback = function() {
-                context.toggle_hide_device_ui(button);
-            };
-            this.send_request(data, spinner, callback);
-        }
-    }, {
-        NAME : 'message-device-toolbox',
-        ATTRS : {
-    }
-    });
-
-    M.message = M.message || {};
-
-    M.message.init_device_toolbox = function(config) {
-        return new DEVICETOOLBOX(config);
-    };
-
-},
-'@VERSION@', {
-    requires : ['base', 'node', 'io']
-}
-);