Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 11
Línea 14... Línea 14...
14
        _locks: null,
14
        _locks: null,
15
        _hides: null,
15
        _hides: null,
16
        _dirty: null,
16
        _dirty: null,
17
        _nameCollections: null,
17
        _nameCollections: null,
18
        _fileinputs: null,
18
        _fileinputs: null,
-
 
19
        _staticElements: null,
-
 
20
        _editors: null,
-
 
21
        _editorNameSuffix: '[text]',
Línea 19... Línea 22...
19
 
22
 
20
        initializer: function() {
23
        initializer: function() {
21
            // Setup initial values for complex properties.
24
            // Setup initial values for complex properties.
22
            this._locks = {};
25
            this._locks = {};
Línea 85... Línea 88...
85
            this.get('form').get('elements').each(function(node) {
88
            this.get('form').get('elements').each(function(node) {
86
                var name = node.getAttribute('name');
89
                var name = node.getAttribute('name');
87
                if (({}).hasOwnProperty.call(names, name)) {
90
                if (({}).hasOwnProperty.call(names, name)) {
88
                    names[name].push(node);
91
                    names[name].push(node);
89
                    allnames[name].push(node);
92
                    allnames[name].push(node);
-
 
93
                } else if (this.isEditor(name)) {
-
 
94
                    // If this is an editor, we need to remove the suffix.
-
 
95
                    name = name.replace(this._editorNameSuffix, '');
-
 
96
                    if (({}).hasOwnProperty.call(names, name)) {
-
 
97
                        names[name].push(node);
-
 
98
                        allnames[name].push(node);
-
 
99
                    }
90
                }
100
                }
91
            });
101
            }, this);
92
            // Locate any groups with the given name.
102
            // Locate any groups with the given name.
93
            this.get('form').all('.fitem').each(function(node) {
103
            this.get('form').all('.fitem').each(function(node) {
94
                var name = node.getData('groupname');
104
                var name = node.getData('groupname');
95
                if (name && ({}).hasOwnProperty.call(allnames, name)) {
105
                if (name && ({}).hasOwnProperty.call(allnames, name)) {
96
                    allnames[name].push(node);
106
                    allnames[name].push(node);
97
                }
107
                }
98
            });
108
            });
-
 
109
            // Locate any static elements for each name.
-
 
110
            this.get('form').all('.form-control-static').each(function(node) {
-
 
111
                var name = node.getData('name');
-
 
112
                if (({}).hasOwnProperty.call(allnames, name)) {
-
 
113
                    names[name].push(node);
-
 
114
                    allnames[name].push(node);
-
 
115
                }
-
 
116
            });
99
            this._nameCollections = {names: names, allnames: allnames};
117
            this._nameCollections = {names: names, allnames: allnames};
100
        },
118
        },
Línea 101... Línea 119...
101
 
119
 
102
        /**
120
        /**
Línea 248... Línea 266...
248
         *
266
         *
249
         * @param {String} name The form element name.
267
         * @param {String} name The form element name.
250
         * @param {Boolean} disabled True to disable, false to enable.
268
         * @param {Boolean} disabled True to disable, false to enable.
251
         */
269
         */
252
        _disableElement: function(name, disabled) {
270
        _disableElement: function(name, disabled) {
253
            var els = this.elementsByName(name),
271
            const els = this.elementsByName(name),
254
                filepicker = this.isFilePicker(name),
272
                filepicker = this.isFilePicker(name),
255
                editors = this.get('form').all('.fitem [data-fieldtype="editor"] textarea[name="' + name + '[text]"]');
273
                editors = this.get('form').all('.fitem [data-fieldtype="editor"] textarea[name="' + name + '[text]"]'),
-
 
274
                staticElement = this.isStaticElement(name);
Línea 256... Línea 275...
256
 
275
 
-
 
276
            els.each(function(node) {
257
            els.each(function(node) {
277
                const fitem = node.ancestor('.fitem');
258
                if (disabled) {
278
                if (disabled) {
259
                    node.setAttribute('disabled', 'disabled');
279
                    node.setAttribute('disabled', 'disabled');
260
                } else {
280
                } else {
261
                    node.removeAttribute('disabled');
281
                    node.removeAttribute('disabled');
-
 
282
                }
-
 
283
                // Enable/Disable static elements if exist.
-
 
284
                if (staticElement) {
-
 
285
                    const disabledNonTextElements = 'INPUT,SELECT,TEXTAREA,BUTTON,A';
-
 
286
                    if (disabled) {
-
 
287
                        // Mute the text inside the current static element.
262
                }
-
 
-
 
288
                        fitem.addClass('text-muted');
-
 
289
                        // Disabled non-text elements in the static if exist.
-
 
290
                        fitem.all(disabledNonTextElements).each(function(disabledElement) {
-
 
291
                            if (disabledElement.get('tagName').toUpperCase() === "A") {
-
 
292
                                disabledElement.addClass('disabled');
-
 
293
                            } else {
-
 
294
                                disabledElement.setAttribute('disabled', 'disabled');
-
 
295
                            }
-
 
296
                        });
-
 
297
                    } else {
-
 
298
                        // Unmute the text inside the current static element.
-
 
299
                        fitem.removeClass('text-muted');
-
 
300
                        // Enabled non-text elements in the static if exist.
-
 
301
                        fitem.all(disabledNonTextElements).each(function(disabledElement) {
-
 
302
                            if (disabledElement.get('tagName').toUpperCase() === "A") {
-
 
303
                                disabledElement.removeClass('disabled');
-
 
304
                            } else {
-
 
305
                                disabledElement.removeAttribute('disabled', 'disabled');
-
 
306
                            }
-
 
307
                        });
-
 
308
                    }
263
 
309
                }
264
                // Extra code to disable filepicker or filemanager form elements
310
                // Extra code to disable filepicker or filemanager form elements
265
                if (filepicker) {
-
 
266
                    var fitem = node.ancestor('.fitem');
311
                if (filepicker) {
267
                    if (fitem) {
312
                    if (fitem) {
268
                        if (disabled) {
313
                        if (disabled) {
269
                            fitem.addClass('disabled');
314
                            fitem.addClass('disabled');
270
                        } else {
315
                        } else {
Línea 352... Línea 397...
352
                return this._fileinputs[el] || false;
397
                return this._fileinputs[el] || false;
353
            }
398
            }
Línea 354... Línea 399...
354
 
399
 
355
            return false;
400
            return false;
-
 
401
        },
-
 
402
        /**
-
 
403
         * Checks if a form element with the given name is static.
-
 
404
         *
-
 
405
         * @param {string} el - The name of the form element to check.
-
 
406
         * @returns {boolean} - Returns true if the form element is static, otherwise false.
-
 
407
         */
-
 
408
        isStaticElement: function(el) {
-
 
409
            if (!this._staticElements) {
-
 
410
                const staticElements = {};
-
 
411
                const els = this.get('form').all('.fitem [data-fieldtype="static"] .form-control-static');
-
 
412
                els.each(function(node) {
-
 
413
                    if (node.getData('name') === el) {
-
 
414
                        staticElements[node.getData('name')] = true;
-
 
415
                    }
-
 
416
                });
-
 
417
                this._staticElements = staticElements;
-
 
418
            }
-
 
419
            if (({}).hasOwnProperty.call(this._staticElements, el)) {
-
 
420
                return this._staticElements[el] || false;
-
 
421
            }
-
 
422
            return false;
356
        },
423
        },
357
        _dependencyNotchecked: function(elements, value, isHide) {
424
        _dependencyNotchecked: function(elements, value, isHide) {
358
            var lock = false;
425
            var lock = false;
359
            elements.each(function() {
426
            elements.each(function() {
360
                if (this.getAttribute('type').toLowerCase() == 'hidden' &&
427
                if (this.getAttribute('type').toLowerCase() == 'hidden' &&
Línea 584... Línea 651...
584
            });
651
            });
585
            return {
652
            return {
586
                lock: lock,
653
                lock: lock,
587
                hide: isHide ? lock : false
654
                hide: isHide ? lock : false
588
            };
655
            };
589
        }
656
        },
-
 
657
        /**
-
 
658
         * Is the form element an editor?
-
 
659
         *
-
 
660
         * @param {String} el The form element name.
-
 
661
         * @return {Boolean}
-
 
662
         */
-
 
663
        isEditor: function(el) {
-
 
664
            if (!this._editors) {
-
 
665
                let editors = {};
-
 
666
                const selector = '.fitem [data-fieldtype="editor"] textarea';
-
 
667
                const els = this.get('form').all(selector);
-
 
668
                els.each(function(node) {
-
 
669
                    editors[node.getAttribute('name')] = true;
-
 
670
                });
-
 
671
                this._editors = editors;
-
 
672
            }
-
 
673
 
-
 
674
            return this._editors[el] || false;
-
 
675
        },
590
    }, {
676
    }, {
591
        NAME: 'mform-dependency-manager',
677
        NAME: 'mform-dependency-manager',
592
        ATTRS: {
678
        ATTRS: {
593
            form: {
679
            form: {
594
                setter: function(value) {
680
                setter: function(value) {