[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/lib/yui/build/moodle-core-notification-confirm/ -> moodle-core-notification-confirm.js (source)

   1  YUI.add('moodle-core-notification-confirm', function (Y, NAME) {
   2  
   3  var DIALOGUE_PREFIX,
   4      BASE,
   5      CONFIRMYES,
   6      CONFIRMNO,
   7      TITLE,
   8      QUESTION,
   9      CSS;
  10  
  11  DIALOGUE_PREFIX = 'moodle-dialogue',
  12  BASE = 'notificationBase',
  13  CONFIRMYES = 'yesLabel',
  14  CONFIRMNO = 'noLabel',
  15  TITLE = 'title',
  16  QUESTION = 'question',
  17  CSS = {
  18      BASE : 'moodle-dialogue-base',
  19      WRAP : 'moodle-dialogue-wrap',
  20      HEADER : 'moodle-dialogue-hd',
  21      BODY : 'moodle-dialogue-bd',
  22      CONTENT : 'moodle-dialogue-content',
  23      FOOTER : 'moodle-dialogue-ft',
  24      HIDDEN : 'hidden',
  25      LIGHTBOX : 'moodle-dialogue-lightbox'
  26  };
  27  
  28  // Set up the namespace once.
  29  M.core = M.core || {};
  30  /**
  31   * A dialogue type designed to display a confirmation to the user.
  32   *
  33   * @module moodle-core-notification
  34   * @submodule moodle-core-notification-confirm
  35   */
  36  
  37  var CONFIRM_NAME = 'Moodle confirmation dialogue',
  38      CONFIRM;
  39  
  40  /**
  41   * Extends core Dialogue to show the confirmation dialogue.
  42   *
  43   * @param {Object} config Object literal specifying the dialogue configuration properties.
  44   * @constructor
  45   * @class M.core.confirm
  46   * @extends M.core.dialogue
  47   */
  48  CONFIRM = function(config) {
  49      CONFIRM.superclass.constructor.apply(this, [config]);
  50  };
  51  Y.extend(CONFIRM, M.core.notification.info, {
  52      /**
  53       * The list of events to detach when destroying this dialogue.
  54       *
  55       * @property _closeEvents
  56       * @type EventHandle[]
  57       * @private
  58       */
  59      _closeEvents: null,
  60  
  61      /**
  62       * A reference to the yes button.
  63       *
  64       * @property _yesButton
  65       * @type Node
  66       * @private
  67       */
  68      _yesButton: null,
  69  
  70      /**
  71       * A reference to the No button.
  72       *
  73       * @property _noButton
  74       * @type Node
  75       * @private
  76       */
  77      _noButton: null,
  78  
  79      /**
  80       * A reference to the Question.
  81       *
  82       * @property _question
  83       * @type Node
  84       * @private
  85       */
  86      _question: null,
  87  
  88      initializer: function() {
  89          this._closeEvents = [];
  90          this.publish('complete');
  91          this.publish('complete-yes');
  92          this.publish('complete-no');
  93          this._yesButton = Y.Node.create('<input type="button" id="id_yuiconfirmyes-' + this.get('COUNT') + '" value="'+this.get(CONFIRMYES)+'" />');
  94          this._noButton = Y.Node.create('<input type="button" id="id_yuiconfirmno-' + this.get('COUNT') + '" value="'+this.get(CONFIRMNO)+'" />');
  95          this._question = Y.Node.create('<div class="confirmation-message">' + this.get(QUESTION) + '</div>');
  96          var content = Y.Node.create('<div class="confirmation-dialogue"></div>')
  97                          .append(this._question)
  98                          .append(Y.Node.create('<div class="confirmation-buttons"></div>')
  99                              .append(this._yesButton)
 100                              .append(this._noButton));
 101          this.get(BASE).addClass('moodle-dialogue-confirm');
 102          this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE);
 103          this.setStdModContent(Y.WidgetStdMod.HEADER,
 104                  '<h1 id="moodle-dialogue-'+this.get('COUNT')+'-header-text">' + this.get(TITLE) + '</h1>', Y.WidgetStdMod.REPLACE);
 105  
 106          this._closeEvents.push(
 107              Y.on('key', this.submit, window, 'down:27', this, false),
 108              this._yesButton.on('click', this.submit, this, true),
 109              this._noButton.on('click', this.submit, this, false)
 110          );
 111  
 112          var closeButton = this.get('boundingBox').one('.closebutton');
 113          if (closeButton) {
 114              // The close button should act exactly like the 'No' button.
 115              this._closeEvents.push(
 116                  closeButton.on('click', this.submit, this)
 117              );
 118          }
 119      },
 120      submit: function(e, outcome) {
 121          new Y.EventHandle(this._closeEvents).detach();
 122          this.fire('complete', outcome);
 123          if (outcome) {
 124              this.fire('complete-yes');
 125          } else {
 126              this.fire('complete-no');
 127          }
 128          this.hide();
 129          this.destroy();
 130      }
 131  }, {
 132      NAME: CONFIRM_NAME,
 133      CSS_PREFIX: DIALOGUE_PREFIX,
 134      ATTRS: {
 135  
 136          /**
 137           * The button text to use to accept the confirmation.
 138           *
 139           * @attribute yesLabel
 140           * @type String
 141           * @default 'Yes'
 142           */
 143          yesLabel: {
 144              validator: Y.Lang.isString,
 145              valueFn: function() {
 146                  return M.util.get_string('yes', 'moodle');
 147              },
 148              setter: function(value) {
 149                  if (this._yesButton) {
 150                      this._yesButton.set('value', value);
 151                  }
 152                  return value;
 153              }
 154          },
 155  
 156          /**
 157           * The button text to use to reject the confirmation.
 158           *
 159           * @attribute noLabel
 160           * @type String
 161           * @default 'No'
 162           */
 163          noLabel: {
 164              validator: Y.Lang.isString,
 165              valueFn: function() {
 166                  return M.util.get_string('no', 'moodle');
 167              },
 168              setter: function(value) {
 169                  if (this._noButton) {
 170                      this._noButton.set('value', value);
 171                  }
 172                  return value;
 173              }
 174          },
 175  
 176          /**
 177           * The title of the dialogue.
 178           *
 179           * @attribute title
 180           * @type String
 181           * @default 'Confirm'
 182           */
 183          title: {
 184              validator: Y.Lang.isString,
 185              value: M.util.get_string('confirm', 'moodle')
 186          },
 187  
 188          /**
 189           * The question posed by the dialogue.
 190           *
 191           * @attribute question
 192           * @type String
 193           * @default 'Are you sure?'
 194           */
 195          question: {
 196              validator: Y.Lang.isString,
 197              valueFn: function() {
 198                  return M.util.get_string('areyousure', 'moodle');
 199              },
 200              setter: function(value) {
 201                  if (this._question) {
 202                      this._question.set('value', value);
 203                  }
 204                  return value;
 205              }
 206          }
 207      }
 208  });
 209  Y.augment(CONFIRM, Y.EventTarget);
 210  
 211  M.core.confirm = CONFIRM;
 212  
 213  
 214  }, '@VERSION@', {"requires": ["moodle-core-notification-dialogue"]});


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1