File size: 10,254 Bytes
4b876a7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | /*!
* UI development toolkit for HTML5 (OpenUI5)
* (c) Copyright 2009-2016 SAP SE or an SAP affiliate company.
* Licensed under the Apache License, Version 2.0 - see LICENSE.txt.
*/
// Provides control sap.ui.commons.Message.
sap.ui.define(['jquery.sap.global', './Dialog', './library', 'sap/ui/core/Control'],
function(jQuery, Dialog, library, Control) {
"use strict";
/**
* Constructor for a new Message.
*
* @param {string} [sId] id for the new control, generated automatically if no id is given
* @param {object} [mSettings] initial settings for the new control
*
* @class
* Creates the "Message"s to be supplied to the "MessageBar" Control.
* @extends sap.ui.core.Control
* @version 1.38.4
*
* @constructor
* @public
* @deprecated Since version 1.4.0.
* A new messaging concept will be created in future. Therefore this control might be removed in one of the next versions.
* @alias sap.ui.commons.Message
* @ui5-metamodel This control/element also will be described in the UI5 (legacy) designtime metamodel
*/
var Message = Control.extend("sap.ui.commons.Message", /** @lends sap.ui.commons.Message.prototype */ { metadata : {
deprecated : true,
library : "sap.ui.commons",
properties : {
/**
* "Success", or "Warning", or "Error" messages. (Mandatory)
*/
type : {type : "sap.ui.commons.MessageType", group : "Behavior", defaultValue : null},
/**
* Message short text. (Mandatory)
*/
text : {type : "string", group : "Data", defaultValue : null},
/**
* Associated UI element ID. (Optional)
* For navigation to error field.
*/
associatedElementId : {type : "string", group : "Data", defaultValue : null},
/**
* Internal attribute, used to force the display of the "short" or the "long" text only.
*/
design : {type : "string", group : "Misc", defaultValue : null}
}
}});
Message.prototype.init = function(){
// Defining some private data...
this.isRTL = sap.ui.getCore().getConfiguration().getRTL();
// The "Details" related Controls.
this.fnCallBack = null; // Supplied only if a longText is to be provided on demand.
this.oLink = null; // Created only if a longText exists. This is the link opening the Details Dialog.
this.oContainer = null; // Created only if a longText exists. This is the "Dialog" hosting the Details.
this.oDetails = null; // Created only if a longText exists. This is the Controller rendering the Details.
this.oBtnOK = null; // Created only if a longText exists. This is the OK button found within the Dialog.
};
/**
* Destroys this Control instance, called by Element#destroy()
* @private
*/
Message.prototype.exit = function() {
if (this.oLink) {
this.oLink.destroy();
this.oLink = null;
}
if (this.oDetails) {
this.oDetails.destroy();
this.oDetails = null;
}
if (this.oContainer) {
this.oContainer.destroy();
this.oContainer = null;
}
if (this.oBtnOK) {
this.oBtnOK.destroy();
this.oBtnOK = null;
}
};
// #############################################################################
// Internal Utilities
// #############################################################################
/**
* This utility is for closing the Message Details from its OK button.
* @private
*/
Message.closeDetails = function(oControlEvent) {
oControlEvent.getSource().getParent().close();
};
/**
* This utility closes THIS Message's Details.
* @private
*/
Message.prototype.closeDetails = function() {
// If Details have been opened, can attempt to close them:
if (this.oContainer) {
this.oContainer.close();
}
};
/**
* This utility renders the Message Details.
* Current Specifications are those of JPaaS:
* Supported by: "Dialog" "MessageBox"
* - Title: Yes Yes
* - Non-blocking: Yes, configurable. No, modal only
* - Accepts HTML string: Yes, via oContent. No, sMessage only
* - Bottom-Right resize handle: Yes No
* - No icon: Yes Possible
* @private
*/
Message.prototype.openDetails = function() {
if (!this.oContainer) {
var rb = sap.ui.getCore().getLibraryResourceBundle("sap.ui.commons");
var OK = rb.getText("MSGBAR_DETAILS_DIALOG_CLOSE");
var title = rb.getText("MSGBAR_DETAILS_DIALOG_TITLE");
// Reading the HTML details as is, styles included:
var htmlDetails = this.fnCallBack(this.getId());
this.oDetails = new Message({type: this.getType(), text: htmlDetails});
this.oBtnOK = new sap.ui.commons.Button({text: OK, press:Message.closeDetails});
this.oContainer = new Dialog();
this.oContainer.addContent(this.oDetails);
this.oContainer.setTitle(title);
this.oContainer.addButton(this.oBtnOK);
//this.oContainer.setDefaultButton(this.oBtnOK); // Already the default since the only button...
}
// Other visible Dialogs around?
var sContainerId = this.oContainer.getId();
var iOthersMaxZIndex = 0;
var oOtherOpenDialogs = jQuery('.sapUiDlg');
for (var i = oOtherOpenDialogs.length - 1; i >= 0; i--) {
if (jQuery(oOtherOpenDialogs[i]).css('visibility') != "visible") {
oOtherOpenDialogs.splice(i, 1);
} else if (oOtherOpenDialogs[i].id == sContainerId) {
oOtherOpenDialogs.splice(i, 1);
} else {
iOthersMaxZIndex = Math.max(iOthersMaxZIndex,jQuery(oOtherOpenDialogs[i]).css('zIndex'));
}
}
// Taking note for later:
var bWasOpen = this.oContainer.isOpen();
// No matter what, we have to open the new Details, so:
this.oContainer.open();
// jQuery version of our OPEN Dialog Container:
var jContainer = this.oContainer.$();
// Starting a new Stack in the default Dialog's location:
var jContainerRect = jContainer.rect(); // For Height and Width...
if (oOtherOpenDialogs.length == 0) {
// "offsets.right" & "offsets.left" should be identical as plain Dialogs are centered,
// but in case there is a bug (like in Safari RTL):
if (this.isRTL) {
// Will be using "left" invariably for RTL or LTR:
jContainerRect.left = Number(jContainer.css('right').replace("px", ""));
}
this.setLastOffsets(jContainerRect);
// Nothing else to do:
return;
}
// Dialog limitation. Work-around:
if (bWasOpen) {
if (iOthersMaxZIndex > jContainer.css('zIndex')) {
// zIndex not raised via previous re-open()...
// Have to raise it ourselves.
jContainer.css('zIndex',iOthersMaxZIndex + 1);
}
// Nothing else to do:
return;
}
//*************** Stacking process starts ***************
// 1st rendering the new Dialog on top of the old one...
var oNextOffsets = this.getNextOffsets();
jContainer.css('top', (oNextOffsets.top - Message.TOP_INCR ) + "px");
if (this.isRTL) {
jContainer.css('right', (oNextOffsets.left - Message.LEFT_INCR) + "px");
} else {
jContainer.css('left', (oNextOffsets.left - Message.LEFT_INCR) + "px");
}
// Figuring what should the next coordinates be:
var jContainerRect = jContainer.rect(); // For Height and Width...
var scrollTop = jQuery(window).scrollTop();
var scrollLeft = jQuery(window).scrollLeft(); // Negative in RTL
var scrollRight = -scrollLeft;
// Checking if the new coordinates fit within the window:
if ((jQuery(window).height() + scrollTop) < (oNextOffsets.top + jContainerRect.height)) {
// ReStacking from the top:
oNextOffsets.top = scrollTop;
this.setLastOffsets(oNextOffsets);
}
if (this.isRTL) {
if ((jQuery(window).width() + scrollRight) < (oNextOffsets.left + jContainerRect.width)) {
// ReStacking from the right:
oNextOffsets.left = scrollRight;
this.setLastOffsets(oNextOffsets);
}
// Animating the Dialog to its new offset position:
jContainer.animate({top:oNextOffsets.top + "px", right:oNextOffsets.left + "px"}, 200);
} else {
if ((jQuery(window).width() + scrollLeft) < (oNextOffsets.left + jContainerRect.width)) {
// ReStacking from the left:
oNextOffsets.left = scrollLeft;
this.setLastOffsets(oNextOffsets);
}
// Animating the Dialog to its new offset position:
jContainer.animate({top:oNextOffsets.top + "px", left:oNextOffsets.left + "px"}, 200);
}
//MESSAGEBOX BACKUP: Issues: Only Modal, Doesn't accept HTML string, No Resize-Area.
// var rb = sap.ui.getCore().getLibraryResourceBundle("sap.ui.commons");
// var ICON = this.getType().toUpperCase(); // ERROR, WARNING, ...
// var title = rb.getText("MSGTYPE_" + ICON);
// var text = this.getLongText();
// sap.ui.commons.MessageBox.show(text, ICON, title);
};
Message.TOP_INCR = 20;
Message.LEFT_INCR = 10;
// Begin of Dialog-Offsets-Stacking facilities
(function() {
var oLastOffsets = null;
/**
* @static
*/
Message.setLastOffsets = function(oOffsets){
oLastOffsets = oOffsets;
};
Message.prototype.setLastOffsets = function(oOffsets){
Message.setLastOffsets(oOffsets);
};
Message.getNextOffsets = function(){
oLastOffsets.top += Message.TOP_INCR;
oLastOffsets.left += Message.LEFT_INCR;
return oLastOffsets;
};
Message.prototype.getNextOffsets = function(){
return Message.getNextOffsets();
};
}());
// End of Dialog-Offsets-Stacking facilities
// #############################################################################
// Public APIs
// #############################################################################
/**
* Registers a callback function to be invoked if long text Details are to be made available.
*
* This callback function will be supplied the corresponding Message "id", and should
* return the (simple) HTML string to be displayed within the Message Details Dialog.
*
* E.g.: myMessage.bindDetails(getDetails);
* function getDetails(sId) {... return htmlString;}
*
* @param {function} fnCallBack the callback function
* @ui5-metamodel This method also will be described in the UI5 (legacy) designtime metamodel
* @public
*/
Message.prototype.bindDetails = function(fnCallBack) {
this.fnCallBack = fnCallBack;
};
return Message;
}, /* bExport= */ true);
|