aboutsummaryrefslogtreecommitdiff
path: root/node_modules/montage/ui/popup/alert.reel/alert.js
blob: 54b854a4d437b3c911e3a76c03b2ec6ec190a843 (plain)
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/* <copyright>
 This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
 No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
 (c) Copyright 2011 Motorola Mobility, Inc.  All Rights Reserved.
 </copyright> */

/**
    @module "montage/ui/popup/alert.reel"
    @requires montage/core/core
    @requires montage/ui/component
    @requires "montage/ui/popup/popup.reel"
*/

var Montage = require("montage").Montage;
var Component = require("ui/component").Component;
var Popup = require("ui/popup/popup.reel").Popup;

/**
 @class module:"montage/ui/popup/alert.reel".Alert
 @extends module:montage/ui/component.Component
 */

var Alert = exports.Alert = Montage.create(Component, {
    title: {
        value: 'Alert'
    },
/**
        Description TODO
        @type {Property}
        @default {String} ''
    */
    msg: {
        value: ''
    },
/**
        Description TODO
        @type {Property}
        @default {String} ''
    */
    details: {
        value: ''
    },
/**
  Description TODO
  @private
*/
    _popup: {
        value: null
    },
/**
        Description TODO
        @type {Function}
        @default null
    */
    popup: {
        set: function(value) {
            this._popup = value;
        },
        get: function() {
            return this._popup;
        }
    },

    okCallback: {value: null},

    prepareForDraw: {
        value: function() {
            this.element.addEventListener("keyup", this, false);
        }
    },
/**
    Description TODO
    @function
    @param {Event} evt The event keyCode.
    */
    handleKeyup: {
        value: function(evt) {
            if (evt.keyCode == 13 /*Enter*/ ||
                    evt.keyCode == 27 /*Escape*/) {

                this.handleOkAction(evt);
            }
        }
    },
/**
    Description TODO
    @function
    @param {Event} evt The event keyCode.
    */
    handleOkAction: {
        value: function(evt) {
            if(this.okCallback) {
                this.okCallback.call(this, evt);
            }
            var anEvent = document.createEvent("CustomEvent");
            anEvent.initCustomEvent("montage_alert_ok", true, true, null);

            this.dispatchEvent(anEvent);
            this.popup.hide();
        }
    },

    // Static method to show an Alert dialog
    /**
     Displays an Alert dialog with a OK button.
     @function
     @param {String} msg A message to display in the dialog.
     @param {Function} okCallback Function that's invoked when the user clicks OK
     @example
     ...
     */
    show: {
        value: function(msg, okCallback) {
            var popup = this.application._alertPopup, alert;
            if(!popup) {
                popup = Popup.create();
                this.popup = popup;

                popup.type = 'alert';
                popup.title = 'Message';
                popup.modal = true;
                this.application._alertPopup = popup;

                alert = Alert.create();
                popup.content = alert;
            }
            alert = popup.content;
            alert.msg = msg;
            alert.okCallback = okCallback || null;
            popup.show();
        }
    }
});