Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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', function() {
26
                    this.check_for_permission(plugintypesel);
27
                }, this);
28
                this.repeat_permcheck_icon = Y.Node.create('<div><a href="#repeat-permcheck"><img src="' + M.util.image_url('i/reload') + '" /> ' +
29
                    M.util.get_string('permcheckrepeat', 'tool_installaddon') + '</a></div>');
30
                this.repeat_permcheck_icon.one('a').on('click', function(e) {
31
                    e.preventDefault();
32
                    this.check_for_permission(plugintypesel);
33
                }, this);
34
            }
35
        },
36
 
37
        /**
38
         * @method check_for_permission
39
         * @param {Node} plugintypesel Plugin type selector node
40
         */
41
        check_for_permission : function(plugintypesel) {
42
            var plugintype = plugintypesel.get('value');
43
 
44
            if (plugintype == '') {
45
                return;
46
            }
47
            Y.log('Selected plugin type: ' + plugintype, 'debug', 'moodle-tool_installaddon-permcheck');
48
            Y.io(this.config.permcheckurl, {
49
                'method' : 'GET',
50
                'data' : {
51
                    'sesskey' : M.cfg.sesskey,
52
                    'plugintype' : plugintype
53
                },
54
                'context' : this,
55
                'on' : {
56
                    'start' : function(transid, args) {
57
                        this.showresult(M.util.get_string('permcheckprogress', 'tool_installaddon'), 'progress');
58
                    },
59
                    'success': function(transid, outcome, args) {
60
                        var response;
61
                        try {
62
                            response = Y.JSON.parse(outcome.responseText);
63
                            if (response.error) {
64
                                Y.log(response.error, 'error', 'moodle-tool_installaddon-permcheck');
65
                                this.showresult(M.util.get_string('permcheckerror', 'tool_installaddon', response), 'error');
66
                            } else if (response.path && response.writable == 1) {
67
                                this.showresult(M.util.get_string('permcheckresultyes', 'tool_installaddon', response), 'success');
68
                            } else if (response.path && response.writable == 0) {
69
                                this.showresult(M.util.get_string('permcheckresultno', 'tool_installaddon', response), 'error');
70
                            } else {
71
                                Y.log(response, 'debug', 'moodle-tool_installaddon-permcheck');
72
                                this.showresult(M.util.get_string('permcheckerror', 'tool_installaddon', response), 'error');
73
                            }
74
 
75
                        } catch (e) {
76
                            Y.log(e, 'error', 'moodle-tool_installaddon-permcheck');
77
                            this.showresult(M.util.get_string('permcheckerror', 'tool_installaddon'), 'error');
78
                        }
79
                    },
80
                    'failure': function(transid, outcome, args) {
81
                        Y.log(outcome.statusText, 'error', 'moodle-tool_installaddon-permcheck');
82
                        this.showresult(M.util.get_string('permcheckerror', 'tool_installaddon'));
83
                    }
84
                }
85
            });
86
        },
87
 
88
        /**
89
         * @method showresult
90
         * @param {String} msg Message to display
91
         * @param {String} status Message status
92
         */
93
        showresult : function(msg, status) {
94
            var resultline = Y.one('#tool_installaddon_installfromzip_permcheck');
95
            if (resultline) {
96
                if (status === 'success') {
97
                    resultline.setHTML('<span class="success"><img src="' + M.util.image_url('i/valid') + '" /> ' +
98
                        msg + '</span>');
99
                } else if (status === 'progress') {
100
                    resultline.setHTML('<span class="progress"><img src="' + M.cfg.loadingicon + '" /> ' +
101
                        msg + '</span>');
102
                } else {
103
                    resultline.setHTML('<span class="error"><img src="' + M.util.image_url('i/invalid') + '" /> ' +
104
                        msg + '</span>').append(this.repeat_permcheck_icon);
105
                }
106
            }
107
        },
108
 
109
        /**
110
         * @property
111
         * @type {Y.Node}
112
         */
113
        repeat_permcheck_icon : null,
114
 
115
        /**
116
         * @property
117
         * @type {Object}
118
         */
119
        config : null
120
    };
121
 
122
}, '@VERSION@', {
123
    requires:['node', 'event', 'io-base']
124
});