      1 // ==========================================================================
      2 // Project:   The M-Project - Mobile HTML5 Application Framework
      3 // Copyright: (c) 2010 M-Way Solutions GmbH. All rights reserved.
      4 // Creator:   Dominik
      5 // Date:      23.11.2010
      6 // License:   Dual licensed under the MIT or GPL Version 2 licenses.
      7 //            http://github.com/mwaylabs/The-M-Project/blob/master/MIT-LICENSE
      8 //            http://github.com/mwaylabs/The-M-Project/blob/master/GPL-LICENSE
      9 // ==========================================================================
     10
     11 m_require('ui/dialog.js');
     12
     13 /**
     14  * @class
     15  *
     16  * This is the prototype for any alert dialog view. It is derived from M.DialogView
     17  * and mainly used for implementing a alert dialog view specific render method.
     18  *
     19  * @extends M.DialogView
     20  */
     21 M.AlertDialogView = M.DialogView.extend(
     22 /** @scope M.AlertDialogView.prototype */ {
     23
     24     /**
     25      * The type of this object.
     26      *
     27      * @type String
     28      */
     29     type: 'M.AlertDialogView',
     30
     31     /**
     32      * The default title of an alert dialog.
     33      *
     34      * @type String
     35      */
     36     title: 'Alert',
     37
     38     /**
     39      * The default message of an alert dialog.
     40      *
     41      * @type String
     42      */
     43     message: '',
     44
     45     /**
     46      * The default transition of an alert dialog.
     47      *
     48      * @type String
     49      */
     50     transition: M.TRANSITION.POP,
     51
     52     /**
     53      * Determines whether the alert dialog gets a default ok button.
     54      *
     55      * @type Boolean
     56      */
     57     hasOkButton: YES,
     58
     59     /**
     60      * Renders an alert dialog as a pop-up page.
     61      *
     62      * @private
     63      * @returns {String} The alert dialog view's html representation.
     64      */
     65     render: function() {
     66         this.html = '<div data-role="dialog" id="' + this.id + '">';
     67         this.html += '<div data-role="header" data-position="fixed"><h1>' + this.title + '</h1></div>';
     68         this.html += '<div data-role="content">' + this.message;
     69
     70         if(this.hasOkButton) {
     71             var button = M.ButtonView.design({
     72                 value: 'OK',
     73                 cssClass: 'b',
     74                 target: this,
     75                 action: 'dialogWillClose',
     76                 role: 'onOk'
     77             });
     78             this.buttonIds.push(button.id);
     79             this.html += button.render();
     80         }
     81
     82         this.html += '</div>';
     83         this.html += '</div>';
     84
     85         $('body').append(this.html);
     86     }
     87
     88 });