      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 action sheet dialog view. It is derived from M.DialogView
     17  * and mainly used for implementing a action sheet dialog view specific render method.
     18  *
     19  * @extends M.DialogView
     20  */
     21 M.ActionSheetDialogView = M.DialogView.extend(
     22 /** @scope M.ActionSheetDialogView.prototype */ {
     23
     24     /**
     25      * The type of this object.
     26      *
     27      * @type String
     28      */
     29     type: 'M.ActionSheetDialogView',
     30
     31     /**
     32      * The default title of an action sheet dialog.
     33      *
     34      * @type String
     35      */
     36     title: 'ActionSheet',
     37
     38     /**
     39      * The default transition of an action sheet dialog.
     40      *
     41      * @type String
     42      */
     43     transition: M.TRANSITION.SLIDEUP,
     44
     45     /**
     46      * Determines whether the action sheet dialog gets a default cancel button.
     47      *
     48      * @type Boolean
     49      */
     50     hasCancelButton: YES,
     51
     52     /**
     53      * Renders an action sheet dialog as a slide-up page.
     54      *
     55      * @private
     56      * @returns {String} The action sheet dialog view's html representation.
     57      */
     58     render: function() {
     59         this.html = '<div data-role="dialog" id="' + this.id + '">';
     60         this.html += '<div data-role="content"><h2>' + this.title + '</h2>';
     61         this.html += this.message ? this.message : '';
     62
     63         if(this.buttons) {
     64             for(var buttonName in this.buttons) {
     65                 var button = M.ButtonView.design({
     66                     value: this.buttons[buttonName].title,
     67                     target: this,
     68                     action: 'dialogWillClose',
     69                     role: buttonName,
     70                     cssClass: this.buttons[buttonName].cssClass ? this.buttons[buttonName].cssClass : (buttonName === 'cancel' ? 'c' : 'b')
     71                 });
     72                 this.buttonIds.push(button.id);
     73                 this.html += button.render();
     74             }
     75         }
     76
     77         if(this.hasCancelButton) {
     78             var button = M.ButtonView.design({
     79                 value: 'Cancel',
     80                 cssClass: 'c',
     81                 target: this,
     82                 action: 'dialogWillClose',
     83                 role: 'onCancel'
     84             });
     85             this.buttonIds.push(button.id);
     86             this.html += button.render();
     87         }
     88
     89         this.html += '</div>';
     90
     91         $('body').append(this.html);
     92     }
     93
     94 });