Skip to content

Commit

Permalink
MDL-21420 modole_cfg converted to M.cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Jan 21, 2010
1 parent 7b42e81 commit 9598d57
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 59 deletions.
6 changes: 3 additions & 3 deletions admin/report/spamcleaner/spamcleaner.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function init() {
YAHOO.util.Event.addListener("removeall_btn", "click", function(){
var yes = confirm(mstr.report_spamcleaner.spamdeleteallconfirm);
if(yes){
var cObj = YAHOO.util.Connect.asyncRequest('POST', spamcleaner.me+'?delall=yes&sesskey='+moodle_cfg.sesskey, delall_cb);
var cObj = YAHOO.util.Connect.asyncRequest('POST', spamcleaner.me+'?delall=yes&sesskey='+M.cfg.sesskey, delall_cb);
}
});
}
Expand Down Expand Up @@ -64,11 +64,11 @@ function del_user(obj, id) {
var yes = confirm(mstr.report_spamcleaner.spamdeleteconfirm);
if(yes){
row = obj;
var cObj = YAHOO.util.Connect.asyncRequest('POST', spamcleaner.me+'?del=yes&sesskey='+moodle_cfg.sesskey+'&id='+id, del_cb);
var cObj = YAHOO.util.Connect.asyncRequest('POST', spamcleaner.me+'?del=yes&sesskey='+M.cfg.sesskey+'&id='+id, del_cb);
}
}
function ignore_user(obj, id) {
row = obj;
var cObj = YAHOO.util.Connect.asyncRequest('POST', spamcleaner.me+'?ignore=yes&sesskey='+moodle_cfg.sesskey+'&id='+id, ignore_cb);
var cObj = YAHOO.util.Connect.asyncRequest('POST', spamcleaner.me+'?ignore=yes&sesskey='+M.cfg.sesskey+'&id='+id, ignore_cb);
}
YAHOO.util.Event.onDOMReady(init);
4 changes: 2 additions & 2 deletions blocks/global_navigation_tree/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ M.blocks.navigation.classes.tree.prototype.init_load_ajax = function(e, branch)
if (this.instance != null) {
cfginstance = '&instance='+this.instance
}
Y.io(moodle_cfg.wwwroot+'/lib/ajax/getnavbranch.php', {
Y.io(M.cfg.wwwroot+'/lib/ajax/getnavbranch.php', {
method:'POST',
data:'elementid='+branch.id+'&id='+branch.branchid+'&type='+branch.type+'&sesskey='+moodle_cfg.sesskey+cfginstance,
data:'elementid='+branch.id+'&id='+branch.branchid+'&type='+branch.type+'&sesskey='+M.cfg.sesskey+cfginstance,
on: {
complete:this.load_ajax,
success:function() {Y.detach('click', this.init_load_ajax, e.target);}
Expand Down
4 changes: 2 additions & 2 deletions comment/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function init() {
}
}
function delete_comments() {
var url = moodle_cfg.wwwroot + '/comment/index.php';
var url = M.cfg.wwwroot + '/comment/index.php';
var cb = {
success:function(o) {
if (o.responseText == 'yes') {
Expand All @@ -37,7 +37,7 @@ function delete_comments() {
}
var data = {
'commentids': list,
'sesskey': moodle_cfg.sesskey
'sesskey': M.cfg.sesskey
}
var trans = YAHOO.util.Connect.asyncRequest('POST',
url+'?action=delete', cb, build_querystring(data));
Expand Down
18 changes: 9 additions & 9 deletions comment/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function cmt_replace(client_id,list,newcmt) {
var val = template.innerHTML;
val = val.replace('___name___', list[i].username);
if (list[i]['delete']||newcmt) {
list[i].content = '<div class="comment-delete"><a href="###" title="'+mstr.moodle.deletecomment+'" onclick="delete_comment(\''+client_id+'\',\''+list[i].id+'\')"><img src="'+moodle_cfg.wwwroot+'/pix/t/delete.gif" /></a></div>' + list[i].content;
list[i].content = '<div class="comment-delete"><a href="###" title="'+mstr.moodle.deletecomment+'" onclick="delete_comment(\''+client_id+'\',\''+list[i].id+'\')"><img src="'+M.cfg.wwwroot+'/pix/t/delete.gif" /></a></div>' + list[i].content;
}
val = val.replace('___time___', list[i].time);
val = val.replace('___picture___', list[i].avatar);
Expand All @@ -26,18 +26,18 @@ function cmt_replace(client_id,list,newcmt) {
}
function cmt_load(cid) {
var container = document.getElementById('comment-list-'+cid);
container.innerHTML = '<div style="text-align:center"><img src="'+moodle_cfg.wwwroot+'/pix/i/loading.gif'+'" /></div>';
container.innerHTML = '<div style="text-align:center"><img src="'+M.cfg.wwwroot+'/pix/i/loading.gif'+'" /></div>';
}
function get_comments(client_id, area, itemid, page) {
var url = moodle_cfg.wwwroot + '/comment/comment_ajax.php';
var url = M.cfg.wwwroot + '/comment/comment_ajax.php';
var data = {
'courseid': comment_params.courseid,
'contextid': comment_params.contextid,
'area': area,
'itemid': itemid,
'page': page,
'client_id': client_id,
'sesskey': moodle_cfg.sesskey
'sesskey': M.cfg.sesskey
}
this.cb = {
success: function(o) {
Expand Down Expand Up @@ -93,7 +93,7 @@ function post_comment(cid) {
}
var ta = document.getElementById('dlg-content-'+cid);
if (ta.value && ta.value != mstr.moodle.addcomment) {
var url = moodle_cfg.wwwroot + '/comment/comment_ajax.php';
var url = M.cfg.wwwroot + '/comment/comment_ajax.php';
var formObject = document.getElementById('comment-form-'+cid);
YAHOO.util.Connect.setForm(formObject);
var trans = YAHOO.util.Connect.asyncRequest('POST', url+'?action=add', this.cb);
Expand All @@ -106,13 +106,13 @@ function post_comment(cid) {
}
}
function delete_comment(client_id, comment_id) {
var url = moodle_cfg.wwwroot + '/comment/comment_ajax.php';
var url = M.cfg.wwwroot + '/comment/comment_ajax.php';
var data = {
'courseid': comment_params.courseid,
'contextid': comment_params.contextid,
'commentid': comment_id,
'client_id': client_id,
'sesskey': moodle_cfg.sesskey
'sesskey': M.cfg.sesskey
}
this.cb = {
success: function(o) {
Expand Down Expand Up @@ -146,11 +146,11 @@ function view_comments(client_id, area, itemid, page) {
// show
get_comments(client_id, area, itemid, page);
container.style.display = 'block';
img.src=moodle_cfg.wwwroot+'/pix/t/expanded.png';
img.src=M.cfg.wwwroot+'/pix/t/expanded.png';
} else {
// hide
container.style.display = 'none';
img.src=moodle_cfg.wwwroot+'/pix/t/collapsed.png';
img.src=M.cfg.wwwroot+'/pix/t/collapsed.png';
ta.value = '';
}
toggle_textarea.apply(ta, [false]);
Expand Down
2 changes: 1 addition & 1 deletion course/completion.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function completion_toggle(e) {
YAHOO.util.Event.preventDefault(e);
// By setting completion_wwwroot you can cause it to use absolute path
// otherwise script assumes it is called from somewhere in /course
var target = moodle_cfg.wwwroot + '/course/togglecompletion.php';
var target = M.cfg.wwwroot + '/course/togglecompletion.php';
YAHOO.util.Connect.asyncRequest('POST',target,
{success:completion_handle_response,failure:completion_handle_failure,scope:this},
'id='+this.cmid+'&completionstate='+this.otherState+'&fromajax=1');
Expand Down
2 changes: 1 addition & 1 deletion enrol/authorize/authorize.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function authorize_jump_to_mypayments(e, args) {
var locationtogo = moodle_cfg.wwwroot + '/enrol/authorize/index.php?status=' + args.status;
var locationtogo = M.cfg.wwwroot + '/enrol/authorize/index.php?status=' + args.status;
locationtogo += '&user=' + (this.checked ? args.userid : '0');
top.location.href = locationtogo;
}
11 changes: 7 additions & 4 deletions lib/ajax/ajaxlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ class page_requirements_manager {
protected $yui3loader;
/** YUI PHPLoader instance responsible for YUI3 loading from javascript */
protected $M_yui_loader;
/** some config vars exposend in JS, please no secret stuff there */
protected $M_cfg;

/**
* Page requirements constructor.
Expand Down Expand Up @@ -215,17 +217,16 @@ protected function init_requirements_data(moodle_page $page, core_renderer $rend

//TODO: problem here is we may need this in some included JS - move this somehow to the very beginning
// right after the YUI loading
$config = array(
$this->M_cfg = array(
'wwwroot' => $CFG->httpswwwroot, // Yes, really. See above.
'sesskey' => sesskey(),
'loadingicon' => $renderer->pix_url('i/loading_small', 'moodle')->out(false),
'themerev' => theme_get_revision(),
'theme' => $page->theme->name,
);
if (debugging('', DEBUG_DEVELOPER)) {
$config['developerdebug'] = true;
$this->M_cfg['developerdebug'] = true;
}
$this->data_for_js('moodle_cfg', $config)->in_head();

if (debugging('', DEBUG_DEVELOPER)) {
$this->yui2_lib('logger');
Expand Down Expand Up @@ -785,7 +786,9 @@ public function get_head_code(moodle_page $page, core_renderer $renderer) {
// set up global YUI3 loader object - this should contain all code needed by plugins
// note: in JavaScript just use "YUI(M.yui.loader).use('overlay', function(Y) { .... });"
// this needs to be done before including any other script
$js = "var M = {}; M.yui = {}; " . js_writer::set_variable('M.yui.loader', $this->M_yui_loader, false);
$js = "var M = {}; M.yui = {}; ";
$js .= js_writer::set_variable('M.yui.loader', $this->M_yui_loader, false) . "\n";
$js .= js_writer::set_variable('M.cfg', $this->M_cfg, false);
$output .= html_writer::script($js);

// link our main JS file, all core stuff should be there
Expand Down
28 changes: 14 additions & 14 deletions lib/form/filemanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ YAHOO.moodle.filemanager.mkdir_dialog = null;
// an object used to record filemanager instances' data,
// we use it quite often
var fm_cfg = {};
fm_cfg.api = moodle_cfg.wwwroot + '/files/files_ajax.php';
fm_cfg.api = M.cfg.wwwroot + '/files/files_ajax.php';

// initialize file manager
var filemanager = (function(){
Expand Down Expand Up @@ -151,7 +151,7 @@ function fm_create_folder(e, client_id, itemid) {
var params = [];
params['itemid'] = itemid;
params['newdirname'] = foldername;
params['sesskey'] = moodle_cfg.sesskey;
params['sesskey'] = M.cfg.sesskey;
params['filepath'] = fm_cfg[client_id].currentpath;
var trans = YAHOO.util.Connect.asyncRequest('POST',
fm_cfg.api+'?action=mkdir', mkdir_ajax_callback, build_querystring(params));
Expand Down Expand Up @@ -313,11 +313,11 @@ function html_compiler(client_id, options) {

// add green tick to main file
if (ismainfile) {
fullname = "<strong>"+list[i].fullname+"</strong> <img src='"+moodle_cfg.wwwroot+"/pix/i/tick_green_small.gif"+"' />";
fullname = "<strong>"+list[i].fullname+"</strong> <img src='"+M.cfg.wwwroot+"/pix/i/tick_green_small.gif"+"' />";
}

html = html.replace('___fullname___', '<a href="'+url+'" id="'+fileid+'"><img src="'+list[i].icon+'" /> ' + fullname + '</a>');
html = html.replace('___action___', '<a style="display:none" href="###" id="'+action+'"><img alt="▶" src="'+moodle_cfg.wwwroot+'/pix/i/settings.gif'+'" /></a>');
html = html.replace('___action___', '<a style="display:none" href="###" id="'+action+'"><img alt="▶" src="'+M.cfg.wwwroot+'/pix/i/settings.gif'+'" /></a>');
html = '<li id="'+htmlid+'">'+html+'</li>';
listhtml += html;
}
Expand All @@ -341,7 +341,7 @@ function fm_refresh(path, args) {
var params = [];
params['itemid'] = args.itemid;
params['filepath'] = path;
params['sesskey'] = moodle_cfg.sesskey;
params['sesskey'] = M.cfg.sesskey;
this.cb = {
success: function(o) {
var data = json_decode(o.responseText);
Expand Down Expand Up @@ -379,7 +379,7 @@ function fm_mouseout_menu(ev, args) {
function fm_click_breadcrumb(ev, args) {
var params = [];
params['itemid'] = args.itemid;
params['sesskey'] = moodle_cfg.sesskey;
params['sesskey'] = M.cfg.sesskey;
params['filepath'] = args.requestpath;
this.cb = {
success: function(o) {
Expand Down Expand Up @@ -422,7 +422,7 @@ function fm_create_foldermenu(e, data) {
params['itemid'] = obj.itemid;
params['filepath'] = this.file.filepath;
params['filename'] = '.';
params['sesskey'] = moodle_cfg.sesskey;
params['sesskey'] = M.cfg.sesskey;
fm_loading('filemanager-'+obj.client_id, 'fm-prgressbar');
var trans = YAHOO.util.Connect.asyncRequest('POST',
fm_cfg.api+'?action=zip', this.cb, build_querystring(params));
Expand Down Expand Up @@ -459,7 +459,7 @@ function fm_create_zipmenu(e, data) {
params['itemid'] = obj.itemid;
params['filepath'] = this.file.filepath;
params['filename'] = this.file.fullname;
params['sesskey'] = moodle_cfg.sesskey;
params['sesskey'] = M.cfg.sesskey;
fm_loading('filemanager-'+obj.client_id, 'fm-prgressbar');
var trans = YAHOO.util.Connect.asyncRequest('POST',
fm_cfg.api+'?action=unzip', this.cb, build_querystring(params));
Expand Down Expand Up @@ -491,7 +491,7 @@ function fm_create_menu(ev, menuid, menuitems, file, options) {
params['filepath'] = fm_cfg[this.client_id].currentpath;
}
params['itemid'] = this.itemid;
params['sesskey'] = moodle_cfg.sesskey;
params['sesskey'] = M.cfg.sesskey;
fm_loading('filemanager-'+this.client_id, 'fm-prgressbar');
var trans = YAHOO.util.Connect.asyncRequest('POST',
fm_cfg.api+'?action=delete', this.cb, build_querystring(params));
Expand Down Expand Up @@ -559,7 +559,7 @@ function fm_create_menu(ev, menuid, menuitems, file, options) {
}
params['newfilename'] = newfilename;

params['sesskey'] = moodle_cfg.sesskey;
params['sesskey'] = M.cfg.sesskey;
rename_cb.newfilename = newfilename;
var trans = YAHOO.util.Connect.asyncRequest('POST',
fm_cfg.api+'?action='+action, rename_cb, build_querystring(params));
Expand Down Expand Up @@ -624,7 +624,7 @@ function fm_create_menu(ev, menuid, menuitems, file, options) {
params['filepath'] = file.filepath;
params['filename'] = file.fullname;
params['itemid'] = obj.itemid;
params['sesskey'] = moodle_cfg.sesskey;
params['sesskey'] = M.cfg.sesskey;
params['newfilepath'] = tree.targetpath;
fm_loading('filemanager-'+obj.client_id, 'fm-prgressbar');
var trans = YAHOO.util.Connect.asyncRequest('POST',
Expand Down Expand Up @@ -664,7 +664,7 @@ function fm_create_menu(ev, menuid, menuitems, file, options) {
var params = {};
params['itemid'] = node.data.itemid;
params['filepath'] = node.data.path;
params['sesskey'] = moodle_cfg.sesskey;
params['sesskey'] = M.cfg.sesskey;
var trans = YAHOO.util.Connect.asyncRequest('POST',
fm_cfg.api+'?action=dir', this.cb, build_querystring(params));
this.cb.complete = onCompleteCallback;
Expand Down Expand Up @@ -800,7 +800,7 @@ function fm_setup_buttons(client_id, options) {
downloaddir_callback.client_id = this.options.client_id;
var params = [];
params['itemid'] = this.options.itemid;
params['sesskey'] = moodle_cfg.sesskey;
params['sesskey'] = M.cfg.sesskey;
params['filepath'] = this.options.currentpath;
// perform downloaddir ajax request
var trans = YAHOO.util.Connect.asyncRequest('POST',
Expand All @@ -824,7 +824,7 @@ function fm_loading(container, id) {
}

var loading = new YAHOO.widget.Module(id, {visible:false});
loading.setBody('<div style="text-align:center"><img alt="'+mstr.repository.loading+'" src="'+moodle_cfg.wwwroot+'/pix/i/progressbar.gif" /></div>');
loading.setBody('<div style="text-align:center"><img alt="'+mstr.repository.loading+'" src="'+M.cfg.wwwroot+'/pix/i/progressbar.gif" /></div>');
loading.render();
loading.show();

Expand Down
25 changes: 13 additions & 12 deletions lib/javascript-static.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Miscellaneous core Javascript functions for Moodle
// Global M object is initilised in inline javascript

// Global Y instance, inilialised much later in page footer
// Global Y instance, inilialised much later in page footer,
// it is usually better to initialise own Y by: "YUI(M.yui.loader).use('......', function(Y) { .... });
var Y = null;

/**
Expand Down Expand Up @@ -853,7 +854,7 @@ function openpopup(event, args) {

var fullurl = args.url;
if (!args.url.match(/https?:\/\//)) {
fullurl = moodle_cfg.wwwroot + args.url;
fullurl = M.cfg.wwwroot + args.url;
}
var windowobj = window.open(fullurl,args.name,args.options);
if (!windowobj) {
Expand Down Expand Up @@ -912,13 +913,13 @@ emoticons_help = {
function set_user_preference(name, value) {
// Don't generate a script error if the library has not been loaded,
// unless we are a Developer, in which case we want the error.
if (YAHOO && YAHOO.util && YAHOO.util.Connect || moodle_cfg.developerdebug) {
var url = moodle_cfg.wwwroot + '/lib/ajax/setuserpref.php?sesskey=' +
moodle_cfg.sesskey + '&pref=' + encodeURI(name) + '&value=' + encodeURI(value);
if (YAHOO && YAHOO.util && YAHOO.util.Connect || M.cfg.developerdebug) {
var url = M.cfg.wwwroot + '/lib/ajax/setuserpref.php?sesskey=' +
M.cfg.sesskey + '&pref=' + encodeURI(name) + '&value=' + encodeURI(value);

// If we are a developer, ensure that failures are reported.
var callback = {};
if (moodle_cfg.developerdebug) {
if (M.cfg.developerdebug) {
callback.failure = function() {
var a = document.createElement('a');
a.href = url;
Expand Down Expand Up @@ -1261,7 +1262,7 @@ function init_help_icons() {
// Fetch help page contents asynchronously
// Load spinner icon while content is loading
var spinner = document.createElement('img');
spinner.src = moodle_cfg.loadingicon;
spinner.src = M.cfg.loadingicon;

this.cfg.setProperty('text', spinner);

Expand All @@ -1279,7 +1280,7 @@ function init_help_icons() {
},
failure: function(o) {
var debuginfo = o.statusText;
if (moodle_cfg.developerdebug) {
if (M.cfg.developerdebug) {
o.statusText += ' (' + ajaxurl + ')';
}
thistooltip.cfg.setProperty('text', debuginfo);
Expand Down Expand Up @@ -1349,7 +1350,7 @@ function confirm_dialog(event, args) {
if (parentelement.tagName.toLowerCase() == 'form') {
parentelement.submit();
}
} else if(moodle_cfg.developerdebug) {
} else if(M.cfg.developerdebug) {
alert("Element of type " + target.tagName + " is not supported by the confirm_dialog function. Use A or INPUT");
}
};
Expand Down Expand Up @@ -1402,10 +1403,10 @@ function frame_breakout(e, properties) {
}

function get_image_url(imagename, component) {
var url = moodle_cfg.wwwroot + '/theme/image.php?theme=' + moodle_cfg.theme + '&image=' + imagename;
var url = M.cfg.wwwroot + '/theme/image.php?theme=' + M.cfg.theme + '&image=' + imagename;

if (moodle_cfg.themerev > 0) {
url = url + '&rev=' + moodle_cfg.themerev;
if (M.cfg.themerev > 0) {
url = url + '&rev=' + M.cfg.themerev;
}

if (component != '' && component != 'moodle' && component != 'core') {
Expand Down
2 changes: 1 addition & 1 deletion mod/chat/gui_ajax/script.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
YAHOO.namespace('moodle.chat');
YAHOO.moodle.chat.api = moodle_cfg.wwwroot+'/mod/chat/chat_ajax.php';
YAHOO.moodle.chat.api = M.cfg.wwwroot+'/mod/chat/chat_ajax.php';
YAHOO.moodle.chat.interval = null;
YAHOO.moodle.chat.chat_input_element = null;
YAHOO.moodle.chat.msgs = [];
Expand Down
2 changes: 1 addition & 1 deletion mod/feedback/feedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function set_item_focus(itemid) {
}

function feedbackGo2delete(form) {
form.action = moodle_cfg.wwwroot+'/mod/feedback/delete_completed.php';
form.action = M.cfg.wwwroot+'/mod/feedback/delete_completed.php';
form.submit();
}

Expand Down
Loading

0 comments on commit 9598d57

Please sign in to comment.