Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

gallery-2014.01.10-22-44 ItsAsbreuk gallery-itsamessagecontroller

  • Loading branch information...
commit 0d2f592118f0d71fcac4df303c4332391b5cf797 1 parent 9cdbbdc
@clarle clarle authored
Showing with 3,658 additions and 0 deletions.
  1. +6 −0 build/gallery-itsamessagecontroller/gallery-itsamessagecontroller-coverage.js
  2. +1,061 −0 build/gallery-itsamessagecontroller/gallery-itsamessagecontroller-debug.js
  3. +2 −0  build/gallery-itsamessagecontroller/gallery-itsamessagecontroller-min.js
  4. +1,036 −0 build/gallery-itsamessagecontroller/gallery-itsamessagecontroller.js
  5. +7 −0 src/gallery-itsamessagecontroller/HISTORY.md
  6. +18 −0 src/gallery-itsamessagecontroller/README.md
  7. +10 −0 src/gallery-itsamessagecontroller/build.json
  8. +21 −0 src/gallery-itsamessagecontroller/docs/component.json
  9. +22 −0 src/gallery-itsamessagecontroller/docs/dialog.mustache
  10. +138 −0 src/gallery-itsamessagecontroller/docs/index.mustache
  11. +49 −0 src/gallery-itsamessagecontroller/docs/partials/api-button.mustache
  12. +78 −0 src/gallery-itsamessagecontroller/docs/partials/dialog-js.mustache
  13. +7 −0 src/gallery-itsamessagecontroller/docs/partials/init-loaderconfig-js.mustache
  14. +38 −0 src/gallery-itsamessagecontroller/docs/partials/loaderconfig-js.mustache
  15. +1,045 −0 src/gallery-itsamessagecontroller/js/gallery-itsamessagecontroller.js
  16. +29 −0 src/gallery-itsamessagecontroller/logs/tests.json
  17. 0  src/gallery-itsamessagecontroller/logs/yogi.stderr.log
  18. +36 −0 src/gallery-itsamessagecontroller/logs/yogi.stdout.log
  19. +15 −0 src/gallery-itsamessagecontroller/meta/gallery-itsamessagecontroller.json
  20. +25 −0 src/gallery-itsamessagecontroller/tests/unit/index.html
  21. +15 −0 src/gallery-itsamessagecontroller/tests/unit/js/tests.js
View
6 build/gallery-itsamessagecontroller/gallery-itsamessagecontroller-coverage.js
6 additions, 0 deletions not shown
View
1,061 build/gallery-itsamessagecontroller/gallery-itsamessagecontroller-debug.js
@@ -0,0 +1,1061 @@
+YUI.add('gallery-itsamessagecontroller', function (Y, NAME) {
+
+'use strict';
+
+/*jshint maxlen:215 */
+
+/**
+ *
+ * Extends Y.Model by adding methods through which they can create editable form-elements, which represent and are bound to the propery-value.
+ * This model is for defining the UI-structure for all Model's properties and for firing model-events for
+ * Y.ITSAFormModel does not rendering to the dom itself. That needs to be done by an Y.View-instance, like Y.ITSAViewModel.
+ *
+ * @module gallery-itsamessagecontroller
+ * @extends Base
+ * @class ITSAMessageController
+ * @constructor
+ * @since 0.1
+ *
+ * <i>Copyright (c) 2013 Marco Asbreuk - http://itsasbreuk.nl</i>
+ * YUI BSD License - http://developer.yahoo.com/yui/license.html
+ *
+*/
+
+ var YArray = Y.Array,
+ APP = 'application',
+ BOOLEAN = 'boolean',
+ ERROR = 'error',
+ INFO = 'info',
+ WARN = 'warn',
+ STRING = 'string',
+ DELETE = 'delete',
+ DESTROY = 'destroy',
+ ESSAGE = 'essage',
+ MESSAGE = 'm'+ESSAGE,
+ MAIL = 'mail',
+ EMAIL = 'e'+MAIL,
+ URL = 'url',
+ LOADDELAY = 5000,
+ MODEL = 'model',
+ SYNC = 'sync',
+ LIST = 'list',
+ GALLERY_ITSA = 'gallery-itsa',
+ SYNCPROMISE = SYNC+'promise',
+ GALLERYITSAMODELSYNCPROMISE = GALLERY_ITSA+MODEL+SYNCPROMISE,
+ GALLERYITSAMODELLISTSYNCPROMISE = GALLERY_ITSA+MODEL+LIST+SYNCPROMISE,
+ MODELSYNC = MODEL+SYNC,
+ PUBLISHED = '_pub_',
+ NEWMESSAGE = 'new'+MESSAGE,
+ PUBLISHED_NEWMESSAGE = PUBLISHED+NEWMESSAGE,
+ GALLERY_ITSAMESSAGE = GALLERY_ITSA+MESSAGE,
+ GET = 'get',
+ SHOW = 'show',
+ REMOVE = 'remove',
+ STATUS = 'Status',
+ CONFIRMATION = 'Confirmation',
+ GET_RETRY_CONFIRMATION = GET+'Retry'+CONFIRMATION,
+ GET_CONFIRMATION = GET+CONFIRMATION,
+ GET_INPUT = GET+'Input',
+ GET_NUMBER = GET+'Number',
+ GET_EMAIL = GET+'E'+MAIL,
+ GET_URL = GET+'URL',
+ SHOW_MESSAGE = SHOW+'M'+ESSAGE,
+ SHOW_WARNING = SHOW+'Warning',
+ SHOW_ERROR = SHOW+'Error',
+ SHOW_STATUS = SHOW+STATUS,
+ SHOW_BUSY = SHOW+'Busy',
+ REMOVE_STATUS = REMOVE+STATUS,
+ UNDERSCORE = '_',
+ BASE_BUILD = 'base-build',
+ TEXTAREA = 'textarea',
+ QUESTION = 'question',
+ INFORM = INFO+'rm',
+ ITSAICON_DIALOG = 'itsaicon-dialog-',
+ ICON_INFORM = ITSAICON_DIALOG+INFORM,
+ ICON_ERROR = ITSAICON_DIALOG+ERROR,
+ ICON_INFO = ITSAICON_DIALOG+INFO,
+ ICON_QUESTION = ITSAICON_DIALOG+QUESTION,
+ ICON_WARN = ITSAICON_DIALOG+WARN,
+ ERROR_MSG_SIMPLE_NOTARGET = 'non-simple-message cannot be targetted to simple-messageviewer',
+ ITSADIALOG = 'itsadialog';
+
+function ITSAMessageControllerClass() {
+ ITSAMessageControllerClass.superclass.constructor.apply(this, arguments);
+}
+
+ITSAMessageControllerClass.NAME = 'itsamessagecontroller';
+
+Y.ITSAMessageControllerClass = Y.extend(ITSAMessageControllerClass, Y.Base);
+
+/**
+ * @method initializer
+ * @protected
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype.initializer = function() {
+ Y.log('initializer', 'info', 'ITSAMessageController');
+ var instance = this,
+ eventhandlers;
+
+ /**
+ * Array with all the messages that needs to be shown.
+ * @property queue
+ * @default []
+ * @type Array
+ */
+ instance.queue = [];
+
+ /**
+ * Array with internal eventsubscribers.
+ * @property _eventhandlers
+ * @default []
+ * @type Array
+ * @private
+ */
+ eventhandlers = instance._eventhandlers = [];
+
+ /**
+ * Reference to which MessageViewer wil handle untargeted messages.
+ * @property _targets
+ * @default {info: 'itsadialog', warn: 'itsadialog', error: 'itsadialog', status: undefined, modelsync: undefined}
+ * @type Object
+ * @private
+ */
+ instance._targets = {
+ info: ITSADIALOG,
+ warn: ITSADIALOG,
+ error: ITSADIALOG
+ };
+
+ /**
+ * Reference to which MessageViewer wil handle untargeted 'simple'-messages.
+ * @property _simpleTargets
+ * @default {info: 'itsadialog', warn: 'itsadialog', error: 'itsadialog'}
+ * @type Object
+ * @private
+ */
+ instance._simpleTargets = {
+ info: ITSADIALOG,
+ warn: ITSADIALOG,
+ error: ITSADIALOG
+ };
+
+ /**
+ * The sound that is generated when a message at level-error occurs. Sound only happens when the property soundError is set true.<br>
+ * @property errorMidi
+ * @default 'xxxxx.midi'
+ * @type String
+ */
+ instance.errorMidi = 'error.midi';
+
+ /**
+ * Whether the webapp should sound when a message at level-error appears<br>
+ * The messagesound is defined by a midi-file, which is defined by the property: warnMidi
+ * @property soundWarning
+ * @default true
+ * @type Boolean
+ */
+ instance.soundWarning = true;
+
+ /**
+ * Whether the webapp should sound when a message at level-error appears<br>
+ * The messagesound is defined by a midi-file, which is defined by the property: errorMidi
+ * @property soundError
+ * @default true
+ * @type Boolean
+ */
+ instance.soundError = true;
+
+ /**
+ * The sound that is generated when a message at warb-error occurs. Sound only happens when the property soundWarning is set true.<br>
+ * @property errorMidi
+ * @default 'xxxxx.midi'
+ * @type String
+ */
+ instance.warnMidi = 'warn.midi';
+
+ eventhandlers.push(
+ Y.on(
+ NEWMESSAGE,
+ function(e) {
+ var itsamessage = e.itsamessage,
+ messagetarget = itsamessage.target;
+ if (messagetarget && !itsamessage._simpleMessage && messagetarget.simpleMessages) {
+ e.preventDefault();
+ Y.log(ERROR_MSG_SIMPLE_NOTARGET, 'warn', 'ITSAMessageController');
+ itsamessage._rejectPromise(new Error(ERROR_MSG_SIMPLE_NOTARGET));
+ }
+ }
+ )
+ );
+
+ Y.later(LOADDELAY, instance, instance.isReady);
+};
+
+/**
+ * Promise that is resolved once all dependencies are loaded and ITSAMessageController is ready to use.<br>
+ * To speed up initial loading of the webpage, several modules are loaded by delay, or when needed. this.isReady() holds the promise
+ * that everything is loaded.
+ *
+ * @method isReady
+ * @return {Y.Promise} resolves when everything is loaded.
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype.isReady = function() {
+ Y.log('isReady', 'info', 'ITSAMessageController');
+ var instance = this;
+ return instance._readyPromise || (instance._readyPromise=Y.usePromise(BASE_BUILD, GALLERY_ITSAMESSAGE).then(
+ function() {
+ instance._intlMessageObj = new Y.ITSAMessage(); // used for synchronous translations
+ },
+ function(reason) {
+ var facade = {
+ error : reason && (reason.message || reason),
+ src : 'ITSAMessageViewer'
+ };
+ instance._lazyFireErrorEvent(facade);
+ }
+ ));
+};
+
+/**
+ * Adds the Y.ITSAMessage-instance to the queue.<br>
+ * This method is meant for creating custom messages. Read Y.ITSAMessage for how to setup a new Y.ITSAMessage-instance.<br>
+ * <b>Note:</b> itsamessage needs to be initiated. Destruction takes place automaticly when it gets out of the queue (Y.ITSAMessageController takes care of this)
+ *
+ * @method queueMessage
+ * @param itsamessage {Y.ITSAMessage} the Y.ITSAMessage-instance to be viewed.
+ * @return {Y.Promise} Promise that holds the user-response.
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype.queueMessage = function(itsamessage) {
+ Y.log('queueMessage', 'info', 'ITSAMessageController');
+ var instance = this,
+ promise, promiseResolve, promiseReject;
+ promise = new Y.Promise(function (resolve, reject) {
+ promiseResolve = resolve;
+ promiseReject = reject;
+ });
+ // we pass the promise, together with the resolve and reject handlers as an option to the event.
+ // this way we can fullfill the promise in the messageviewer or prevDefaultFn.
+/*jshint expr:true */
+ itsamessage || (itsamessage = {});
+ itsamessage._promise = promise;
+ itsamessage._resolvePromise = promiseResolve;
+ itsamessage._rejectPromise = promiseReject;
+ // lazy publish the event
+ /**
+ * Event fired when a new Y.ITSAMessage-instance gets in the queue.
+ * @preventable
+ * @event newmessage
+ * @param e {EventFacade} Event Facade including:
+ * @param e.itsamessage {Y.ITSAMessage} Y.ITSAMessage-instance.
+ **/
+ instance[PUBLISHED_NEWMESSAGE] || (instance[PUBLISHED_NEWMESSAGE]=Y.publish(NEWMESSAGE,
+ {
+ defaultTargetOnly: true,
+ emitFacade: true,
+ defaultFn: Y.rbind(instance._defQueueFn, instance),
+ preventedFn: instance._prevDefFn
+ }
+ ));
+ Y.fire(NEWMESSAGE, {itsamessage: itsamessage});
+/*jshint expr:false */
+ return promise;
+};
+
+/**
+ * Creates a sound, if appropriate. Plays itsamessage.soundfile if found. Otherwise this.warnMidi or this.errorMidi might be played, but only if
+ * itsamessage.level has the 'warn'-level or 'error'-level and the corresponding this.soundWarning/this.soundError is true.
+ * @method sound
+ * @param itsamessage {Y.ITSAMessage} The Y.ITSAMessage-instance which should be sounded.
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype.sound = function(itsamessage) {
+ Y.log('sound', 'info', 'ITSAMessage');
+ var instance = this;
+ instance.isReady().then(
+ function() {
+ var soundfile,
+ itsamessageSoundfile = itsamessage.soundfile;
+/*jshint expr:true */
+ if (itsamessageSoundfile) {
+ soundfile = itsamessageSoundfile;
+ }
+ else if (itsamessage.level===WARN) {
+ instance.soundWarning && (soundfile=instance.warnMidi);
+ }
+ else if (itsamessage.level===ERROR) {
+ instance.soundError && (soundfile=instance.errorMidi);
+ }
+ itsamessage.noAudio || (soundfile && instance._playMidi(soundfile));
+/*jshint expr:false */
+ }
+ );
+};
+
+/**
+ * Cleans up bindings
+ * @method destructor
+ * @protected
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype.destructor = function() {
+ Y.log('destructor', 'info', 'ITSAMessageController');
+ var instance = this,
+ queue = instance.queue,
+ intlMessageObj = instance._intlMessageObj;
+ instance._clearEventhandlers();
+ instance.removeTarget(Y);
+ YArray.each(
+ queue,
+ function(itsamessage) {
+ itsamessage.detachAll();
+ itsamessage.destroy();
+ itsamessage = null;
+ }
+ );
+ queue.length = 0;
+/*jshint expr:true */
+ intlMessageObj && intlMessageObj.destroy() && (instance._intlMessageObj=null);
+/*jshint expr:false */
+ instance._targets = {};
+ instance._simpleTargets = {};
+};
+
+//--- private methods ---------------------------------------------------
+
+/**
+ * Cleaning up all eventlisteners
+ *
+ * @method _clearEventhandlers
+ * @private
+ * @since 0.1
+ *
+*/
+ITSAMessageControllerClass.prototype._clearEventhandlers = function() {
+ Y.log('_clearEventhandlers', 'info', 'ITSAMessageController');
+ var instance = this;
+ YArray.each(
+ instance._eventhandlers,
+ function(item){
+ item.detach();
+ }
+ );
+};
+
+/**
+ * Plays a midi-file.
+ * @method _playMidi
+ * @param soundfile {String} The soundfile to be played.
+ * @private
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype._playMidi = function(soundfile) {
+ Y.log('_playMidi', 'info', 'ITSAMessageController');
+ // TODO: create JS to play a midi-file
+ console.log('playing '+soundfile);
+};
+
+/**
+ * Rearanges the 3 parameters that are passed through to many methods. Because some of them are optional.<br>
+ * Returns an object where you are sure that all properties are indeed those that the developer send through.
+ *
+ * @method _retrieveParams
+ * @param title {String} 1st parameter
+ * @param message {String} 2nd parameter
+ * @param config {Object} 3th parameter
+ * @private
+ * @return {Object} with properties: title, message and config
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype._retrieveParams = function(title, message, config) {
+ Y.log('_retrieveParams', 'info', 'ITSAMessageController');
+ var withTitle = (typeof message === STRING),
+ withMessage;
+ if (!withTitle) {
+ config = message;
+ message = title;
+ title = null;
+ }
+ withMessage = (typeof message === STRING);
+ if (!withMessage) {
+ // oops, just passed an object --> perhaps it is an error-object?
+ config = {};
+ message = (message && (message.message || ''));
+ }
+/*jshint expr:true */
+ config || (config={});
+/*jshint expr:false */
+ return {
+ title: title,
+ message: message,
+ config: config
+ };
+};
+
+/**
+ * Rearanges the 3 parameters that are passed through to many methods. Because some of the are optional.<br>
+ * Returns an object where you are sure that all properties are indeed those that the developer send through.
+ *
+ * @method _setupModelSyncListeners
+ * @param title {String} 1st parameter
+ * @param message {String} 2nd parameter
+ * @param config {Object} 3th parameter
+ * @private
+ * @return {Object} with properties: title, message and config
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype._setupModelSyncListeners = function() {
+ Y.log('_setupModelSyncListeners', 'info', 'ITSAMessageController');
+ var instance = this,
+ eventhandlers = instance._eventhandlers;
+ eventhandlers.push(
+ Y.on(['*:load', '*:submit', '*:save', '*:destroy'], function(e) {
+ var model = e.target,
+ type = e.type,
+ options = e.options,
+ remove = options && (options.remove || options[DELETE]),
+ subtype = type.split(':')[1],
+ statushandle, defSyncMessages;
+ // cannot check Y.Model or Y.ModelList until we are sure the model-module is loaded
+ Y.usePromise(MODEL, MODEL+'-'+LIST, GALLERYITSAMODELSYNCPROMISE, GALLERYITSAMODELLISTSYNCPROMISE).then(
+ function() {
+ // model._itsaMessageViewer needs to be undefined, that means it has no target
+ if (((model instanceof Y.Model) || (model instanceof Y.ModelList)) && ((subtype!==DESTROY) || remove) && (!model._itsamessageListener)) {
+ // because multiple simultanious on-events will return only one after-event (is this an error?),
+ // we will take the promise's then() to remove the status lateron.
+ defSyncMessages = model._defSyncMessages;
+ statushandle = instance._showStatus(e.syncmessage || (defSyncMessages && defSyncMessages[subtype]) || Y.Intl.get(GALLERYITSAMODELSYNCPROMISE)[subtype], {source: MODELSYNC, busy: true});
+ e.promise.then(
+ function() {
+ instance._removeStatus(statushandle);
+ },
+ function() {
+ instance._removeStatus(statushandle);
+ }
+ );
+ }
+ }
+ );
+ })
+ );
+};
+
+/**
+ * Informs the user with a message and three buttons: 'abort', 'ignore', 'retry'.<br>
+ * The promise can resolve by either 'ignore' or 'retry' and will reject by 'abort'. Once resolved, look for result.button
+ * to find out which button the user pressed.<br>
+ * <b>Note:</b> You need a descendant of Y.ITSAMessageViewer (f.i. Y.ITSADialog) to make the message be displayed!
+ *
+ * @method _getRetryConfirmation
+ * @param [title] {String} The title of the message
+ * @param [message] {String} The message
+ * @param [config] {Object} Config passed through to the Y.ITSAMessage instance and the next additional properties:
+ * @param [config.closeButton] {Boolean} whether the closebutton should be visible.
+ * By setting this, you the default setting of closeButton is overruled.
+ * @param [config.icon] {String} Classname of the iconfont, for instance 'itsaicon-dialog-info' --> see gallerycss-itsa-base for more info about iconfonts.
+ * By setting this, you the default icon is overruled.
+ * @param [config.imageButtons] {Boolean} Whether to display imagebuttons.
+ * @param [config.level] {String} The message-level, should be either 'info', warn' or 'error'.
+ * @param [config.priority] {boolean} By setting this, the message will be positioned in the queue above messages that have no priority.
+ * @param [config.primaryButton] {String} Name of the primary button, f.i. 'btn_ok'.
+ * By setting this, you the default primaryButton ('btn_retry') is overruled.
+ * @param [config.source] {String} Identification of the source (sender) of the message, which is 'application' by default.
+ * @param [config.target] {Y.ITSAMessageViewer} MessageViewer-instance that is targeted and should handle the message.
+ * @param [config.timeoutReject] {Number} Timeout after which the message's visiblilty should be rejected
+ * @param [config.timeoutResolve] {Number} Timeout after which the message's visiblilty should be resolved
+ * @private
+ * @return {Y.Promise} Promise that holds the user-response. Check 'button' to find out what button was pressed.
+ * resolve(result) --> result.button==='ignore' || 'retry' OR reject(reason) --> reason==='abort' or error
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype[UNDERSCORE+GET_RETRY_CONFIRMATION] = function(title, message, config) {
+ Y.log('_getRetryConfirmation', 'info', 'ITSAMessageController');
+ return this._queueMessage(title, message, config, '{btn_abort}{btn_ignore}{btn_retry}', 'btn_retry', 'btn_abort', GET_RETRY_CONFIRMATION, WARN, ICON_WARN);
+};
+
+/**
+ * Informs the user with a message and two buttons: 'no' and 'yes'.<br>
+ * The promise can resolve by 'yes and will reject by 'no'.
+ * <b>Note:</b> You need a descendant of Y.ITSAMessageViewer (f.i. Y.ITSADialog) to make the message be displayed!
+ *
+ * @method _getConfirmation
+ * @param [title] {String} The title of the message
+ * @param [message] {String} The message
+ * @param [config] {Object} Config passed through to the Y.ITSAMessage instance and the next additional properties:
+ * @param [config.closeButton] {Boolean} whether the closebutton should be visible.
+ * By setting this, you the default setting of closeButton is overruled.
+ * @param [config.icon] {String} Classname of the iconfont, for instance 'itsaicon-dialog-info' --> see gallerycss-itsa-base for more info about iconfonts.
+ * By setting this, you the default icon is overruled.
+ * @param [config.imageButtons] {Boolean} Whether to display imagebuttons.
+ * @param [config.level] {String} The message-level, should be either 'info', warn' or 'error'.
+ * @param [config.priority] {boolean} By setting this, the message will be positioned in the queue above messages that have no priority.
+ * @param [config.primaryButton] {String} Name of the primary button, f.i. 'btn_ok'.
+ * By setting this, you the default primaryButton 'btn_yes' is overruled.
+ * @param [config.source] {String} Identification of the source (sender) of the message, which is 'application' by default.
+ * @param [config.target] {Y.ITSAMessageViewer} MessageViewer-instance that is targeted and should handle the message.
+ * @param [config.timeoutReject] {Number} Timeout after which the message's visiblilty should be rejected
+ * @param [config.timeoutResolve] {Number} Timeout after which the message's visiblilty should be resolved
+ * @private
+ * @return {Y.Promise} Promise that holds the user-response. Resolves by 'ok' and rejects by 'no'.
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype[UNDERSCORE+GET_CONFIRMATION] = function(title, message, config) {
+ Y.log('_getConfirmation', 'info', 'ITSAMessageController');
+ return this._queueMessage(title, message, config, '{btn_no}{btn_yes}', 'btn_yes', 'btn_no', GET_CONFIRMATION, INFO, ICON_QUESTION);
+};
+
+/**
+ * Asks the user for an url.<br>
+ * <b>Note:</b> You need a descendant of Y.ITSAMessageViewer (f.i. Y.ITSADialog) to make the message be displayed!
+ *
+ * @method _getURL
+ * @param [title] {String} The title of the message
+ * @param [message] {String} The message
+ * @param [config] {Object} Config passed through to the Y.ITSAMessage instance and the next additional properties:
+ * @param [config.closeButton] {Boolean} whether the closebutton should be visible.
+ * By setting this, you the default setting of closeButton is overruled.
+ * @param [config.formconfig] {Object} Config that passes through to the UI-element. See Y.ITSAFormModel for usage of formconfig.
+ * @param [config.icon] {String} Classname of the iconfont, for instance 'itsaicon-dialog-info' --> see gallerycss-itsa-base for more info about iconfonts.
+ * By setting this, you the default icon is overruled.
+ * @param [config.imageButtons] {Boolean} Whether to display imagebuttons.
+ * @param [config.level] {String} The message-level, should be either 'info', warn' or 'error'.
+ * @param [config.priority] {boolean} By setting this, the message will be positioned in the queue above messages that have no priority.
+ * @param [config.primaryButton] {String} Name of the primary button, f.i. 'btn_ok'.
+ * By setting this, you the default primaryButton is overruled.
+ * @param [config.required] {Boolean} Makes the input required: the promise cannot be rejected, there is no cancel or close-button.
+ * @param [config.source] {String} Identification of the source (sender) of the message, which is 'application' by default.
+ * @param [config.target] {Y.ITSAMessageViewer} MessageViewer-instance that is targeted and should handle the message.
+ * @param [config.timeoutReject] {Number} Timeout after which the message's visiblilty should be rejected
+ * @param [config.timeoutResolve] {Number} Timeout after which the message's visiblilty should be resolved
+ * @param [config.validationerror] {String} Message that Y.Tipsy uses when validation fails.
+ * @param [config.validator] {Function} Validator function for the UI-element
+ * @param [config.value] {Any} Initial value that passes through to the UI-element.
+ * @private
+ * @return {Y.Promise} Promise that holds the user-response.
+ * resolve(result) --> result.input===the url OR reject(reason) --> reason==='cancel' or error
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype[UNDERSCORE+GET_URL] = function(title, message, config) {
+ Y.log('_getURL', 'info', 'ITSAMessageController');
+ var instance = this,
+ params = instance._retrieveParams(title, message, config),
+ newconfig = params.config;
+ newconfig.url = true;
+ return instance[UNDERSCORE+GET_INPUT](params.title, params.message, newconfig);
+};
+
+/**
+ * Asks the user for an emailaddress.<br>
+ * <b>Note:</b> You need a descendant of Y.ITSAMessageViewer (f.i. Y.ITSADialog) to make the message be displayed!
+ *
+ * @method _getEmail
+ * @param [title] {String} The title of the message
+ * @param [message] {String} The message
+ * @param [config] {Object} Config passed through to the Y.ITSAMessage instance and the next additional properties:
+ * @param [config.closeButton] {Boolean} whether the closebutton should be visible.
+ * By setting this, you the default setting of closeButton is overruled.
+ * @param [config.formconfig] {Object} Config that passes through to the UI-element. See Y.ITSAFormModel for usage of formconfig.
+ * @param [config.icon] {String} Classname of the iconfont, for instance 'itsaicon-dialog-info' --> see gallerycss-itsa-base for more info about iconfonts.
+ * By setting this, you the default icon is overruled.
+ * @param [config.imageButtons] {Boolean} Whether to display imagebuttons.
+ * @param [config.level] {String} The message-level, should be either 'info', warn' or 'error'.
+ * @param [config.priority] {boolean} By setting this, the message will be positioned in the queue above messages that have no priority.
+ * @param [config.primaryButton] {String} Name of the primary button, f.i. 'btn_ok'.
+ * By setting this, you the default primaryButton is overruled.
+ * @param [config.required] {Boolean} Makes the input required: the promise cannot be rejected, there is no cancel or close-button.
+ * @param [config.source] {String} Identification of the source (sender) of the message, which is 'application' by default.
+ * @param [config.target] {Y.ITSAMessageViewer} MessageViewer-instance that is targeted and should handle the message.
+ * @param [config.timeoutReject] {Number} Timeout after which the message's visiblilty should be rejected
+ * @param [config.timeoutResolve] {Number} Timeout after which the message's visiblilty should be resolved
+ * @param [config.validationerror] {String} Message that Y.Tipsy uses when validation fails.
+ * @param [config.validator] {Function} Validator function for the UI-element
+ * @param [config.value] {Any} Initial value that passes through to the UI-element.
+ * @private
+ * @return {Y.Promise} Promise that holds the user-response.
+ * resolve(result) --> result.input===the emailaddress OR reject(reason) --> reason==='cancel' or error
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype[UNDERSCORE+GET_EMAIL] = function(title, message, config) {
+ Y.log('_getEmail', 'info', 'ITSAMessageController');
+ var instance = this,
+ params = instance._retrieveParams(title, message, config),
+ newconfig = params.config;
+ newconfig.email = true;
+ return instance[UNDERSCORE+GET_INPUT](params.title, params.message, newconfig);
+};
+
+/**
+ * Asks the user for any input.<br>
+ * <b>Note:</b> You need a descendant of Y.ITSAMessageViewer (f.i. Y.ITSADialog) to make the message be displayed!
+ *
+ * @method _getInput
+ * @param [title] {String} The title of the message
+ * @param [message] {String} The message
+ * @param [config] {Object} Config passed through to the Y.ITSAMessage instance and the next additional properties:
+ * @param [config.closeButton] {Boolean} whether the closebutton should be visible.
+ * By setting this, you the default setting of closeButton is overruled.
+ * @param [config.formconfig] {Object} Config that passes through to the UI-element. See Y.ITSAFormModel for usage of formconfig.
+ * @param [config.icon] {String} Classname of the iconfont, for instance 'itsaicon-dialog-info' --> see gallerycss-itsa-base for more info about iconfonts.
+ * By setting this, you the default icon is overruled.
+ * @param [config.imageButtons] {Boolean} Whether to display imagebuttons.
+ * @param [config.level] {String} The message-level, should be either 'info', warn' or 'error'.
+ * @param [config.priority] {boolean} By setting this, the message will be positioned in the queue above messages that have no priority.
+ * @param [config.primaryButton] {String} Name of the primary button, f.i. 'btn_ok'.
+ * By setting this, you the default primaryButton is overruled.
+ * @param [config.required] {Boolean} Makes the input required: the promise cannot be rejected, there is no cancel or close-button.
+ * @param [config.source] {String} Identification of the source (sender) of the message, which is 'application' by default.
+ * @param [config.target] {Y.ITSAMessageViewer} MessageViewer-instance that is targeted and should handle the message.
+ * @param [config.textarea] {Boolean} Render a textarea instead of an input-element.
+ * @param [config.timeoutReject] {Number} Timeout after which the message's visiblilty should be rejected
+ * @param [config.timeoutResolve] {Number} Timeout after which the message's visiblilty should be resolved
+ * @param [config.validationerror] {String} Message that Y.Tipsy uses when validation fails.
+ * @param [config.validator] {Function} Validator function for the UI-element
+ * @param [config.value] {Any} Initial value that passes through to the UI-element.
+ * @private
+ * @return {Y.Promise} Promise that holds the user-response.
+ * resolve(result) --> result.input===the input OR reject(reason) --> reason==='cancel' or error
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype[UNDERSCORE+GET_INPUT] = function(title, message, config) {
+ Y.log('_getInput', 'info', 'ITSAMessageController');
+ var instance = this,
+ params = instance._retrieveParams(title, message, config),
+ required, MyITSAMessage, email, url, formtype, formconfig;
+ title = params.title;
+ message = params.message;
+ config = params.config;
+ formconfig = config.formconfig || {};
+ formconfig.fullselect = true;
+ email = (typeof config.email === BOOLEAN) && config.email;
+ url = (typeof config.url === BOOLEAN) && config.url;
+ formconfig.primarybtnonenter = !config[TEXTAREA] || email || url;
+ formtype = email ? EMAIL : (url ? URL : (config[TEXTAREA] ? TEXTAREA : 'text'));
+ formconfig.classname = 'itsa-'+formtype + (formconfig.classname ? ' '+formconfig.classname : '');
+ required = (typeof config.required === BOOLEAN) && config.required;
+ formconfig.required = required;
+ return instance.isReady().then(
+ function() {
+/*jshint expr:true */
+ (config.email || config.url) && (config.validationerror || (config.validationerror=instance._intlMessageObj.translate('enterrightformat')));
+/*jshint expr:false */
+ MyITSAMessage = Y.Base.create('itsamessageinput', Y.ITSAMessage, [], null, {
+ ATTRS: {
+ input: {
+ value: config.value,
+ formtype: formtype,
+ formconfig: formconfig,
+ validator: config.validator,
+ validationerror: config.validationerror
+ }
+ }
+ });
+ message += '<fieldset class="'+'itsa-input'+'">'+
+ '<div class="pure-control-group">{input}</div>'+
+ '</fieldset>';
+ return instance._queueMessage(title, message, config, (required ? '' : '{btn_cancel}') + '{btn_ok}', 'btn_ok', (required ? null : 'btn_cancel'), GET_INPUT, INFO, ICON_INFO, null, null, MyITSAMessage);
+ }
+ );
+};
+
+/**
+ * Asks the user for a number.<br>
+ * <b>Note:</b> You need a descendant of Y.ITSAMessageViewer (f.i. Y.ITSADialog) to make the message be displayed!
+ *
+ * @method _getNumber
+ * @param [title] {String} The title of the message
+ * @param [message] {String} The message
+ * @param [config] {Object} Config passed through to the Y.ITSAMessage instance and the next additional properties:
+ * @param [config.closeButton] {Boolean} whether the closebutton should be visible.
+ * By setting this, you the default setting of closeButton is overruled.
+ * @param [config.formconfig] {Object} Config that passes through to the UI-element. See Y.ITSAFormModel for usage of formconfig.
+ * @param [config.icon] {String} Classname of the iconfont, for instance 'itsaicon-dialog-info' --> see gallerycss-itsa-base for more info about iconfonts.
+ * By setting this, you the default icon is overruled.
+ * @param [config.imageButtons] {Boolean} Whether to display imagebuttons.
+ * @param [config.level] {String} The message-level, should be either 'info', warn' or 'error'.
+ * @param [config.priority] {boolean} By setting this, the message will be positioned in the queue above messages that have no priority.
+ * @param [config.primaryButton] {String} Name of the primary button, f.i. 'btn_ok'.
+ * By setting this, you the default primaryButton is overruled.
+ * @param [config.required] {Boolean} Makes the input required: the promise cannot be rejected, there is no cancel or close-button.
+ * @param [config.source] {String} Identification of the source (sender) of the message, which is 'application' by default.
+ * @param [config.target] {Y.ITSAMessageViewer} MessageViewer-instance that is targeted and should handle the message.
+ * @param [config.timeoutReject] {Number} Timeout after which the message's visiblilty should be rejected
+ * @param [config.timeoutResolve] {Number} Timeout after which the message's visiblilty should be resolved
+ * @param [config.validationerror] {String} Message that Y.Tipsy uses when validation fails.
+ * @param [config.validator] {Function} Validator function for the UI-element
+ * @param [config.value] {Any} Initial value that passes through to the UI-element.
+ * @private
+ * @return {Y.Promise} Promise that holds the user-response.
+ * resolve(result) --> result.number===the number OR reject(reason) --> reason==='cancel' or error
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype[UNDERSCORE+GET_NUMBER] = function(title, message, config) {
+ Y.log('_getNumber', 'info', 'ITSAMessageController');
+ var instance = this,
+ params = instance._retrieveParams(title, message, config),
+ required, MyITSAMessage, formconfig;
+ title = params.title;
+ message = params.message;
+ config = params.config;
+ formconfig = config.formconfig || {};
+ formconfig.fullselect = true;
+ formconfig.primarybtnonenter = true;
+ formconfig.classname = 'itsa-number' + (formconfig.classname ? ' '+formconfig.classname : '');
+ formconfig.required = true;
+ required = (typeof config.required === BOOLEAN) && config.required;
+ return instance.isReady().then(
+ function() {
+/*jshint expr:true */
+ config.validationerror || (config.validationerror=instance._intlMessageObj.translate('entervalidnumber'));
+/*jshint expr:false */
+ MyITSAMessage = Y.Base.create('itsamessagenumber', Y.ITSAMessage, [], null, {
+ ATTRS: {
+ number: {
+ value: config.value,
+ formtype: 'number',
+ formconfig: formconfig,
+ validator: config.validator,
+ validationerror: config.validationerror
+ }
+ }
+ });
+ message += '<fieldset class="'+'itsa-number'+'">'+
+ '<div class="pure-control-group">{number}</div>'+
+ '</fieldset>';
+ return instance._queueMessage(title, message, config, (required ? '' : '{btn_cancel}') + '{btn_ok}', 'btn_ok', (required ? null : 'btn_cancel'), GET_NUMBER, INFO, ICON_INFO, null, null, MyITSAMessage);
+ }
+ );
+};
+
+/**
+ * Removes a message (that was shown using Y.showStatus) from the MessageView - or queue.
+ *
+ * @method _removeStatus
+ * @param handle {Y.Promise} The returnvalue when Y.showStatus was called.
+ * @private
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype[UNDERSCORE+REMOVE_STATUS] = function(messageHandle) {
+ Y.log('_removeStatus', 'info', 'ITSAMessageController');
+ messageHandle.then(
+ function(itsamessage) {
+ itsamessage.resolve();
+ }
+ );
+};
+
+/**
+ * Shows a message.<br>
+ * <b>Note:</b> You need a descendant of Y.ITSAMessageViewer (f.i. Y.ITSADialog) to make the message be displayed!
+ *
+ * @method _showMessage
+ * @param [title] {String} The title of the message
+ * @param [message] {String} The message
+ * @param [config] {Object} Config passed through to the Y.ITSAMessage instance and the next additional properties:
+ * @param [config.closeButton] {Boolean} whether the closebutton should be visible.
+ * By setting this, you the default setting of closeButton is overruled.
+ * @param [config.icon] {String} Classname of the iconfont, for instance 'itsaicon-dialog-info' --> see gallerycss-itsa-base for more info about iconfonts.
+ * By setting this, you the default icon is overruled.
+ * @param [config.imageButtons] {Boolean} Whether to display imagebuttons.
+ * @param [config.level] {String} The message-level, should be either 'info', warn' or 'error'.
+ * @param [config.priority] {boolean} By setting this, the message will be positioned in the queue above messages that have no priority.
+ * @param [config.primaryButton] {String} Name of the primary button, f.i. 'btn_ok'.
+ * By setting this, you the default primaryButton is overruled.
+ * @param [config.source] {String} Identification of the source (sender) of the message, which is 'application' by default.
+ * @param [config.target] {Y.ITSAMessageViewer} MessageViewer-instance that is targeted and should handle the message.
+ * @param [config.timeoutReject] {Number} Timeout after which the message's visiblilty should be rejected
+ * @param [config.timeoutResolve] {Number} Timeout after which the message's visiblilty should be resolved
+ * @private
+ * @return {Y.Promise} Promise that holds the user-response. Resolved once the user presses the 'ok'-button.
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype[UNDERSCORE+SHOW_MESSAGE] = function(title, message, config) {
+ Y.log('_showMessage', 'info', 'ITSAMessageController');
+ return this._queueMessage(title, message, config, '{btn_ok}', 'btn_ok', null, SHOW_MESSAGE, INFO, ICON_INFORM, false, true);
+};
+
+/**
+ * Shows a warning. Because the level will be 'warn', the message has precedence above normal messages.<br>
+ * <b>Note:</b> You need a descendant of Y.ITSAMessageViewer (f.i. Y.ITSADialog) to make the message be displayed!
+ *
+ * @method _showWarning
+ * @param [title] {String} The title of the message
+ * @param [message] {String} The message
+ * @param [config] {Object} Config passed through to the Y.ITSAMessage instance and the next additional properties:
+ * @param [config.closeButton] {Boolean} whether the closebutton should be visible.
+ * By setting this, you the default setting of closeButton is overruled.
+ * @param [config.icon] {String} Classname of the iconfont, for instance 'itsaicon-dialog-info' --> see gallerycss-itsa-base for more info about iconfonts.
+ * By setting this, you the default icon is overruled.
+ * @param [config.imageButtons] {Boolean} Whether to display imagebuttons.
+ * @param [config.level] {String} The message-level, should be either 'info', warn' or 'error'.
+ * @param [config.priority] {boolean} By setting this, the message will be positioned in the queue above messages that have no priority.
+ * @param [config.primaryButton] {String} Name of the primary button, f.i. 'btn_ok'.
+ * By setting this, you the default primaryButton is overruled.
+ * @param [config.source] {String} Identification of the source (sender) of the message, which is 'application' by default.
+ * @param [config.target] {Y.ITSAMessageViewer} MessageViewer-instance that is targeted and should handle the message.
+ * @param [config.timeoutReject] {Number} Timeout after which the message's visiblilty should be rejected
+ * @param [config.timeoutResolve] {Number} Timeout after which the message's visiblilty should be resolved
+ * @private
+ * @return {Y.Promise} Promise that holds the user-response. Resolved once the user presses the 'ok'-button.
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype[UNDERSCORE+SHOW_WARNING] = function(title, message, config) {
+ Y.log('_showWarning', 'info', 'ITSAMessageController');
+ return this._queueMessage(title, message, config, '{btn_ok}', 'btn_ok', null, SHOW_WARNING, WARN, ICON_WARN, false, true);
+};
+
+/**
+ * Shows an error. Because the level will be 'error', the message has precedence above warnings and normal messages.<br>
+ * <b>Note:</b> You need a descendant of Y.ITSAMessageViewer (f.i. Y.ITSADialog) to make the message be displayed!
+ *
+ * @method _showError
+ * @param [title] {String} The title of the message
+ * @param [message] {String} The message
+ * @param [config] {Object} Config passed through to the Y.ITSAMessage instance and the next additional properties:
+ * @param [config.closeButton] {Boolean} whether the closebutton should be visible.
+ * By setting this, you the default setting of closeButton is overruled.
+ * @param [config.icon] {String} Classname of the iconfont, for instance 'itsaicon-dialog-info' --> see gallerycss-itsa-base for more info about iconfonts.
+ * By setting this, you the default icon is overruled.
+ * @param [config.imageButtons] {Boolean} Whether to display imagebuttons.
+ * @param [config.level] {String} The message-level, should be either 'info', warn' or 'error'.
+ * @param [config.priority] {boolean} By setting this, the message will be positioned in the queue above messages that have no priority.
+ * @param [config.primaryButton] {String} Name of the primary button, f.i. 'btn_ok'.
+ * By setting this, you the default primaryButton is overruled.
+ * @param [config.source] {String} Identification of the source (sender) of the message, which is 'application' by default.
+ * @param [config.target] {Y.ITSAMessageViewer} MessageViewer-instance that is targeted and should handle the message.
+ * @param [config.timeoutReject] {Number} Timeout after which the message's visiblilty should be rejected
+ * @param [config.timeoutResolve] {Number} Timeout after which the message's visiblilty should be resolved
+ * @private
+ * @return {Y.Promise} Promise that holds the user-response. Resolved once the user presses the 'ok'-button.
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype[UNDERSCORE+SHOW_ERROR] = function(title, message, config) {
+ Y.log('_showError', 'info', 'ITSAMessageController');
+ return this._queueMessage(title, message, config, '{btn_ok}', 'btn_ok', null, SHOW_ERROR, ERROR, ICON_ERROR, false, true);
+};
+
+/**
+ * Returns a handle with reference to the ITSAMessage-instance. The message itself is NOT fullfilled yet!<br>
+ * Because there are no buttons to make it fullfilled, you <u>must fullfil manually</u> by calling removeStatus(handle)<br>
+ * <b>Note:</b> You need a descendant of Y.ITSAMessageViewer that has its property 'statusMessages' (f.i. Y.ITSADialog) to make the message be displayed!
+ *
+ * @method _showStatus
+ * @param message {String} The message
+ * @param [config] {Object} Config passed through to the Y.ITSAMessage instance and the next additional properties:
+ * @param [config.busy] {Boolean} set true to create a spinning icon in front of message.
+ * @param [config.closeButton] {Boolean} whether the closebutton should be visible.
+ * By setting this, you the default setting of closeButton is overruled.
+ * @param [config.icon] {String} Classname of the iconfont, for instance 'itsaicon-dialog-info' --> see gallerycss-itsa-base for more info about iconfonts.
+ * By setting this, you the default icon is overruled.
+ * @param [config.imageButtons] {Boolean} Whether to display imagebuttons.
+ * @param [config.level] {String} The message-level, should be either 'info', warn' or 'error'.
+ * @param [config.priority] {boolean} By setting this, the message will be positioned in the queue above messages that have no priority.
+ * @param [config.primaryButton] {String} Name of the primary button, f.i. 'btn_ok'.
+ * By setting this, you the default primaryButton is overruled.
+ * @param [config.source] {String} Identification of the source (sender) of the message, which is 'application' by default.
+ * @param [config.target] {Y.ITSAMessageViewer} MessageViewer-instance that is targeted and should handle the message.
+ * @param [config.timeout] {Number} Timeout after which the message should disappear (will actually make the messageinstance resolved)
+ * @private
+ * @return {Y.Promise} handle with reference to the message, needs to be removed manually by Y.removeStatus(handle).
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype[UNDERSCORE+SHOW_STATUS] = function(message, config) {
+ Y.log('_showStatus', 'info', 'ITSAMessageController');
+ var instance = this;
+ message = (typeof message===STRING) ? message : '';
+/*jshint expr:true */
+ config || (config={});
+/*jshint expr:false */
+ return instance.isReady().then(
+ function() {
+ var itsamessage = new Y.ITSAMessage();
+ itsamessage.message = message;
+ itsamessage._simpleMessage = true;
+ itsamessage._statusMessage = true;
+ itsamessage.type = SHOW_STATUS;
+ itsamessage.level = INFO;
+ itsamessage.noButtons = true;
+ itsamessage.priority = config.priority;
+ itsamessage.timeoutResolve = config.timeout;
+ itsamessage.target = config.target;
+ itsamessage.source = config.source || APP;
+ itsamessage.messageType = config.busy ? SHOW_BUSY : SHOW_STATUS;
+ instance.queueMessage(itsamessage);
+ return itsamessage;
+ }
+ );
+};
+
+/**
+ * Fires the ERROR-event and -if not published yet- publish it broadcasted to Y.
+ * Because the error-event is broadcasted to Y, it can be catched by gallery-itsaerrorreporter.
+ *
+ * @method _lazyFireErrorEvent
+ * @param {Object} [facade] eventfacade.
+ * @private
+**/
+ITSAMessageControllerClass.prototype._lazyFireErrorEvent = function(facade) {
+ var instance = this;
+
+ Y.log('_lazyFireErrorEvent', 'info', 'ITSAMessageController');
+ // lazy publish
+ if (!instance._errorEvent) {
+ instance._errorEvent = instance.publish(ERROR, {
+ broadcast: 1
+ });
+ }
+ instance.fire(ERROR, facade);
+};
+
+/**
+ * Prevented defaultFn as a Promise. Cleans up the Y.ITSAMessage-instance and will not add it to the queue.
+ *
+ * @method _prevDefFn
+ * @param e {EventTarget}
+ * @param e.itsamessage {Y.ITSAMessage} Y.ITSAMessage-instance
+ * @private
+ * @return {Y.Promise} resolve promise
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype._prevDefFn = function(e) {
+ Y.log('_prevDefFn', 'info', 'ITSAMessageController');
+ var itsamessage = e.itsamessage;
+ itsamessage._rejectPromise(new Error('queuemessage prevented'));
+ // need to return a Promise to continue the messageviewer
+ return new Y.Promise(function (resolve) {
+ itsamessage.detachAll();
+ itsamessage.destroy();
+ itsamessage = null;
+ resolve();
+ });
+};
+
+
+/**
+ * Prevented defaultFn as a Promise. Adds the Y.ITSAMessage-instane to the queue.
+ *
+ * @method _defQueueFn
+ * @param e {EventTarget}
+ * @param e.itsamessage {Y.ITSAMessage} Y.ITSAMessage-instance
+ * @private
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype._defQueueFn = function(e) {
+ Y.log('_defQueueFn', 'info', 'ITSAMessageController');
+ var instance = this,
+ itsamessage = e.itsamessage,
+ queue = instance.queue;
+ queue.push(itsamessage);
+ return itsamessage._promise.then(
+ null,
+ function() {return true;} // fullfil promise
+ ).then(
+ function() {
+ var index = queue.indexOf(itsamessage);
+/*jshint expr:true */
+ (index>-1) && queue.splice(index, 1);
+/*jshint expr:false */
+ itsamessage.detachAll();
+ itsamessage.destroy();
+ itsamessage = null;
+ }
+ );
+};
+
+// define public methods:
+
+/**
+ * Creates an Y.ITSAMessage-instance and adds it to the queue.<br>
+ *
+ * @method _queueMessage
+ * @param [title] {String} The title of the message
+ * @param [message] {String} The message
+ * @param [config] {Object} Config passed through to the Y.ITSAMessage instance and the next additional properties:
+ * @param [config.closeButton] {Boolean} whether the closebutton should be visible.
+ * By setting this, you the default setting of closeButton is overruled.
+ * @param [config.icon] {String} Classname of the iconfont, for instance 'itsaicon-dialog-info' --> see gallerycss-itsa-base for more info about iconfonts.
+ * By setting this, you the default icon is overruled.
+ * @param [config.imageButtons] {Boolean} Whether to display imagebuttons.
+ * @param [config.level] {String} The message-level, should be either 'info', warn' or 'error'.
+ * @param [config.priority] {boolean} By setting this, the message will be positioned in the queue above messages that have no priority.
+ * @param [config.primaryButton] {String} Name of the primary button, f.i. 'btn_ok'.
+ * By setting this, you the default primaryButton is overruled.
+ * @param [config.source] {String} Identification of the source (sender) of the message, which is 'application' by default.
+ * @param [config.target] {Y.ITSAMessageViewer} MessageViewer-instance that is targeted and should handle the message.
+ * @param [config.timeoutReject] {Number} Timeout after which the message's visiblilty should be rejected
+ * @param [config.timeoutResolve] {Number} Timeout after which the message's visiblilty should be resolved
+ * @param [footer] {String} Footertemplate, typically something like: '{btn_cancel}{btn_ok}' be aware to use <u>brackets</u> to identify the UI-elements!
+ * @param [primaryButton] {String} Name of the primary button, f.i. 'btn_ok'.
+ * @param [rejectButton] {String} Name of the button that rejects the itsamessage-promie, f.i. 'btn_cancel'.
+ * @param [messageType] {String} Identification of the messagetype, which could be used by a Y.ITSAMessageViewer-instance.
+ * @param [level] {String} The message-level, should be either 'info', warn' or 'error'.
+ * @param [icon] {String} Classname of the iconfont, for instance 'itsaicon-dialog-info' --> see gallerycss-itsa-base for more info about iconfonts.
+ * @param [closeButton] {Boolean} whether the closebutton should be visible.
+ * @param [simpleMessage] {Boolean} whether the message is a simplemessage with only title+message.
+ * @param [ITSAMessageClass] {Y.ITSAMessage-Class} the class that is created, defaults to Y.ITSAMessage, but could be a descendant.
+ * @private
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype._queueMessage = function(title, message, config, footer, primaryButton, rejectButton, messageType, level, icon, closeButton, simpleMessage, ITSAMessageClass) {
+ Y.log('_queueMessage', 'info', 'ITSAMessageController');
+ var instance = this,
+ params = instance._retrieveParams(title, message, config),
+ imageButtons, required, simpleMsg;
+ title = params.title;
+ message = params.message;
+ config = params.config;
+ imageButtons = (typeof config.imageButtons === BOOLEAN) && config.imageButtons;
+ simpleMsg = ((typeof config.simpleMessage === BOOLEAN) && config.simpleMessage) || ((typeof simpleMessage === BOOLEAN) && simpleMessage) || false;
+ required = ((typeof config.required === BOOLEAN) && config.required) || false;
+/*jshint expr:true */
+ if (imageButtons) {
+ footer = footer.replace(/\{btn_/g,'{imgbtn_');
+ primaryButton && (primaryButton=primaryButton.replace(/btn_/g,'imgbtn_'));
+ }
+/*jshint expr:false */
+ return instance.isReady().then(
+ function() {
+ var itsamessage = ITSAMessageClass ? (new ITSAMessageClass()) : (new Y.ITSAMessage());
+ itsamessage.title = title;
+ itsamessage.message = message;
+ itsamessage._config = config;
+ itsamessage._simpleMessage = simpleMsg;
+ itsamessage.footer = footer;
+ itsamessage.icon = config.icon || icon;
+ itsamessage.noAudio = config.noAudio || false;
+ itsamessage.closeButton = required ? false : (config.closeButton || closeButton);
+ itsamessage.priority = config.priority;
+ itsamessage.imageButtons = imageButtons;
+ itsamessage.primaryButton = config.primaryButton || primaryButton; // config.primaryButton should overrule primaryButton
+ itsamessage.rejectButton = rejectButton;
+ itsamessage.timeoutResolve = config.timeoutResolve;
+ itsamessage.timeoutReject = config.timeoutReject;
+ itsamessage.target = config.target;
+ itsamessage.level = config.level || level; // config.level should overrule the param level;
+ itsamessage.source = config.source || APP;
+ itsamessage.messageType = messageType;
+ return instance.queueMessage(itsamessage);
+ }
+ );
+};
+
+// define 1 global messagecontroller
+/*jshint expr:true */
+Y.Global.ITSAMessageController || (Y.Global.ITSAMessageController=new ITSAMessageControllerClass());
+/*jshint expr:false */
+Y.ITSAMessageController = Y.Global.ITSAMessageController;
+
+}, 'gallery-2014.01.10-22-44', {
+ "requires": [
+ "yui-base",
+ "oop",
+ "base-base",
+ "base-build",
+ "event-custom-complex",
+ "promise",
+ "event-custom-base",
+ "yui-later",
+ "gallery-itsamodulesloadedpromise"
+ ]
+});
View
2  build/gallery-itsamessagecontroller/gallery-itsamessagecontroller-min.js
@@ -0,0 +1,2 @@
+YUI.add("gallery-itsamessagecontroller",function(e,t){"use strict";function st(){st.superclass.constructor.apply(this,arguments)}var n=e.Array,r="application",i="boolean",s="error",o="info",u="warn",a="string",f="delete",l="destroy",c="essage",h="m"+c,p="mail",d="e"+p,v="url",m=5e3,g="model",y="sync",b="list",w="gallery-itsa",E=y+"promise",S=w+g+E,x=w+g+b+E,T=g+y,N="_pub_",C="new"+h,k=N+C,L=w+h,A="get",O="show",M="remove",_="Status",D="Confirmation",P=A+"Retry"+D,H=A+D,B=A+"Input",j=A+"Number",F=A+"E"+p,I=A+"URL",q=O+"M"+c,R=O+"Warning",U=O+"Error",z=O+_,W=O+"Busy",X=M+_,V="_",$="base-build",J="textarea",K="question",Q=o+"rm",G="itsaicon-dialog-",Y=G+Q,Z=G+s,et=G+o,tt=G+K,nt=G+u,rt="non-simple-message cannot be targetted to simple-messageviewer",it="itsadialog";st.NAME="itsamessagecontroller",e.ITSAMessageControllerClass=e.extend(st,e.Base),st.prototype.initializer=function(){var t=this,n;t.queue=[],n=t._eventhandlers=[],t._targets={info:it,warn:it,error:it},t._simpleTargets={info:it,warn:it,error:it},t.errorMidi="error.midi",t.soundWarning=!0,t.soundError=!0,t.warnMidi="warn.midi",n.push(e.on(C,function(e){var t=e.itsamessage,n=t.target;n&&!t._simpleMessage&&n.simpleMessages&&(e.preventDefault(),t._rejectPromise(new Error(rt)))})),e.later(m,t,t.isReady)},st.prototype.isReady=function(){var t=this;return t._readyPromise||(t._readyPromise=e.usePromise($,L).then(function(){t._intlMessageObj=new e.ITSAMessage},function(e){var n={error:e&&(e.message||e),src:"ITSAMessageViewer"};t._lazyFireErrorEvent(n)}))},st.prototype.queueMessage=function(t){var n=this,r,i,s;return r=new e.Promise(function(e,t){i=e,s=t}),t||(t={}),t._promise=r,t._resolvePromise=i,t._rejectPromise=s,n[k]||(n[k]=e.publish(C,{defaultTargetOnly:!0,emitFacade:!0,defaultFn:e.rbind(n._defQueueFn,n),preventedFn:n._prevDefFn})),e.fire(C,{itsamessage:t}),r},st.prototype.sound=function(e){var t=this;t.isReady().then(function(){var n,r=e.soundfile;r?n=r:e.level===u?t.soundWarning&&(n=t.warnMidi):e.level===s&&t.soundError&&(n=t.errorMidi),e.noAudio||n&&t._playMidi(n)})},st.prototype.destructor=function(){var t=this,r=t.queue,i=t._intlMessageObj;t._clearEventhandlers(),t.removeTarget(e),n.each(r,function(e){e.detachAll(),e.destroy(),e=null}),r.length=0,i&&i.destroy()&&(t._intlMessageObj=null),t._targets={},t._simpleTargets={}},st.prototype._clearEventhandlers=function(){var e=this;n.each(e._eventhandlers,function(e){e.detach()})},st.prototype._playMidi=function(e){console.log("playing "+e)},st.prototype._retrieveParams=function(e,t,n){var r=typeof t===a,i;return r||(n=t,t=e,e=null),i=typeof t===a,i||(n={},t=t&&(t.message||"")),n||(n={}),{title:e,message:t,config:n}},st.prototype._setupModelSyncListeners=function(){var t=this,n=t._eventhandlers;n.push(e.on(["*:load","*:submit","*:save","*:destroy"],function(n){var r=n.target,i=n.type,s=n.options,o=s&&(s.remove||s[f]),u=i.split(":")[1],a,c;e.usePromise(g,g+"-"+b,S,x).then(function(){(r instanceof e.Model||r instanceof e.ModelList)&&(u!==l||o)&&!r._itsamessageListener&&(c=r._defSyncMessages,a=t._showStatus(n.syncmessage||c&&c[u]||e.Intl.get(S)[u],{source:T,busy:!0}),n.promise.then(function(){t._removeStatus(a)},function(){t._removeStatus(a)}))})}))},st.prototype[V+P]=function(e,t,n){return this._queueMessage(e,t,n,"{btn_abort}{btn_ignore}{btn_retry}","btn_retry","btn_abort",P,u,nt)},st.prototype[V+H]=function(e,t,n){return this._queueMessage(e,t,n,"{btn_no}{btn_yes}","btn_yes","btn_no",H,o,tt)},st.prototype[V+I]=function(e,t,n){var r=this,i=r._retrieveParams(e,t,n),s=i.config;return s.url=!0,r[V+B](i.title,i.message,s)},st.prototype[V+F]=function(e,t,n){var r=this,i=r._retrieveParams(e,t,n),s=i.config;return s.email=!0,r[V+B](i.title,i.message,s)},st.prototype[V+B]=function(t,n,r){var s=this,u=s._retrieveParams(t,n,r),a,f,l,c,h,p;return t=u.title,n=u.message,r=u.config,p=r.formconfig||{},p.fullselect=!0,l=typeof r.email===i&&r.email,c=typeof r.url===i&&r.url,p.primarybtnonenter=!r[J]||l||c,h=l?d:c?v:r[J]?J:"text",p.classname="itsa-"+h+(p.classname?" "+p.classname:""),a=typeof r.required===i&&r.required,p.required=a,s.isReady().then(function(){return(r.email||r.url)&&(r.validationerror||(r.validationerror=s._intlMessageObj.translate("enterrightformat"))),f=e.Base.create("itsamessageinput",e.ITSAMessage,[],null,{ATTRS:{input:{value:r.value,formtype:h,formconfig:p,validator:r.validator,validationerror:r.validationerror}}}),n+='<fieldset class="itsa-input"><div class="pure-control-group">{input}</div></fieldset>',s._queueMessage(t,n,r,(a?"":"{btn_cancel}")+"{btn_ok}","btn_ok",a?null:"btn_cancel",B,o,et,null,null,f)})},st.prototype[V+j]=function(t,n,r){var s=this,u=s._retrieveParams(t,n,r),a,f,l;return t=u.title,n=u.message,r=u.config,l=r.formconfig||{},l.fullselect=!0,l.primarybtnonenter=!0,l.classname="itsa-number"+(l.classname?" "+l.classname:""),l.required=!0,a=typeof r.required===i&&r.required,s.isReady().then(function(){return r.validationerror||(r.validationerror=s._intlMessageObj.translate("entervalidnumber")),f=e.Base.create("itsamessagenumber",e.ITSAMessage,[],null,{ATTRS:{number:{value:r.value,formtype:"number",formconfig:l,validator:r.validator,validationerror:r.validationerror}}}),n+='<fieldset class="itsa-number"><div class="pure-control-group">{number}</div></fieldset>',s._queueMessage(t,n,r,(a?"":"{btn_cancel}")+"{btn_ok}","btn_ok",a?null:"btn_cancel",j,o,et,null,null,f)})},st.prototype[V+X]=function(e){e.then(function(e){e.resolve()})},st.prototype[V+q]=function(e,t,n){return this._queueMessage(e,t,n,"{btn_ok}","btn_ok",null,q,o,Y,!1,!0)},st.prototype[V+R]=function(e,t,n){return this._queueMessage(e,t,n,"{btn_ok}","btn_ok",null,R,u,nt,!1,!0)},st.prototype[V+U]=function(e,t,n){return this._queueMessage(e,t,n,"{btn_ok}","btn_ok",null,U,s,Z,!1,!0)},st.prototype[V+z]=function(t,n){var i=this;return t=typeof t===a?t:"",n||(n={}),i.isReady().then(function(){var s=new e.ITSAMessage;return s.message=t,s._simpleMessage=!0,s._statusMessage=!0,s.type=z,s.level=o,s.noButtons=!0,s.priority=n
+.priority,s.timeoutResolve=n.timeout,s.target=n.target,s.source=n.source||r,s.messageType=n.busy?W:z,i.queueMessage(s),s})},st.prototype._lazyFireErrorEvent=function(e){var t=this;t._errorEvent||(t._errorEvent=t.publish(s,{broadcast:1})),t.fire(s,e)},st.prototype._prevDefFn=function(t){var n=t.itsamessage;return n._rejectPromise(new Error("queuemessage prevented")),new e.Promise(function(e){n.detachAll(),n.destroy(),n=null,e()})},st.prototype._defQueueFn=function(e){var t=this,n=e.itsamessage,r=t.queue;return r.push(n),n._promise.then(null,function(){return!0}).then(function(){var e=r.indexOf(n);e>-1&&r.splice(e,1),n.detachAll(),n.destroy(),n=null})},st.prototype._queueMessage=function(t,n,s,o,u,a,f,l,c,h,p,d){var v=this,m=v._retrieveParams(t,n,s),g,y,b;return t=m.title,n=m.message,s=m.config,g=typeof s.imageButtons===i&&s.imageButtons,b=typeof s.simpleMessage===i&&s.simpleMessage||typeof p===i&&p||!1,y=typeof s.required===i&&s.required||!1,g&&(o=o.replace(/\{btn_/g,"{imgbtn_"),u&&(u=u.replace(/btn_/g,"imgbtn_"))),v.isReady().then(function(){var i=d?new d:new e.ITSAMessage;return i.title=t,i.message=n,i._config=s,i._simpleMessage=b,i.footer=o,i.icon=s.icon||c,i.noAudio=s.noAudio||!1,i.closeButton=y?!1:s.closeButton||h,i.priority=s.priority,i.imageButtons=g,i.primaryButton=s.primaryButton||u,i.rejectButton=a,i.timeoutResolve=s.timeoutResolve,i.timeoutReject=s.timeoutReject,i.target=s.target,i.level=s.level||l,i.source=s.source||r,i.messageType=f,v.queueMessage(i)})},e.Global.ITSAMessageController||(e.Global.ITSAMessageController=new st),e.ITSAMessageController=e.Global.ITSAMessageController},"gallery-2014.01.10-22-44",{requires:["yui-base","oop","base-base","base-build","event-custom-complex","promise","event-custom-base","yui-later","gallery-itsamodulesloadedpromise"]});
View
1,036 build/gallery-itsamessagecontroller/gallery-itsamessagecontroller.js
@@ -0,0 +1,1036 @@
+YUI.add('gallery-itsamessagecontroller', function (Y, NAME) {
+
+'use strict';
+
+/*jshint maxlen:215 */
+
+/**
+ *
+ * Extends Y.Model by adding methods through which they can create editable form-elements, which represent and are bound to the propery-value.
+ * This model is for defining the UI-structure for all Model's properties and for firing model-events for
+ * Y.ITSAFormModel does not rendering to the dom itself. That needs to be done by an Y.View-instance, like Y.ITSAViewModel.
+ *
+ * @module gallery-itsamessagecontroller
+ * @extends Base
+ * @class ITSAMessageController
+ * @constructor
+ * @since 0.1
+ *
+ * <i>Copyright (c) 2013 Marco Asbreuk - http://itsasbreuk.nl</i>
+ * YUI BSD License - http://developer.yahoo.com/yui/license.html
+ *
+*/
+
+ var YArray = Y.Array,
+ APP = 'application',
+ BOOLEAN = 'boolean',
+ ERROR = 'error',
+ INFO = 'info',
+ WARN = 'warn',
+ STRING = 'string',
+ DELETE = 'delete',
+ DESTROY = 'destroy',
+ ESSAGE = 'essage',
+ MESSAGE = 'm'+ESSAGE,
+ MAIL = 'mail',
+ EMAIL = 'e'+MAIL,
+ URL = 'url',
+ LOADDELAY = 5000,
+ MODEL = 'model',
+ SYNC = 'sync',
+ LIST = 'list',
+ GALLERY_ITSA = 'gallery-itsa',
+ SYNCPROMISE = SYNC+'promise',
+ GALLERYITSAMODELSYNCPROMISE = GALLERY_ITSA+MODEL+SYNCPROMISE,
+ GALLERYITSAMODELLISTSYNCPROMISE = GALLERY_ITSA+MODEL+LIST+SYNCPROMISE,
+ MODELSYNC = MODEL+SYNC,
+ PUBLISHED = '_pub_',
+ NEWMESSAGE = 'new'+MESSAGE,
+ PUBLISHED_NEWMESSAGE = PUBLISHED+NEWMESSAGE,
+ GALLERY_ITSAMESSAGE = GALLERY_ITSA+MESSAGE,
+ GET = 'get',
+ SHOW = 'show',
+ REMOVE = 'remove',
+ STATUS = 'Status',
+ CONFIRMATION = 'Confirmation',
+ GET_RETRY_CONFIRMATION = GET+'Retry'+CONFIRMATION,
+ GET_CONFIRMATION = GET+CONFIRMATION,
+ GET_INPUT = GET+'Input',
+ GET_NUMBER = GET+'Number',
+ GET_EMAIL = GET+'E'+MAIL,
+ GET_URL = GET+'URL',
+ SHOW_MESSAGE = SHOW+'M'+ESSAGE,
+ SHOW_WARNING = SHOW+'Warning',
+ SHOW_ERROR = SHOW+'Error',
+ SHOW_STATUS = SHOW+STATUS,
+ SHOW_BUSY = SHOW+'Busy',
+ REMOVE_STATUS = REMOVE+STATUS,
+ UNDERSCORE = '_',
+ BASE_BUILD = 'base-build',
+ TEXTAREA = 'textarea',
+ QUESTION = 'question',
+ INFORM = INFO+'rm',
+ ITSAICON_DIALOG = 'itsaicon-dialog-',
+ ICON_INFORM = ITSAICON_DIALOG+INFORM,
+ ICON_ERROR = ITSAICON_DIALOG+ERROR,
+ ICON_INFO = ITSAICON_DIALOG+INFO,
+ ICON_QUESTION = ITSAICON_DIALOG+QUESTION,
+ ICON_WARN = ITSAICON_DIALOG+WARN,
+ ERROR_MSG_SIMPLE_NOTARGET = 'non-simple-message cannot be targetted to simple-messageviewer',
+ ITSADIALOG = 'itsadialog';
+
+function ITSAMessageControllerClass() {
+ ITSAMessageControllerClass.superclass.constructor.apply(this, arguments);
+}
+
+ITSAMessageControllerClass.NAME = 'itsamessagecontroller';
+
+Y.ITSAMessageControllerClass = Y.extend(ITSAMessageControllerClass, Y.Base);
+
+/**
+ * @method initializer
+ * @protected
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype.initializer = function() {
+ var instance = this,
+ eventhandlers;
+
+ /**
+ * Array with all the messages that needs to be shown.
+ * @property queue
+ * @default []
+ * @type Array
+ */
+ instance.queue = [];
+
+ /**
+ * Array with internal eventsubscribers.
+ * @property _eventhandlers
+ * @default []
+ * @type Array
+ * @private
+ */
+ eventhandlers = instance._eventhandlers = [];
+
+ /**
+ * Reference to which MessageViewer wil handle untargeted messages.
+ * @property _targets
+ * @default {info: 'itsadialog', warn: 'itsadialog', error: 'itsadialog', status: undefined, modelsync: undefined}
+ * @type Object
+ * @private
+ */
+ instance._targets = {
+ info: ITSADIALOG,
+ warn: ITSADIALOG,
+ error: ITSADIALOG
+ };
+
+ /**
+ * Reference to which MessageViewer wil handle untargeted 'simple'-messages.
+ * @property _simpleTargets
+ * @default {info: 'itsadialog', warn: 'itsadialog', error: 'itsadialog'}
+ * @type Object
+ * @private
+ */
+ instance._simpleTargets = {
+ info: ITSADIALOG,
+ warn: ITSADIALOG,
+ error: ITSADIALOG
+ };
+
+ /**
+ * The sound that is generated when a message at level-error occurs. Sound only happens when the property soundError is set true.<br>
+ * @property errorMidi
+ * @default 'xxxxx.midi'
+ * @type String
+ */
+ instance.errorMidi = 'error.midi';
+
+ /**
+ * Whether the webapp should sound when a message at level-error appears<br>
+ * The messagesound is defined by a midi-file, which is defined by the property: warnMidi
+ * @property soundWarning
+ * @default true
+ * @type Boolean
+ */
+ instance.soundWarning = true;
+
+ /**
+ * Whether the webapp should sound when a message at level-error appears<br>
+ * The messagesound is defined by a midi-file, which is defined by the property: errorMidi
+ * @property soundError
+ * @default true
+ * @type Boolean
+ */
+ instance.soundError = true;
+
+ /**
+ * The sound that is generated when a message at warb-error occurs. Sound only happens when the property soundWarning is set true.<br>
+ * @property errorMidi
+ * @default 'xxxxx.midi'
+ * @type String
+ */
+ instance.warnMidi = 'warn.midi';
+
+ eventhandlers.push(
+ Y.on(
+ NEWMESSAGE,
+ function(e) {
+ var itsamessage = e.itsamessage,
+ messagetarget = itsamessage.target;
+ if (messagetarget && !itsamessage._simpleMessage && messagetarget.simpleMessages) {
+ e.preventDefault();
+ itsamessage._rejectPromise(new Error(ERROR_MSG_SIMPLE_NOTARGET));
+ }
+ }
+ )
+ );
+
+ Y.later(LOADDELAY, instance, instance.isReady);
+};
+
+/**
+ * Promise that is resolved once all dependencies are loaded and ITSAMessageController is ready to use.<br>
+ * To speed up initial loading of the webpage, several modules are loaded by delay, or when needed. this.isReady() holds the promise
+ * that everything is loaded.
+ *
+ * @method isReady
+ * @return {Y.Promise} resolves when everything is loaded.
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype.isReady = function() {
+ var instance = this;
+ return instance._readyPromise || (instance._readyPromise=Y.usePromise(BASE_BUILD, GALLERY_ITSAMESSAGE).then(
+ function() {
+ instance._intlMessageObj = new Y.ITSAMessage(); // used for synchronous translations
+ },
+ function(reason) {
+ var facade = {
+ error : reason && (reason.message || reason),
+ src : 'ITSAMessageViewer'
+ };
+ instance._lazyFireErrorEvent(facade);
+ }
+ ));
+};
+
+/**
+ * Adds the Y.ITSAMessage-instance to the queue.<br>
+ * This method is meant for creating custom messages. Read Y.ITSAMessage for how to setup a new Y.ITSAMessage-instance.<br>
+ * <b>Note:</b> itsamessage needs to be initiated. Destruction takes place automaticly when it gets out of the queue (Y.ITSAMessageController takes care of this)
+ *
+ * @method queueMessage
+ * @param itsamessage {Y.ITSAMessage} the Y.ITSAMessage-instance to be viewed.
+ * @return {Y.Promise} Promise that holds the user-response.
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype.queueMessage = function(itsamessage) {
+ var instance = this,
+ promise, promiseResolve, promiseReject;
+ promise = new Y.Promise(function (resolve, reject) {
+ promiseResolve = resolve;
+ promiseReject = reject;
+ });
+ // we pass the promise, together with the resolve and reject handlers as an option to the event.
+ // this way we can fullfill the promise in the messageviewer or prevDefaultFn.
+/*jshint expr:true */
+ itsamessage || (itsamessage = {});
+ itsamessage._promise = promise;
+ itsamessage._resolvePromise = promiseResolve;
+ itsamessage._rejectPromise = promiseReject;
+ // lazy publish the event
+ /**
+ * Event fired when a new Y.ITSAMessage-instance gets in the queue.
+ * @preventable
+ * @event newmessage
+ * @param e {EventFacade} Event Facade including:
+ * @param e.itsamessage {Y.ITSAMessage} Y.ITSAMessage-instance.
+ **/
+ instance[PUBLISHED_NEWMESSAGE] || (instance[PUBLISHED_NEWMESSAGE]=Y.publish(NEWMESSAGE,
+ {
+ defaultTargetOnly: true,
+ emitFacade: true,
+ defaultFn: Y.rbind(instance._defQueueFn, instance),
+ preventedFn: instance._prevDefFn
+ }
+ ));
+ Y.fire(NEWMESSAGE, {itsamessage: itsamessage});
+/*jshint expr:false */
+ return promise;
+};
+
+/**
+ * Creates a sound, if appropriate. Plays itsamessage.soundfile if found. Otherwise this.warnMidi or this.errorMidi might be played, but only if
+ * itsamessage.level has the 'warn'-level or 'error'-level and the corresponding this.soundWarning/this.soundError is true.
+ * @method sound
+ * @param itsamessage {Y.ITSAMessage} The Y.ITSAMessage-instance which should be sounded.
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype.sound = function(itsamessage) {
+ var instance = this;
+ instance.isReady().then(
+ function() {
+ var soundfile,
+ itsamessageSoundfile = itsamessage.soundfile;
+/*jshint expr:true */
+ if (itsamessageSoundfile) {
+ soundfile = itsamessageSoundfile;
+ }
+ else if (itsamessage.level===WARN) {
+ instance.soundWarning && (soundfile=instance.warnMidi);
+ }
+ else if (itsamessage.level===ERROR) {
+ instance.soundError && (soundfile=instance.errorMidi);
+ }
+ itsamessage.noAudio || (soundfile && instance._playMidi(soundfile));
+/*jshint expr:false */
+ }
+ );
+};
+
+/**
+ * Cleans up bindings
+ * @method destructor
+ * @protected
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype.destructor = function() {
+ var instance = this,
+ queue = instance.queue,
+ intlMessageObj = instance._intlMessageObj;
+ instance._clearEventhandlers();
+ instance.removeTarget(Y);
+ YArray.each(
+ queue,
+ function(itsamessage) {
+ itsamessage.detachAll();
+ itsamessage.destroy();
+ itsamessage = null;
+ }
+ );
+ queue.length = 0;
+/*jshint expr:true */
+ intlMessageObj && intlMessageObj.destroy() && (instance._intlMessageObj=null);
+/*jshint expr:false */
+ instance._targets = {};
+ instance._simpleTargets = {};
+};
+
+//--- private methods ---------------------------------------------------
+
+/**
+ * Cleaning up all eventlisteners
+ *
+ * @method _clearEventhandlers
+ * @private
+ * @since 0.1
+ *
+*/
+ITSAMessageControllerClass.prototype._clearEventhandlers = function() {
+ var instance = this;
+ YArray.each(
+ instance._eventhandlers,
+ function(item){
+ item.detach();
+ }
+ );
+};
+
+/**
+ * Plays a midi-file.
+ * @method _playMidi
+ * @param soundfile {String} The soundfile to be played.
+ * @private
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype._playMidi = function(soundfile) {
+ // TODO: create JS to play a midi-file
+ console.log('playing '+soundfile);
+};
+
+/**
+ * Rearanges the 3 parameters that are passed through to many methods. Because some of them are optional.<br>
+ * Returns an object where you are sure that all properties are indeed those that the developer send through.
+ *
+ * @method _retrieveParams
+ * @param title {String} 1st parameter
+ * @param message {String} 2nd parameter
+ * @param config {Object} 3th parameter
+ * @private
+ * @return {Object} with properties: title, message and config
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype._retrieveParams = function(title, message, config) {
+ var withTitle = (typeof message === STRING),
+ withMessage;
+ if (!withTitle) {
+ config = message;
+ message = title;
+ title = null;
+ }
+ withMessage = (typeof message === STRING);
+ if (!withMessage) {
+ // oops, just passed an object --> perhaps it is an error-object?
+ config = {};
+ message = (message && (message.message || ''));
+ }
+/*jshint expr:true */
+ config || (config={});
+/*jshint expr:false */
+ return {
+ title: title,
+ message: message,
+ config: config
+ };
+};
+
+/**
+ * Rearanges the 3 parameters that are passed through to many methods. Because some of the are optional.<br>
+ * Returns an object where you are sure that all properties are indeed those that the developer send through.
+ *
+ * @method _setupModelSyncListeners
+ * @param title {String} 1st parameter
+ * @param message {String} 2nd parameter
+ * @param config {Object} 3th parameter
+ * @private
+ * @return {Object} with properties: title, message and config
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype._setupModelSyncListeners = function() {
+ var instance = this,
+ eventhandlers = instance._eventhandlers;
+ eventhandlers.push(
+ Y.on(['*:load', '*:submit', '*:save', '*:destroy'], function(e) {
+ var model = e.target,
+ type = e.type,
+ options = e.options,
+ remove = options && (options.remove || options[DELETE]),
+ subtype = type.split(':')[1],
+ statushandle, defSyncMessages;
+ // cannot check Y.Model or Y.ModelList until we are sure the model-module is loaded
+ Y.usePromise(MODEL, MODEL+'-'+LIST, GALLERYITSAMODELSYNCPROMISE, GALLERYITSAMODELLISTSYNCPROMISE).then(
+ function() {
+ // model._itsaMessageViewer needs to be undefined, that means it has no target
+ if (((model instanceof Y.Model) || (model instanceof Y.ModelList)) && ((subtype!==DESTROY) || remove) && (!model._itsamessageListener)) {
+ // because multiple simultanious on-events will return only one after-event (is this an error?),
+ // we will take the promise's then() to remove the status lateron.
+ defSyncMessages = model._defSyncMessages;
+ statushandle = instance._showStatus(e.syncmessage || (defSyncMessages && defSyncMessages[subtype]) || Y.Intl.get(GALLERYITSAMODELSYNCPROMISE)[subtype], {source: MODELSYNC, busy: true});
+ e.promise.then(
+ function() {
+ instance._removeStatus(statushandle);
+ },
+ function() {
+ instance._removeStatus(statushandle);
+ }
+ );
+ }
+ }
+ );
+ })
+ );
+};
+
+/**
+ * Informs the user with a message and three buttons: 'abort', 'ignore', 'retry'.<br>
+ * The promise can resolve by either 'ignore' or 'retry' and will reject by 'abort'. Once resolved, look for result.button
+ * to find out which button the user pressed.<br>
+ * <b>Note:</b> You need a descendant of Y.ITSAMessageViewer (f.i. Y.ITSADialog) to make the message be displayed!
+ *
+ * @method _getRetryConfirmation
+ * @param [title] {String} The title of the message
+ * @param [message] {String} The message
+ * @param [config] {Object} Config passed through to the Y.ITSAMessage instance and the next additional properties:
+ * @param [config.closeButton] {Boolean} whether the closebutton should be visible.
+ * By setting this, you the default setting of closeButton is overruled.
+ * @param [config.icon] {String} Classname of the iconfont, for instance 'itsaicon-dialog-info' --> see gallerycss-itsa-base for more info about iconfonts.
+ * By setting this, you the default icon is overruled.
+ * @param [config.imageButtons] {Boolean} Whether to display imagebuttons.
+ * @param [config.level] {String} The message-level, should be either 'info', warn' or 'error'.
+ * @param [config.priority] {boolean} By setting this, the message will be positioned in the queue above messages that have no priority.
+ * @param [config.primaryButton] {String} Name of the primary button, f.i. 'btn_ok'.
+ * By setting this, you the default primaryButton ('btn_retry') is overruled.
+ * @param [config.source] {String} Identification of the source (sender) of the message, which is 'application' by default.
+ * @param [config.target] {Y.ITSAMessageViewer} MessageViewer-instance that is targeted and should handle the message.
+ * @param [config.timeoutReject] {Number} Timeout after which the message's visiblilty should be rejected
+ * @param [config.timeoutResolve] {Number} Timeout after which the message's visiblilty should be resolved
+ * @private
+ * @return {Y.Promise} Promise that holds the user-response. Check 'button' to find out what button was pressed.
+ * resolve(result) --> result.button==='ignore' || 'retry' OR reject(reason) --> reason==='abort' or error
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype[UNDERSCORE+GET_RETRY_CONFIRMATION] = function(title, message, config) {
+ return this._queueMessage(title, message, config, '{btn_abort}{btn_ignore}{btn_retry}', 'btn_retry', 'btn_abort', GET_RETRY_CONFIRMATION, WARN, ICON_WARN);
+};
+
+/**
+ * Informs the user with a message and two buttons: 'no' and 'yes'.<br>
+ * The promise can resolve by 'yes and will reject by 'no'.
+ * <b>Note:</b> You need a descendant of Y.ITSAMessageViewer (f.i. Y.ITSADialog) to make the message be displayed!
+ *
+ * @method _getConfirmation
+ * @param [title] {String} The title of the message
+ * @param [message] {String} The message
+ * @param [config] {Object} Config passed through to the Y.ITSAMessage instance and the next additional properties:
+ * @param [config.closeButton] {Boolean} whether the closebutton should be visible.
+ * By setting this, you the default setting of closeButton is overruled.
+ * @param [config.icon] {String} Classname of the iconfont, for instance 'itsaicon-dialog-info' --> see gallerycss-itsa-base for more info about iconfonts.
+ * By setting this, you the default icon is overruled.
+ * @param [config.imageButtons] {Boolean} Whether to display imagebuttons.
+ * @param [config.level] {String} The message-level, should be either 'info', warn' or 'error'.
+ * @param [config.priority] {boolean} By setting this, the message will be positioned in the queue above messages that have no priority.
+ * @param [config.primaryButton] {String} Name of the primary button, f.i. 'btn_ok'.
+ * By setting this, you the default primaryButton 'btn_yes' is overruled.
+ * @param [config.source] {String} Identification of the source (sender) of the message, which is 'application' by default.
+ * @param [config.target] {Y.ITSAMessageViewer} MessageViewer-instance that is targeted and should handle the message.
+ * @param [config.timeoutReject] {Number} Timeout after which the message's visiblilty should be rejected
+ * @param [config.timeoutResolve] {Number} Timeout after which the message's visiblilty should be resolved
+ * @private
+ * @return {Y.Promise} Promise that holds the user-response. Resolves by 'ok' and rejects by 'no'.
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype[UNDERSCORE+GET_CONFIRMATION] = function(title, message, config) {
+ return this._queueMessage(title, message, config, '{btn_no}{btn_yes}', 'btn_yes', 'btn_no', GET_CONFIRMATION, INFO, ICON_QUESTION);
+};
+
+/**
+ * Asks the user for an url.<br>
+ * <b>Note:</b> You need a descendant of Y.ITSAMessageViewer (f.i. Y.ITSADialog) to make the message be displayed!
+ *
+ * @method _getURL
+ * @param [title] {String} The title of the message
+ * @param [message] {String} The message
+ * @param [config] {Object} Config passed through to the Y.ITSAMessage instance and the next additional properties:
+ * @param [config.closeButton] {Boolean} whether the closebutton should be visible.
+ * By setting this, you the default setting of closeButton is overruled.
+ * @param [config.formconfig] {Object} Config that passes through to the UI-element. See Y.ITSAFormModel for usage of formconfig.
+ * @param [config.icon] {String} Classname of the iconfont, for instance 'itsaicon-dialog-info' --> see gallerycss-itsa-base for more info about iconfonts.
+ * By setting this, you the default icon is overruled.
+ * @param [config.imageButtons] {Boolean} Whether to display imagebuttons.
+ * @param [config.level] {String} The message-level, should be either 'info', warn' or 'error'.
+ * @param [config.priority] {boolean} By setting this, the message will be positioned in the queue above messages that have no priority.
+ * @param [config.primaryButton] {String} Name of the primary button, f.i. 'btn_ok'.
+ * By setting this, you the default primaryButton is overruled.
+ * @param [config.required] {Boolean} Makes the input required: the promise cannot be rejected, there is no cancel or close-button.
+ * @param [config.source] {String} Identification of the source (sender) of the message, which is 'application' by default.
+ * @param [config.target] {Y.ITSAMessageViewer} MessageViewer-instance that is targeted and should handle the message.
+ * @param [config.timeoutReject] {Number} Timeout after which the message's visiblilty should be rejected
+ * @param [config.timeoutResolve] {Number} Timeout after which the message's visiblilty should be resolved
+ * @param [config.validationerror] {String} Message that Y.Tipsy uses when validation fails.
+ * @param [config.validator] {Function} Validator function for the UI-element
+ * @param [config.value] {Any} Initial value that passes through to the UI-element.
+ * @private
+ * @return {Y.Promise} Promise that holds the user-response.
+ * resolve(result) --> result.input===the url OR reject(reason) --> reason==='cancel' or error
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype[UNDERSCORE+GET_URL] = function(title, message, config) {
+ var instance = this,
+ params = instance._retrieveParams(title, message, config),
+ newconfig = params.config;
+ newconfig.url = true;
+ return instance[UNDERSCORE+GET_INPUT](params.title, params.message, newconfig);
+};
+
+/**
+ * Asks the user for an emailaddress.<br>
+ * <b>Note:</b> You need a descendant of Y.ITSAMessageViewer (f.i. Y.ITSADialog) to make the message be displayed!
+ *
+ * @method _getEmail
+ * @param [title] {String} The title of the message
+ * @param [message] {String} The message
+ * @param [config] {Object} Config passed through to the Y.ITSAMessage instance and the next additional properties:
+ * @param [config.closeButton] {Boolean} whether the closebutton should be visible.
+ * By setting this, you the default setting of closeButton is overruled.
+ * @param [config.formconfig] {Object} Config that passes through to the UI-element. See Y.ITSAFormModel for usage of formconfig.
+ * @param [config.icon] {String} Classname of the iconfont, for instance 'itsaicon-dialog-info' --> see gallerycss-itsa-base for more info about iconfonts.
+ * By setting this, you the default icon is overruled.
+ * @param [config.imageButtons] {Boolean} Whether to display imagebuttons.
+ * @param [config.level] {String} The message-level, should be either 'info', warn' or 'error'.
+ * @param [config.priority] {boolean} By setting this, the message will be positioned in the queue above messages that have no priority.
+ * @param [config.primaryButton] {String} Name of the primary button, f.i. 'btn_ok'.
+ * By setting this, you the default primaryButton is overruled.
+ * @param [config.required] {Boolean} Makes the input required: the promise cannot be rejected, there is no cancel or close-button.
+ * @param [config.source] {String} Identification of the source (sender) of the message, which is 'application' by default.
+ * @param [config.target] {Y.ITSAMessageViewer} MessageViewer-instance that is targeted and should handle the message.
+ * @param [config.timeoutReject] {Number} Timeout after which the message's visiblilty should be rejected
+ * @param [config.timeoutResolve] {Number} Timeout after which the message's visiblilty should be resolved
+ * @param [config.validationerror] {String} Message that Y.Tipsy uses when validation fails.
+ * @param [config.validator] {Function} Validator function for the UI-element
+ * @param [config.value] {Any} Initial value that passes through to the UI-element.
+ * @private
+ * @return {Y.Promise} Promise that holds the user-response.
+ * resolve(result) --> result.input===the emailaddress OR reject(reason) --> reason==='cancel' or error
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype[UNDERSCORE+GET_EMAIL] = function(title, message, config) {
+ var instance = this,
+ params = instance._retrieveParams(title, message, config),
+ newconfig = params.config;
+ newconfig.email = true;
+ return instance[UNDERSCORE+GET_INPUT](params.title, params.message, newconfig);
+};
+
+/**
+ * Asks the user for any input.<br>
+ * <b>Note:</b> You need a descendant of Y.ITSAMessageViewer (f.i. Y.ITSADialog) to make the message be displayed!
+ *
+ * @method _getInput
+ * @param [title] {String} The title of the message
+ * @param [message] {String} The message
+ * @param [config] {Object} Config passed through to the Y.ITSAMessage instance and the next additional properties:
+ * @param [config.closeButton] {Boolean} whether the closebutton should be visible.
+ * By setting this, you the default setting of closeButton is overruled.
+ * @param [config.formconfig] {Object} Config that passes through to the UI-element. See Y.ITSAFormModel for usage of formconfig.
+ * @param [config.icon] {String} Classname of the iconfont, for instance 'itsaicon-dialog-info' --> see gallerycss-itsa-base for more info about iconfonts.
+ * By setting this, you the default icon is overruled.
+ * @param [config.imageButtons] {Boolean} Whether to display imagebuttons.
+ * @param [config.level] {String} The message-level, should be either 'info', warn' or 'error'.
+ * @param [config.priority] {boolean} By setting this, the message will be positioned in the queue above messages that have no priority.
+ * @param [config.primaryButton] {String} Name of the primary button, f.i. 'btn_ok'.
+ * By setting this, you the default primaryButton is overruled.
+ * @param [config.required] {Boolean} Makes the input required: the promise cannot be rejected, there is no cancel or close-button.
+ * @param [config.source] {String} Identification of the source (sender) of the message, which is 'application' by default.
+ * @param [config.target] {Y.ITSAMessageViewer} MessageViewer-instance that is targeted and should handle the message.
+ * @param [config.textarea] {Boolean} Render a textarea instead of an input-element.
+ * @param [config.timeoutReject] {Number} Timeout after which the message's visiblilty should be rejected
+ * @param [config.timeoutResolve] {Number} Timeout after which the message's visiblilty should be resolved
+ * @param [config.validationerror] {String} Message that Y.Tipsy uses when validation fails.
+ * @param [config.validator] {Function} Validator function for the UI-element
+ * @param [config.value] {Any} Initial value that passes through to the UI-element.
+ * @private
+ * @return {Y.Promise} Promise that holds the user-response.
+ * resolve(result) --> result.input===the input OR reject(reason) --> reason==='cancel' or error
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype[UNDERSCORE+GET_INPUT] = function(title, message, config) {
+ var instance = this,
+ params = instance._retrieveParams(title, message, config),
+ required, MyITSAMessage, email, url, formtype, formconfig;
+ title = params.title;
+ message = params.message;
+ config = params.config;
+ formconfig = config.formconfig || {};
+ formconfig.fullselect = true;
+ email = (typeof config.email === BOOLEAN) && config.email;
+ url = (typeof config.url === BOOLEAN) && config.url;
+ formconfig.primarybtnonenter = !config[TEXTAREA] || email || url;
+ formtype = email ? EMAIL : (url ? URL : (config[TEXTAREA] ? TEXTAREA : 'text'));
+ formconfig.classname = 'itsa-'+formtype + (formconfig.classname ? ' '+formconfig.classname : '');
+ required = (typeof config.required === BOOLEAN) && config.required;
+ formconfig.required = required;
+ return instance.isReady().then(
+ function() {
+/*jshint expr:true */
+ (config.email || config.url) && (config.validationerror || (config.validationerror=instance._intlMessageObj.translate('enterrightformat')));
+/*jshint expr:false */
+ MyITSAMessage = Y.Base.create('itsamessageinput', Y.ITSAMessage, [], null, {
+ ATTRS: {
+ input: {
+ value: config.value,
+ formtype: formtype,
+ formconfig: formconfig,
+ validator: config.validator,
+ validationerror: config.validationerror
+ }
+ }
+ });
+ message += '<fieldset class="'+'itsa-input'+'">'+
+ '<div class="pure-control-group">{input}</div>'+
+ '</fieldset>';
+ return instance._queueMessage(title, message, config, (required ? '' : '{btn_cancel}') + '{btn_ok}', 'btn_ok', (required ? null : 'btn_cancel'), GET_INPUT, INFO, ICON_INFO, null, null, MyITSAMessage);
+ }
+ );
+};
+
+/**
+ * Asks the user for a number.<br>
+ * <b>Note:</b> You need a descendant of Y.ITSAMessageViewer (f.i. Y.ITSADialog) to make the message be displayed!
+ *
+ * @method _getNumber
+ * @param [title] {String} The title of the message
+ * @param [message] {String} The message
+ * @param [config] {Object} Config passed through to the Y.ITSAMessage instance and the next additional properties:
+ * @param [config.closeButton] {Boolean} whether the closebutton should be visible.
+ * By setting this, you the default setting of closeButton is overruled.
+ * @param [config.formconfig] {Object} Config that passes through to the UI-element. See Y.ITSAFormModel for usage of formconfig.
+ * @param [config.icon] {String} Classname of the iconfont, for instance 'itsaicon-dialog-info' --> see gallerycss-itsa-base for more info about iconfonts.
+ * By setting this, you the default icon is overruled.
+ * @param [config.imageButtons] {Boolean} Whether to display imagebuttons.
+ * @param [config.level] {String} The message-level, should be either 'info', warn' or 'error'.
+ * @param [config.priority] {boolean} By setting this, the message will be positioned in the queue above messages that have no priority.
+ * @param [config.primaryButton] {String} Name of the primary button, f.i. 'btn_ok'.
+ * By setting this, you the default primaryButton is overruled.
+ * @param [config.required] {Boolean} Makes the input required: the promise cannot be rejected, there is no cancel or close-button.
+ * @param [config.source] {String} Identification of the source (sender) of the message, which is 'application' by default.
+ * @param [config.target] {Y.ITSAMessageViewer} MessageViewer-instance that is targeted and should handle the message.
+ * @param [config.timeoutReject] {Number} Timeout after which the message's visiblilty should be rejected
+ * @param [config.timeoutResolve] {Number} Timeout after which the message's visiblilty should be resolved
+ * @param [config.validationerror] {String} Message that Y.Tipsy uses when validation fails.
+ * @param [config.validator] {Function} Validator function for the UI-element
+ * @param [config.value] {Any} Initial value that passes through to the UI-element.
+ * @private
+ * @return {Y.Promise} Promise that holds the user-response.
+ * resolve(result) --> result.number===the number OR reject(reason) --> reason==='cancel' or error
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype[UNDERSCORE+GET_NUMBER] = function(title, message, config) {
+ var instance = this,
+ params = instance._retrieveParams(title, message, config),
+ required, MyITSAMessage, formconfig;
+ title = params.title;
+ message = params.message;
+ config = params.config;
+ formconfig = config.formconfig || {};
+ formconfig.fullselect = true;
+ formconfig.primarybtnonenter = true;
+ formconfig.classname = 'itsa-number' + (formconfig.classname ? ' '+formconfig.classname : '');
+ formconfig.required = true;
+ required = (typeof config.required === BOOLEAN) && config.required;
+ return instance.isReady().then(
+ function() {
+/*jshint expr:true */
+ config.validationerror || (config.validationerror=instance._intlMessageObj.translate('entervalidnumber'));
+/*jshint expr:false */
+ MyITSAMessage = Y.Base.create('itsamessagenumber', Y.ITSAMessage, [], null, {
+ ATTRS: {
+ number: {
+ value: config.value,
+ formtype: 'number',
+ formconfig: formconfig,
+ validator: config.validator,
+ validationerror: config.validationerror
+ }
+ }
+ });
+ message += '<fieldset class="'+'itsa-number'+'">'+
+ '<div class="pure-control-group">{number}</div>'+
+ '</fieldset>';
+ return instance._queueMessage(title, message, config, (required ? '' : '{btn_cancel}') + '{btn_ok}', 'btn_ok', (required ? null : 'btn_cancel'), GET_NUMBER, INFO, ICON_INFO, null, null, MyITSAMessage);
+ }
+ );
+};
+
+/**
+ * Removes a message (that was shown using Y.showStatus) from the MessageView - or queue.
+ *
+ * @method _removeStatus
+ * @param handle {Y.Promise} The returnvalue when Y.showStatus was called.
+ * @private
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype[UNDERSCORE+REMOVE_STATUS] = function(messageHandle) {
+ messageHandle.then(
+ function(itsamessage) {
+ itsamessage.resolve();
+ }
+ );
+};
+
+/**
+ * Shows a message.<br>
+ * <b>Note:</b> You need a descendant of Y.ITSAMessageViewer (f.i. Y.ITSADialog) to make the message be displayed!
+ *
+ * @method _showMessage
+ * @param [title] {String} The title of the message
+ * @param [message] {String} The message
+ * @param [config] {Object} Config passed through to the Y.ITSAMessage instance and the next additional properties:
+ * @param [config.closeButton] {Boolean} whether the closebutton should be visible.
+ * By setting this, you the default setting of closeButton is overruled.
+ * @param [config.icon] {String} Classname of the iconfont, for instance 'itsaicon-dialog-info' --> see gallerycss-itsa-base for more info about iconfonts.
+ * By setting this, you the default icon is overruled.
+ * @param [config.imageButtons] {Boolean} Whether to display imagebuttons.
+ * @param [config.level] {String} The message-level, should be either 'info', warn' or 'error'.
+ * @param [config.priority] {boolean} By setting this, the message will be positioned in the queue above messages that have no priority.
+ * @param [config.primaryButton] {String} Name of the primary button, f.i. 'btn_ok'.
+ * By setting this, you the default primaryButton is overruled.
+ * @param [config.source] {String} Identification of the source (sender) of the message, which is 'application' by default.
+ * @param [config.target] {Y.ITSAMessageViewer} MessageViewer-instance that is targeted and should handle the message.
+ * @param [config.timeoutReject] {Number} Timeout after which the message's visiblilty should be rejected
+ * @param [config.timeoutResolve] {Number} Timeout after which the message's visiblilty should be resolved
+ * @private
+ * @return {Y.Promise} Promise that holds the user-response. Resolved once the user presses the 'ok'-button.
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype[UNDERSCORE+SHOW_MESSAGE] = function(title, message, config) {
+ return this._queueMessage(title, message, config, '{btn_ok}', 'btn_ok', null, SHOW_MESSAGE, INFO, ICON_INFORM, false, true);
+};
+
+/**
+ * Shows a warning. Because the level will be 'warn', the message has precedence above normal messages.<br>
+ * <b>Note:</b> You need a descendant of Y.ITSAMessageViewer (f.i. Y.ITSADialog) to make the message be displayed!
+ *
+ * @method _showWarning
+ * @param [title] {String} The title of the message
+ * @param [message] {String} The message
+ * @param [config] {Object} Config passed through to the Y.ITSAMessage instance and the next additional properties:
+ * @param [config.closeButton] {Boolean} whether the closebutton should be visible.
+ * By setting this, you the default setting of closeButton is overruled.
+ * @param [config.icon] {String} Classname of the iconfont, for instance 'itsaicon-dialog-info' --> see gallerycss-itsa-base for more info about iconfonts.
+ * By setting this, you the default icon is overruled.
+ * @param [config.imageButtons] {Boolean} Whether to display imagebuttons.
+ * @param [config.level] {String} The message-level, should be either 'info', warn' or 'error'.
+ * @param [config.priority] {boolean} By setting this, the message will be positioned in the queue above messages that have no priority.
+ * @param [config.primaryButton] {String} Name of the primary button, f.i. 'btn_ok'.
+ * By setting this, you the default primaryButton is overruled.
+ * @param [config.source] {String} Identification of the source (sender) of the message, which is 'application' by default.
+ * @param [config.target] {Y.ITSAMessageViewer} MessageViewer-instance that is targeted and should handle the message.
+ * @param [config.timeoutReject] {Number} Timeout after which the message's visiblilty should be rejected
+ * @param [config.timeoutResolve] {Number} Timeout after which the message's visiblilty should be resolved
+ * @private
+ * @return {Y.Promise} Promise that holds the user-response. Resolved once the user presses the 'ok'-button.
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype[UNDERSCORE+SHOW_WARNING] = function(title, message, config) {
+ return this._queueMessage(title, message, config, '{btn_ok}', 'btn_ok', null, SHOW_WARNING, WARN, ICON_WARN, false, true);
+};
+
+/**
+ * Shows an error. Because the level will be 'error', the message has precedence above warnings and normal messages.<br>
+ * <b>Note:</b> You need a descendant of Y.ITSAMessageViewer (f.i. Y.ITSADialog) to make the message be displayed!
+ *
+ * @method _showError
+ * @param [title] {String} The title of the message
+ * @param [message] {String} The message
+ * @param [config] {Object} Config passed through to the Y.ITSAMessage instance and the next additional properties:
+ * @param [config.closeButton] {Boolean} whether the closebutton should be visible.
+ * By setting this, you the default setting of closeButton is overruled.
+ * @param [config.icon] {String} Classname of the iconfont, for instance 'itsaicon-dialog-info' --> see gallerycss-itsa-base for more info about iconfonts.
+ * By setting this, you the default icon is overruled.
+ * @param [config.imageButtons] {Boolean} Whether to display imagebuttons.
+ * @param [config.level] {String} The message-level, should be either 'info', warn' or 'error'.
+ * @param [config.priority] {boolean} By setting this, the message will be positioned in the queue above messages that have no priority.
+ * @param [config.primaryButton] {String} Name of the primary button, f.i. 'btn_ok'.
+ * By setting this, you the default primaryButton is overruled.
+ * @param [config.source] {String} Identification of the source (sender) of the message, which is 'application' by default.
+ * @param [config.target] {Y.ITSAMessageViewer} MessageViewer-instance that is targeted and should handle the message.
+ * @param [config.timeoutReject] {Number} Timeout after which the message's visiblilty should be rejected
+ * @param [config.timeoutResolve] {Number} Timeout after which the message's visiblilty should be resolved
+ * @private
+ * @return {Y.Promise} Promise that holds the user-response. Resolved once the user presses the 'ok'-button.
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype[UNDERSCORE+SHOW_ERROR] = function(title, message, config) {
+ return this._queueMessage(title, message, config, '{btn_ok}', 'btn_ok', null, SHOW_ERROR, ERROR, ICON_ERROR, false, true);
+};
+
+/**
+ * Returns a handle with reference to the ITSAMessage-instance. The message itself is NOT fullfilled yet!<br>
+ * Because there are no buttons to make it fullfilled, you <u>must fullfil manually</u> by calling removeStatus(handle)<br>
+ * <b>Note:</b> You need a descendant of Y.ITSAMessageViewer that has its property 'statusMessages' (f.i. Y.ITSADialog) to make the message be displayed!
+ *
+ * @method _showStatus
+ * @param message {String} The message
+ * @param [config] {Object} Config passed through to the Y.ITSAMessage instance and the next additional properties:
+ * @param [config.busy] {Boolean} set true to create a spinning icon in front of message.
+ * @param [config.closeButton] {Boolean} whether the closebutton should be visible.
+ * By setting this, you the default setting of closeButton is overruled.
+ * @param [config.icon] {String} Classname of the iconfont, for instance 'itsaicon-dialog-info' --> see gallerycss-itsa-base for more info about iconfonts.
+ * By setting this, you the default icon is overruled.
+ * @param [config.imageButtons] {Boolean} Whether to display imagebuttons.
+ * @param [config.level] {String} The message-level, should be either 'info', warn' or 'error'.
+ * @param [config.priority] {boolean} By setting this, the message will be positioned in the queue above messages that have no priority.
+ * @param [config.primaryButton] {String} Name of the primary button, f.i. 'btn_ok'.
+ * By setting this, you the default primaryButton is overruled.
+ * @param [config.source] {String} Identification of the source (sender) of the message, which is 'application' by default.
+ * @param [config.target] {Y.ITSAMessageViewer} MessageViewer-instance that is targeted and should handle the message.
+ * @param [config.timeout] {Number} Timeout after which the message should disappear (will actually make the messageinstance resolved)
+ * @private
+ * @return {Y.Promise} handle with reference to the message, needs to be removed manually by Y.removeStatus(handle).
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype[UNDERSCORE+SHOW_STATUS] = function(message, config) {
+ var instance = this;
+ message = (typeof message===STRING) ? message : '';
+/*jshint expr:true */
+ config || (config={});
+/*jshint expr:false */
+ return instance.isReady().then(
+ function() {
+ var itsamessage = new Y.ITSAMessage();
+ itsamessage.message = message;
+ itsamessage._simpleMessage = true;
+ itsamessage._statusMessage = true;
+ itsamessage.type = SHOW_STATUS;
+ itsamessage.level = INFO;
+ itsamessage.noButtons = true;
+ itsamessage.priority = config.priority;
+ itsamessage.timeoutResolve = config.timeout;
+ itsamessage.target = config.target;
+ itsamessage.source = config.source || APP;
+ itsamessage.messageType = config.busy ? SHOW_BUSY : SHOW_STATUS;
+ instance.queueMessage(itsamessage);
+ return itsamessage;
+ }
+ );
+};
+
+/**
+ * Fires the ERROR-event and -if not published yet- publish it broadcasted to Y.
+ * Because the error-event is broadcasted to Y, it can be catched by gallery-itsaerrorreporter.
+ *
+ * @method _lazyFireErrorEvent
+ * @param {Object} [facade] eventfacade.
+ * @private
+**/
+ITSAMessageControllerClass.prototype._lazyFireErrorEvent = function(facade) {
+ var instance = this;
+
+ // lazy publish
+ if (!instance._errorEvent) {
+ instance._errorEvent = instance.publish(ERROR, {
+ broadcast: 1
+ });
+ }
+ instance.fire(ERROR, facade);
+};
+
+/**
+ * Prevented defaultFn as a Promise. Cleans up the Y.ITSAMessage-instance and will not add it to the queue.
+ *
+ * @method _prevDefFn
+ * @param e {EventTarget}
+ * @param e.itsamessage {Y.ITSAMessage} Y.ITSAMessage-instance
+ * @private
+ * @return {Y.Promise} resolve promise
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype._prevDefFn = function(e) {
+ var itsamessage = e.itsamessage;
+ itsamessage._rejectPromise(new Error('queuemessage prevented'));
+ // need to return a Promise to continue the messageviewer
+ return new Y.Promise(function (resolve) {
+ itsamessage.detachAll();
+ itsamessage.destroy();
+ itsamessage = null;
+ resolve();
+ });
+};
+
+
+/**
+ * Prevented defaultFn as a Promise. Adds the Y.ITSAMessage-instane to the queue.
+ *
+ * @method _defQueueFn
+ * @param e {EventTarget}
+ * @param e.itsamessage {Y.ITSAMessage} Y.ITSAMessage-instance
+ * @private
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype._defQueueFn = function(e) {
+ var instance = this,
+ itsamessage = e.itsamessage,
+ queue = instance.queue;
+ queue.push(itsamessage);
+ return itsamessage._promise.then(
+ null,
+ function() {return true;} // fullfil promise
+ ).then(
+ function() {
+ var index = queue.indexOf(itsamessage);
+/*jshint expr:true */
+ (index>-1) && queue.splice(index, 1);
+/*jshint expr:false */
+ itsamessage.detachAll();
+ itsamessage.destroy();
+ itsamessage = null;
+ }
+ );
+};
+
+// define public methods:
+
+/**
+ * Creates an Y.ITSAMessage-instance and adds it to the queue.<br>
+ *
+ * @method _queueMessage
+ * @param [title] {String} The title of the message
+ * @param [message] {String} The message
+ * @param [config] {Object} Config passed through to the Y.ITSAMessage instance and the next additional properties:
+ * @param [config.closeButton] {Boolean} whether the closebutton should be visible.
+ * By setting this, you the default setting of closeButton is overruled.
+ * @param [config.icon] {String} Classname of the iconfont, for instance 'itsaicon-dialog-info' --> see gallerycss-itsa-base for more info about iconfonts.
+ * By setting this, you the default icon is overruled.
+ * @param [config.imageButtons] {Boolean} Whether to display imagebuttons.
+ * @param [config.level] {String} The message-level, should be either 'info', warn' or 'error'.
+ * @param [config.priority] {boolean} By setting this, the message will be positioned in the queue above messages that have no priority.
+ * @param [config.primaryButton] {String} Name of the primary button, f.i. 'btn_ok'.
+ * By setting this, you the default primaryButton is overruled.
+ * @param [config.source] {String} Identification of the source (sender) of the message, which is 'application' by default.
+ * @param [config.target] {Y.ITSAMessageViewer} MessageViewer-instance that is targeted and should handle the message.
+ * @param [config.timeoutReject] {Number} Timeout after which the message's visiblilty should be rejected
+ * @param [config.timeoutResolve] {Number} Timeout after which the message's visiblilty should be resolved
+ * @param [footer] {String} Footertemplate, typically something like: '{btn_cancel}{btn_ok}' be aware to use <u>brackets</u> to identify the UI-elements!
+ * @param [primaryButton] {String} Name of the primary button, f.i. 'btn_ok'.
+ * @param [rejectButton] {String} Name of the button that rejects the itsamessage-promie, f.i. 'btn_cancel'.
+ * @param [messageType] {String} Identification of the messagetype, which could be used by a Y.ITSAMessageViewer-instance.
+ * @param [level] {String} The message-level, should be either 'info', warn' or 'error'.
+ * @param [icon] {String} Classname of the iconfont, for instance 'itsaicon-dialog-info' --> see gallerycss-itsa-base for more info about iconfonts.
+ * @param [closeButton] {Boolean} whether the closebutton should be visible.
+ * @param [simpleMessage] {Boolean} whether the message is a simplemessage with only title+message.
+ * @param [ITSAMessageClass] {Y.ITSAMessage-Class} the class that is created, defaults to Y.ITSAMessage, but could be a descendant.
+ * @private
+ * @since 0.1
+*/
+ITSAMessageControllerClass.prototype._queueMessage = function(title, message, config, footer, primaryButton, rejectButton, messageType, level, icon, closeButton, simpleMessage, ITSAMessageClass) {
+ var instance = this,
+ params = instance._retrieveParams(title, message, config),
+ imageButtons, required, simpleMsg;
+ title = params.title;
+ message = params.message;
+ config = params.config;
+ imageButtons = (typeof config.imageButtons === BOOLEAN) && config.imageButtons;
+ simpleMsg = ((typeof config.simpleMessage === BOOLEAN) && config.simpleMessage) || ((typeof simpleMessage === BOOLEAN) && simpleMessage) || false;
+ required = ((typeof config.required === BOOLEAN) && config.required) || false;
+/*jshint expr:true */
+ if (imageButtons) {
+ footer = footer.replace(/\{btn_/g,'{imgbtn_');
+ primaryButton && (primaryButton=primaryButton.replace(/btn_/g,'imgbtn_'));
+ }
+/*jshint expr:false */
+ return instance.isReady().then(
+ function() {
+ var itsamessage = ITSAMessageClass ? (new ITSAMessageClass()) : (new Y.ITSAMessage());
+ itsamessage.title = title;
+ itsamessage.message = message;
+ itsamessage._config = config;
+ itsamessage._simpleMessage = simpleMsg;
+ itsamessage.footer = footer;
+ itsamessage.icon = config.icon || icon;
+ itsamessage.noAudio = config.noAudio || false;
+ itsamessage.closeButton = required ? false : (config.closeButton || closeButton);
+ itsamessage.priority = config.priority;
+ itsamessage.imageButtons = imageButtons;
+ itsamessage.primaryButton = config.primaryButton || primaryButton; // config.primaryButton should overrule primaryButton
+ itsamessage.rejectButton = rejectButton;
+ itsamessage.timeoutResolve = config.timeoutResolve;
+ itsamessage.timeoutReject = config.timeoutReject;
+ itsamessage.target = config.target;
+ itsamessage.level = config.level || level; // config.level should overrule the param level;
+ itsamessage.source = config.source || APP;
+ itsamessage.messageType = messageType;
+ return instance.queueMessage(itsamessage);
+ }
+ );
+};
+
+// define 1 global messagecontroller
+/*jshint expr:true */
+Y.Global.ITSAMessageController || (Y.Global.ITSAMessageController=new ITSAMessageControllerClass());
+/*jshint expr:false */
+Y.ITSAMessageController = Y.Global.ITSAMessageController;
+
+}, 'gallery-2014.01.10-22-44', {
+ "requires": [
+ "yui-base",
+ "oop",
+ "base-base",
+ "base-build",
+ "event-custom-complex",
+ "promise",
+ "event-custom-base",
+ "yui-later",
+ "gallery-itsamodulesloadedpromise"
+ ]
+});
View
7 src/gallery-itsamessagecontroller/HISTORY.md
@@ -0,0 +1,7 @@
+gallery-itsamessagecontroller
+========
+
+
+0.1 - 11-11-2013
+-----
+* Initial release
View
18 src/gallery-itsamessagecontroller/README.md
@@ -0,0 +1,18 @@
+gallery-itsamessagecontroller
+========
+
+
+Controller of the awesome ITSA-MVC-message system.
+
+
+Landing Page
+--------------
+[http://gallerydocs.itsasbreuk.nl/gallery-itsamessagecontroller](http://gallerydocs.itsasbreuk.nl/gallery-itsamessagecontroller/)
+
+
+License
+-------
+
+Copyright (c) 2013 [Its Asbreuk](http://http://itsasbreuk.nl)
+
+[YUI BSD License](http://developer.yahoo.com/yui/license.html)
View
10 src/gallery-itsamessagecontroller/build.json
@@ -0,0 +1,10 @@
+{
+ "name": "gallery-itsamessagecontroller",
+ "builds": {
+ "gallery-itsamessagecontroller": {
+ "jsfiles": [
+ "js/gallery-itsamessagecontroller.js"
+ ]
+ }
+ }
+}
View
21 src/gallery-itsamessagecontroller/docs/component.json
@@ -0,0 +1,21 @@
+{
+ "name" : "gallery-itsamessagecontroller",
+ "displayName": "Gallery: gallery-itsamessagecontroller",
+ "description": "Controller of the ITSA-MVC-message system.",
+ "author" : [ "itsasbreuk" ],
+ "use" : [ "gallery-itsamessagecontroller" ],
+
+ "tags": [ "gallery" ],
+
+ "examples": [
+ {
+ "name" : "dialog",
+ "displayName": "Add a message to the queue",
+ "description": "This example shows how to create an Y.ITSAMessage-instance and add it to the queue. It will be handled by Y.ITSADialog.",
+ "author" : [ "itsasbreuk" ],
+ "modules" : ["base-buils", "gallery-itsamessagecontroller", "gallery-itsadialog", "gallery-itsadialog", "gallery-itsacheckbox", "gallery-itsamessage"],
+ "tags" : ["gallery-itsamessagecontroller", "gallery-itsamessage"],
+ "hideTableOfContents": true
+ }
+ ]
+}
View
22 src/gallery-itsamessagecontroller/docs/dialog.mustache
@@ -0,0 +1,22 @@
+<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.3.0/pure-min.css">
+
+<div class="intro">
+ <p>
+ {{description}}
+ </p>
+</div>
+
+
+
+<h2>Code</h2>
+```
+<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.3.0/pure-min.css">
+
+{{>dialog-js}}
+```
+
+<script>
+{{>init-loaderconfig-js}}
+{{>loaderconfig-js}}
+{{>dialog-js}}
+</script>
View
138 src/gallery-itsamessagecontroller/docs/index.mustache
@@ -0,0 +1,138 @@
+{{>api-button}}
+<div class="intro">
+ <p>
+ {{description}}
+ </p>
+ <p>
+ Y.ITSAMessageController is the Controller of the <b>ITSA-MVC-message system</b>. By including this module, one Y.ITSAMessageController-instance is created that can be used accross the whole webapp, even with multiple YUI-instances.
+ </p>
+</div>
+
+{{>getting-started}}
+
+<h2>Description</h2>
+
+ <p>
+ Y.ITSAMessageController is the Controller of the <b>ITSA-MVC-message system</b> where messages of the type Y.ITSAMessage can be added and viewed by a subClass of Y.ITSAMessageViewer
+ </p>
+
+ <h3>the Controller</h3>
+ <p>
+ Y.ITSAMessageController takes care of the messages by an internal queue. All messages that are added, should be of the (sub)Class <a href="http://gallerydocs.itsasbreuk.nl/gallery-itsamessage/">Y.ITSAMessage</a>. Adding a message to the queue is done by calling Y.ITSAMessageController.queueMessage(yourMessage).
+ </p>
+ <p>
+ Behind the scenes, the controller has 3 queues at different levels: <code>info</code>, <code>warn</code> and <code>error</code>. In what queue the message resides, is determined by the property: <code>Y.ITSAMessage.level</code>. The different levels are important for the usage of the <a href="http://gallerydocs.itsasbreuk.nl/gallery-itsamessageviewer/">View</a>.
+ </p>
+
+ <h3>the Models</h3>
+ <p>
+ The Models that are added to the queue should be of the type <a href="http://gallerydocs.itsasbreuk.nl/gallery-itsamessage/">Y.ITSAMessage</a> or a subClass. See its documentation.
+ </p>
+
+ <h3>the View</h3>
+ <p>
+ The View should be done by a subClass of <a href="http://gallerydocs.itsasbreuk.nl/gallery-itsamessageviewer/">Y.ITSAMessageViewer</a>. Currently, there are 2 different Views available: <a href="http://gallerydocs.itsasbreuk.nl/gallery-itsadialog/">Y.ITSADialog</a> and <a href="http://gallerydocs.itsasbreuk.nl/gallery-itsastatusbar/">Y.ITSAStatusbar</a>.
+ </p>
+ <p>
+ The Views will handle the messages from the queue, one by one. If there gets a message in the queue that has a higher <code>Y.ITSAMessage.level</code> (warn>info, error>warn), then previous 'lower-level' messages get suspended and the higher message shows up. The lower-message will resurrect once the higher-message disapears. Inside the same level, messages can be given a priority by setting ITSAMessage.priority=true. This wil not result into suspension, but makes the message being placed in its own queue (info, warn or error) just above the last 'non-priority'-message.
+ </p>
+ <p>
+ <b>Note 1:</b> Views should be set up to target 'untargeted' messages of each separate level, or the messages should target the specific View. By default, Y.ITSAMessageController targets all levels of 'untargeted'-messages to Y.ITSADialog. More info about targeting: <a href="http://gallerydocs.itsasbreuk.nl/gallery-itsamessageviewer/">Y.ITSAMessageViewer</a>
+ <b>Note 2:</b> there is also the module <a href="http://gallerydocs.itsasbreuk.nl/gallery-itsamessage/">gallery-itsalogin</a>, which is not a messageviewer, but just introduces Y.getLogin() which can be viewed through Y.ITSADialog.
+ </p>
+
+<h2>Automatic destruction</h2>
+ <p>
+ The Y.ITSAMessage-instances need to be created by the developer, but are destroyed automaticly by <a href="http://gallerydocs.itsasbreuk.nl/gallery-itsamessagecontroller/">Y.ITSAMessageController</a> when they get out of the queue. So you just can add them to the queue and you're done. Just before they get destroyed, their attributes are passed through to the Y.ITSAMessageViewer-Promise, so you can use its Promise-callback safely.
+ </p>
+<h2>Usage</h2