Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
// This file is part of Moodle - http://moodle.org/
2
//
3
// Moodle is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, either version 3 of the License, or
6
// (at your option) any later version.
7
//
8
// Moodle is distributed in the hope that it will be useful,
9
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
// GNU General Public License for more details.
12
//
13
// You should have received a copy of the GNU General Public License
14
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
15
 
16
/**
17
 * Contain the logic for the save/cancel modal.
18
 *
19
 * @module     core/modal_save_cancel
20
 * @copyright  2016 Ryan Wyllie <ryan@moodle.com>
21
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 */
23
 
24
import Modal from 'core/modal';
25
import Notification from 'core/notification';
26
 
27
/**
28
 * The Save/Cancel Modal.
29
 *
30
 * @class
31
 * @extends module:core/modal
32
 */
33
export default class ModalSaveCancel extends Modal {
34
    static TYPE = 'SAVE_CANCEL';
35
    static TEMPLATE = 'core/modal_save_cancel';
36
 
37
    constructor(root) {
38
        super(root);
39
 
40
        if (!this.getFooter().find(this.getActionSelector('save')).length) {
41
            Notification.exception({message: 'No save button found'});
42
        }
43
 
44
        if (!this.getFooter().find(this.getActionSelector('cancel')).length) {
45
            Notification.exception({message: 'No cancel button found'});
46
        }
47
    }
48
 
49
    /**
50
     * Register all event listeners.
51
     */
52
    registerEventListeners() {
53
        // Call the parent registration.
54
        super.registerEventListeners();
55
 
56
        // Register to close on save/cancel.
57
        this.registerCloseOnSave();
58
        this.registerCloseOnCancel();
59
    }
60
 
61
    /**
62
     * Override parent implementation to prevent changing the footer content.
63
     */
64
    setFooter() {
65
        Notification.exception({message: 'Can not change the footer of a save cancel modal'});
66
        return;
67
    }
68
 
69
    /**
70
     * Set the title of the save button.
71
     *
72
     * @param {String|Promise} value The button text, or a Promise which will resolve it
73
     * @returns{Promise}
74
     */
75
    setSaveButtonText(value) {
76
        return this.setButtonText('save', value);
77
    }
78
}
79
 
80
ModalSaveCancel.registerModalType();