1 // ==========================================================================
  2 // Project:   The M-Project - Mobile HTML5 Application Framework
  3 // Copyright: (c) 2010 M-Way Solutions GmbH. All rights reserved.
  4 //            (c) 2011 panacoda GmbH. All rights reserved.
  5 // Creator:   Dominik
  6 // Date:      23.11.2010
  7 // License:   Dual licensed under the MIT or GPL Version 2 licenses.
  8 //            http://github.com/mwaylabs/The-M-Project/blob/master/MIT-LICENSE
  9 //            http://github.com/mwaylabs/The-M-Project/blob/master/GPL-LICENSE
 10 // ==========================================================================
 11 
 12 /**
 13  * @class
 14  *
 15  * This is the prototype of any dialog view. It is responsible for showing and later
 16  * hiding a dialog.
 17  *
 18  * @extends M.View
 19  */
 20 M.DialogView = M.View.extend(
 21 /** @scope M.DialogView.prototype */ {
 22 
 23     /**
 24      * The type of this object.
 25      *
 26      * @type String
 27      */
 28     type: 'M.DialogView',
 29 
 30     /**
 31      * Determines whether there currently is an active alert dialog, confirm
 32      * dialog or action sheet.
 33      *
 34      * @private
 35      * @type Boolean
 36      */
 37     isActive: NO,
 38 
 39     /**
 40      * This property is used to store a queue of coming up dialogs. Whenever a dialog
 41      * is called out of an application and there already is one present, it will be
 42      * added to the queue and called afterwards.
 43      *
 44      * @private
 45      * @type Array
 46      */
 47     queue: [],
 48 
 49     /**
 50      * This property is used to specify whether to store the dialog in the queue if it
 51      * can't be shown right away. So if set to YES, this property will prevent a dialog
 52      * from being added to the queue. If the dialog can not be displayed right away, it
 53      * will not be displayed at all.
 54      *
 55      * @private
 56      * @type Boolean
 57      */
 58     showNowOrNever: NO,
 59 
 60     /**
 61      * This method creates an alert dialog based on the given customizing parameters and
 62      * initiates its displaying on the screen.
 63      *
 64      * @param {Object} obj The customizing parameters of the alert dialog view.
 65      */
 66     alert: function(obj) {
 67         if(this.isActive) {
 68             this.enqueue('alert', obj);
 69         } else {
 70             this.isActive = YES;
 71             M.AlertDialogView.design(obj).show();
 72         }
 73     },
 74 
 75     /**
 76      * This method creates an confirm dialog based on the given customizing parameters and
 77      * initiates its displaying on the screen.
 78      *
 79      * @param {Object} obj The customizing parameters of the confirm dialog view.
 80      */
 81     confirm: function(obj) {
 82         if(this.isActive) {
 83             this.enqueue('confirm', obj);
 84         } else {
 85             this.isActive = YES;
 86             M.ConfirmDialogView.design(obj).show();
 87         }
 88     },
 89 
 90     /**
 91      * This method creates an actionSheet dialog based on the given customizing parameters and
 92      * initiates its displaying on the screen.
 93      *
 94      * @param {Object} obj The customizing parameters of the actionSheet dialog view.
 95      */
 96     actionSheet: function(obj) {
 97         if(this.isActive) {
 98             this.enqueue('actionSheet', obj);
 99         } else {
100             this.isActive = YES;
101             M.ActionSheetDialogView.design(obj).show();
102         }
103     },
104 
105     enqueue: function(action, obj) {
106         if(!obj.showNowOrNever) {
107             this.queue.unshift({
108                 action: action,
109                 obj: obj
110             });
111         }
112     },
113 
114     dequeue: function() {
115         if(!this.isActive && this.queue.length > 0) {
116             var obj = this.queue.pop();
117             this[obj.action](obj.obj);
118         }
119     }
120 
121 });