all files / montage/ui/base/ abstract-confirm.js

96.77% Statements 30/31
87.5% Branches 14/16
100% Functions 5/5
96.77% Lines 30/31
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109                        15×                                                                               11×     11×     11×   11× 10× 10×       10× 10×     10×       10×                              
/**
 * @module ui/alert.reel
 */
var AbstractAlert = require("./abstract-alert").AbstractAlert,
    Promise = require("../../core/promise").Promise;
 
/**
 * @class Alert
 * @extends Component
 */
var AbstractConfirm = exports.AbstractConfirm = AbstractAlert.specialize(/** @lends AbstractAlert# */ {
 
    constructor: {
        value: function AbstractConfirm() {
            if (this.constructor === AbstractConfirm) {
                throw new Error("AbstractConfirm cannot be instantiated.");
            }
        }
    },
 
    cancelButton: {
        value: null
    },
 
    title: {
        value: "Confirm"
    },
 
    okLabel: {
        value: "OK"
    },
 
    cancelLabel: {
        value: "Cancel"
    },
 
    enterDocument: {
        value: function (firstTime) {
            this.super(firstTime);
 
            Eif (firstTime) {
                this._cancelButton.addEventListener("action", this, false);
            }
        }
    },
 
    handleAction: {
        value: function (event) {
            if (event.target === this._okButton) {
                this.resolveUserAction(AbstractConfirm.OKButton);
                this._userActionPromise = null;
                this._overlay.hide();
            }
 
            if (event.target === this._cancelButton) {
                this.resolveUserAction(AbstractConfirm.CancelButton);
                this._userActionPromise = null;
                this._overlay.hide();
            }
        }
    }
 
}, {
 
    show: {
        value: function (message, title, okLabel, cancelLabel) {
            var instance,
                self = this;
 
            if (!this.hasOwnProperty("_instance")) {
                this._setupInstance();
            }
 
            instance = this._instance;
 
            return this._nextMessagePromise = this._nextMessagePromise.then(function () {
                Eif (title) {
                    instance.title = title;
                } else {
                    instance.title = self.prototype.title;
                }
                instance.message = message;
                if (okLabel) {
                    instance.okLabel = okLabel;
                } else {
                    instance.okLabel = self.prototype.okLabel;
                }
                if (cancelLabel) {
                    instance.cancelLabel = cancelLabel;
                } else {
                    instance.cancelLabel = self.prototype.cancelLabel;
                }
 
                return instance.show();
            });
        }
    },
 
    OKButton: {
        value: "ok"
    },
 
    CancelButton: {
        value: "cancel"
    }
 
});