mirror of
https://github.com/moodle/moodle.git
synced 2025-04-24 09:55:33 +02:00
MDL-44342 airnotifier: Add support for shifter in the YUI Module
This commit includes also some integrator review related fixes
This commit is contained in:
parent
438c7020c2
commit
d62c3c6ea8
message/output/airnotifier
db
externallib.phprequestaccesskey.phpsettings.phpyui
build/moodle-message_airnotifier-toolboxes
moodle-message_airnotifier-toolboxes-debug.jsmoodle-message_airnotifier-toolboxes-min.jsmoodle-message_airnotifier-toolboxes.js
src/toolboxes
toolboxes
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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');
|
||||
|
@ -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));
|
||||
}
|
||||
|
252
message/output/airnotifier/yui/build/moodle-message_airnotifier-toolboxes/moodle-message_airnotifier-toolboxes-debug.js
vendored
Normal file
252
message/output/airnotifier/yui/build/moodle-message_airnotifier-toolboxes/moodle-message_airnotifier-toolboxes-debug.js
vendored
Normal file
@ -0,0 +1,252 @@
|
||||
YUI.add('moodle-message_airnotifier-toolboxes', function (Y, NAME) {
|
||||
|
||||
/**
|
||||
* 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);
|
||||
};
|
||||
|
||||
|
||||
|
||||
}, '@VERSION@', {"requires": ["base", "node", "io"]});
|
1
message/output/airnotifier/yui/build/moodle-message_airnotifier-toolboxes/moodle-message_airnotifier-toolboxes-min.js
vendored
Normal file
1
message/output/airnotifier/yui/build/moodle-message_airnotifier-toolboxes/moodle-message_airnotifier-toolboxes-min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
YUI.add("moodle-message_airnotifier-toolboxes",function(e,t){WAITICON={pix:"i/loading_small",component:"moodle"};var n={AIRNOTIFIERCONTENT:"fieldset#messageprocessor_airnotifier",HIDEDEVICE:"a.hidedevice",DEVICELI:"li.airnotifierdevice",DIMCLASS:"dimmed",DIMMEDTEXT:"dimmed_text",DEVICEIDPREFIX:"deviceid-"},r=function(){r.superclass.constructor.apply(this,arguments)};e.extend(r,e.Base,{replace_button:function(t,n,r,i){i||(i="pointer");var s=e.one(t).all(n).setStyle("cursor",i);return s.on("click",r,this),s},toggle_hide_device_ui:function(e){var t=e.ancestor(n.DEVICELI),r=e.one("img"),i=n.DIMMEDTEXT,s="";t.hasClass(i)?s="hide":s="show",t.toggleClass(i);var o=M.util.get_string(s,"moodle");r.setAttrs({alt:o,title:o,src:M.util.image_url("t/"+s)}),e.set("title",o),e.set("className","editing_"+s)},send_request:function(t,n,r){t||(t={});var i=this.get("config").pageparams;for(varname in i)t[varname]=i[varname];n&&n.show(),t.sesskey=M.cfg.sesskey;var s=M.cfg.wwwroot+this.get("ajaxurl"),o=[],u={method:"POST",data:t,on:{success:function(t,i){try{o=e.JSON.parse(i.responseText),o.error?e.use("moodle-core-notification-ajaxexception",function(){return(new M.core.ajaxException(o)).show()}):o.success&&r()}catch(s){}n&&n.hide()},failure:function(t,r){n&&n.hide(),e.use("moodle-core-notification-ajaxexception",function(){return(new M.core.ajaxException(r)).show()})}},context:this,sync:!1};return e.io(s,u),o},get_element_id:function(e){return e.get("id").replace(n.DEVICEIDPREFIX,"")}},{NAME:"device-toolbox",ATTRS:{ajaxurl:{value:0},config:{value:0}}});var i=function(){i.superclass.constructor.apply(this,arguments)};e.extend(i,r,{initializer:function(e){this.setup_for_device()},setup_for_device:function(t){if(!t)var t=n.AIRNOTIFIERCONTENT;e.all(t).each(this._setup_for_device,this)},_setup_for_device:function(e){var t=this.replace_button(e,n.HIDEDEVICE,this.toggle_hide_device)},toggle_hide_device:function(t){t.preventDefault();var r=t.target.ancestor(n.DEVICELI),i=t.target.ancestor("a",!0),s;r.hasClass(n.DIMMEDTEXT)?s=1:s=0;var o={field:"enable",enable:s,id:this.get_element_id(r)},u=M.util.add_spinner(e,r),a=this,f=function(){a.toggle_hide_device_ui(i)};this.send_request(o,u,f)}},{NAME:"message-device-toolbox",ATTRS:{}}),M.message=M.message||{},M.message.init_device_toolbox=function(e){return new i(e)}},"@VERSION@",{requires:["base","node","io"]});
|
252
message/output/airnotifier/yui/build/moodle-message_airnotifier-toolboxes/moodle-message_airnotifier-toolboxes.js
vendored
Normal file
252
message/output/airnotifier/yui/build/moodle-message_airnotifier-toolboxes/moodle-message_airnotifier-toolboxes.js
vendored
Normal file
@ -0,0 +1,252 @@
|
||||
YUI.add('moodle-message_airnotifier-toolboxes', function (Y, NAME) {
|
||||
|
||||
/**
|
||||
* 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);
|
||||
};
|
||||
|
||||
|
||||
|
||||
}, '@VERSION@', {"requires": ["base", "node", "io"]});
|
10
message/output/airnotifier/yui/src/toolboxes/build.json
Normal file
10
message/output/airnotifier/yui/src/toolboxes/build.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "moodle-message_airnotifier-toolboxes",
|
||||
"builds": {
|
||||
"moodle-message_airnotifier-toolboxes": {
|
||||
"jsfiles": [
|
||||
"toolboxes.js"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
247
message/output/airnotifier/yui/src/toolboxes/js/toolboxes.js
vendored
Executable file
247
message/output/airnotifier/yui/src/toolboxes/js/toolboxes.js
vendored
Executable file
@ -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);
|
||||
};
|
||||
|
@ -0,0 +1,9 @@
|
||||
{
|
||||
"moodle-message_airnotifier-toolboxes": {
|
||||
"requires": [
|
||||
"base",
|
||||
"node",
|
||||
"io"
|
||||
]
|
||||
}
|
||||
}
|
@ -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']
|
||||
}
|
||||
);
|
Loading…
x
Reference in New Issue
Block a user