Commit | Line | Data |
---|---|---|
ddab904b DM |
1 | /** |
2 | * Check for write permission for the selected plugin type | |
3 | * | |
4 | * @module moodle-tool_installaddon-permcheck | |
5 | * @author David Mudrak <david@moodle.com> | |
6 | */ | |
7 | YUI.add('moodle-tool_installaddon-permcheck', function(Y) { | |
8 | ||
9 | M.tool_installaddon = M.tool_installaddon || {}; | |
10 | ||
11 | /** | |
12 | * @class permcheck | |
13 | * @static | |
14 | */ | |
15 | M.tool_installaddon.permcheck = { | |
16 | ||
17 | /** | |
18 | * @method init | |
19 | * @param {Object} config Configuration passed from the PHP | |
20 | */ | |
21 | init : function(config) { | |
22 | this.config = config; | |
23 | var plugintypesel = Y.one('#tool_installaddon_installfromzip_plugintype'); | |
24 | if (plugintypesel) { | |
25 | plugintypesel.on('change', this.check_for_permission, this); | |
26 | } | |
27 | }, | |
28 | ||
29 | /** | |
30 | * @method check_for_permission | |
31 | * @param {Event} e | |
32 | */ | |
33 | check_for_permission : function(e) { | |
34 | var plugintype = e.currentTarget.get('value'); | |
35 | if (plugintype == '') { | |
36 | return; | |
37 | } | |
38 | Y.log('Selected plugin type: ' + plugintype, 'debug', 'moodle-tool_installaddon-permcheck'); | |
39 | Y.io(this.config.permcheckurl, { | |
40 | 'method' : 'GET', | |
41 | 'data' : { | |
42 | 'sesskey' : M.cfg.sesskey, | |
43 | 'plugintype' : plugintype | |
44 | }, | |
45 | 'arguments' : { | |
46 | 'plugintypeselector' : e.currentTarget, | |
47 | 'showresult' : function(msg, status) { | |
48 | var resultline = Y.one('#tool_installaddon_installfromzip_permcheck'); | |
49 | if (resultline) { | |
50 | if (status === 'success') { | |
a8dd22a7 | 51 | resultline.setContent('<span class="success"><img src="' + M.util.image_url('i/valid') + '" /> ' + |
ddab904b DM |
52 | msg + '</span>'); |
53 | } else if (status === 'progress') { | |
54 | resultline.setContent('<span class="progress"><img src="' + M.cfg.loadingicon + '" /> ' + | |
55 | msg + '</span>'); | |
56 | } else { | |
a8dd22a7 | 57 | resultline.setContent('<span class="error"><img src="' + M.util.image_url('i/invalid') + '" /> ' + |
ddab904b DM |
58 | msg + '</span>'); |
59 | } | |
60 | } | |
61 | } | |
62 | }, | |
63 | 'on' : { | |
64 | 'start' : function(transid, args) { | |
65 | args.showresult(M.util.get_string('permcheckprogress', 'tool_installaddon'), 'progress'); | |
66 | }, | |
67 | 'success': function(transid, outcome, args) { | |
68 | var response; | |
69 | try { | |
70 | response = Y.JSON.parse(outcome.responseText); | |
71 | if (response.error) { | |
72 | Y.log(response.error, 'error', 'moodle-tool_installaddon-permcheck'); | |
73 | args.showresult(M.util.get_string('permcheckerror', 'tool_installaddon', response), 'error'); | |
74 | } else if (response.path && response.writable == 1) { | |
75 | args.showresult(M.util.get_string('permcheckresultyes', 'tool_installaddon', response), 'success'); | |
76 | } else if (response.path && response.writable == 0) { | |
77 | args.showresult(M.util.get_string('permcheckresultno', 'tool_installaddon', response), 'error'); | |
78 | } else { | |
79 | Y.log(response, 'debug', 'moodle-tool_installaddon-permcheck'); | |
80 | args.showresult(M.util.get_string('permcheckerror', 'tool_installaddon', response), 'error'); | |
81 | } | |
82 | ||
83 | } catch (e) { | |
84 | Y.log(e, 'error', 'moodle-tool_installaddon-permcheck'); | |
85 | args.showresult(M.util.get_string('permcheckerror', 'tool_installaddon'), 'error'); | |
86 | } | |
87 | }, | |
88 | 'failure': function(transid, outcome, args) { | |
89 | Y.log(outcome.statusText, 'error', 'moodle-tool_installaddon-permcheck'); | |
90 | args.showresult(M.util.get_string('permcheckerror', 'tool_installaddon')); | |
91 | } | |
92 | } | |
93 | }); | |
94 | }, | |
95 | ||
96 | /** | |
97 | * @property | |
98 | * @type {Object} | |
99 | */ | |
100 | config : null | |
101 | }; | |
102 | ||
103 | }, '@VERSION@', { | |
104 | requires:['node', 'event', 'io-base'] | |
105 | }); |