📄 dialog.js
字号:
//<okClick : function () { this.saveData(); this.clear(); this.returnValue(true);},//> @method Dialog.applyClick()// Handle a click on the 'apply' button of this Dialog. // Default implementation is to call <code>saveData()</code>, but NOT close the Dialog.// @group buttons// @visibility external// @see type:DialogButtons//<applyClick: function () { this.saveData();},//> @method Dialog.yesClick()// Handle a click on the 'yes' button of this Dialog.// Default implementation is to return <code>true</code>.// Override to do something else// @group buttons// @visibility external// @see type:DialogButtons//<yesClick : function () { this.returnValue(true);},//> @method Dialog.noClick()// Handle a click on the 'no' button of this Dialog.// Default implementation is to return <code>false</code>.// Override to do something else.// @group buttons// @visibility external// @see type:DialogButtons//<noClick : function () { this.returnValue(false);}});//!<Deferred//// Default Dialogs that we create////> @groupDef Prompting// Objects / methods used for displaying prompts and warnings to the user via (possibly modal)// isc Dialog objects.// @treeLocation Client Reference/Control//<//> @classAttr Dialog.Prompt (object : dialog instance properties : A)//// The "Prompt" object on the dialog class is a singleton Dialog instance.// The Prompt is used to show text to the user in a modal fashion - it will expand to show // all the text that you put into it.// By default this Dialog has no end-user controls and is expected to be programmatically// dismissed.<br>// Common use-case: During server-interactions, the Prompt will be used to display a suitable // wait message, and suppress user input.<br><br>//// Notes:<br>// Because this is a singleton object, properties set on the Prompt directly will persist each// time it is shown.<br>// Developers should use the <code>showPrompt()</code> and <code>clearPrompt()</code> methods// to show and hide the prompt rather than manipulating the prompt directly.//// @group Prompting// @visibility external// @see classMethod:isc.showPrompt()// @see classMethod:isc.clearPrompt()//<isc.Dialog.Prompt = { ID:"isc_globalPrompt", _generated:true, width:400, height:90, autoDraw:false, autoSize:true, isModal:true, autoCenter:true, showHeader:false, showFooter:false, showToolbar:false, dismissOnEscape:false, bodyStyle:"promptBody", // no border-top, since there is no header // TODO autogenerate border in Window based on header visibility message:"Loading...", blurbDefaults : { width:390, align:isc.Canvas.CENTER, valign:isc.Canvas.CENTER }, layoutMargin:0, //> @method Prompt.showMessage() // Show a message in the Dialog // // Dialog will redraw and resize to show the entire message // any properties in attributes will get applied and may be visibily changed // // @param newMessage (string) message to display // @param attributes (object) object of name:value pairs to apply to the object // properties are applied before the redraw //< showMessage : function (newMessage, properties) { // first add the properties specified this.setProperties(properties); this.message = newMessage; // Note: we lazily create children on draw, so verify that the items have been // initialized before manipulating the label if (!this._isInitialized) this.createChildren(); // add a label this.addAutoChild("blurb", null, isc.Label, this.body); this.blurb.setContents(this.message); this.show(); }, // clear the prompt message -- just clear the prompt clearMessage : function () { this.clear(); }, // If the prompt gets destroyed, remove the pointer to it. destroy : function () { isc.Dialog.Prompt = this._originalProperties; return this.Super("destroy", arguments); }};//> @classMethod isc.showPrompt()//// Method available on the isc object to show a modal prompt to the user.// This method will display the message using the Dialog.Prompt singleton object.<br>// Note: if this prompt is to be shown to the user during some slow JavaScript logic, we // advise calling this method, then using +link{Class.delayCall()} or +link{Timer.setTimeout}// to kick off the slow logic in a separate thread. This ensures that the prompt is showing// before the lengthy execution begins.// //// @param message (string) message to display// @param [properties] (object) additional properties for the Dialog, applied before// the Dialog is shown//// @visibility external// @see Dialog.Prompt// @group Prompting//<isc.addGlobal("showPrompt", function (message, properties) { var prompt = isc.Dialog.Prompt; if (!isc.isA.Dialog(prompt)) { var props = prompt; prompt = isc.Dialog.Prompt = isc.Dialog.create(prompt); // If we destroy() the prompt, this allows us to essentially 'reset' ourselves to a // state where calling this method again will create a new prompt from the original // set of properties. prompt._originalProperties = props; } isc.Dialog.Prompt.showMessage(message, properties);});//> @classMethod isc.clearPrompt()//// Clear the modal prompt being shown to the user.//// @group Prompting// @visibility external// @see Dialog.Prompt//<isc.addGlobal("clearPrompt", function () { if (!isc.isA.Dialog(isc.Dialog.Prompt)) return; // prompt has never been shown isc.Dialog.Prompt.clearMessage();});//////////////////////////////////////////////////////////////////////////////////////////////> @classAttr Dialog.Warn (object : dialog instance properties : A)//// A singleton Dialog instance that will show text to the user and provide buttons for their// response. The Dialog will expand to show all the text that you put into it.<br>// This can be used in cases where a developer would alternatively make use of the native// JavaScript <code>alert()</code> and <code>confirm()</code> methods. The main differences// between those methods and using the Warn object are:<br>// - The Warn object can be customized by modifying which buttons are visible, the style // applied to it, etc.<br>// - The <code>isc.ask()</code> and <code>isc.warn()</code> methods are asynchronous - rather // than returning a value indicating the user's response, a callback method will be fired// when the user interacts with the dialog.<br><br>//// Notes:<br>// Because this is a singleton object, properties set on the Warn object directly will persist // each time it is shown.<br>// Developers should use the <code>warn()</code> or <code>ask()</code> methods to show and// hide this object rather than manipulating the Dialog directly.// @group Prompting// @visibility external// @see classMethod:isc.warn()// @see classMethod:isc.ask()//<isc.Dialog.Warn = { ID:"isc_globalWarn", _generated:true, width:400, height:60, isModal:true, canDragReposition:true, keepInParentRect:true, autoDraw:false, autoSize:true, autoCenter:true, toolbarButtons:[isc.Dialog.OK], message:"Your message here!", contentLayout:"horizontal", autoChildParentMap : isc.addProperties({}, isc.Window.getInstanceProperty("autoChildParentMap"), { stack : "body", iconImg : "body", blurb : "stack", toolbar : "stack" }), stackDefaults : { height:1 }, bodyDefaults: isc.addProperties({}, isc.Window.getInstanceProperty("bodyDefaults"), { layoutMargin:15, membersMargin:10 }), toolbarDefaults : isc.addProperties({}, isc.Window.getInstanceProperty("toolbarDefaults"), { width:20, layoutAlign:"center" }), iconImgDefaults : { width:32, height:32 }, createChildren : function () { // HACK: prevent toolbar from being created, since we want it placed in "stack", which // we can't create until Super.createChildren() creates the "body", which is "stack"'s // parent. this.showToolbar = false; this.Super("createChildren"); this.addAutoChild("iconImg", null, isc.Img); this.addAutoChild("stack", null, isc.VStack); this.addAutoChild("blurb", {height:10}, isc.Label); this.showToolbar = true; this.makeToolbar(); // can't be done via defaults because policy and direction are dynamically determined this.body.hPolicy = "fill"; }, //> @method Warn.showMessage() // Show a message in the Dialog // // Dialog will redraw and resize to show the entire message // any properties in attributes will get applied and may be visibily changed // // @param newMessage (string) message to display // @param attributes (object) object of name:value pairs to apply to the object // properties are applied before the redraw //< showMessage : function (newMessage, properties) { this.message = newMessage; // first add the properties specified (NOTE: this will rebuild buttons, due to the // setButtons setter) this.setProperties(properties); // if no callback was specified, clear the Dialog callback if (properties.callback == null) delete this.callback; // Note: we lazily create children on draw, so verify that the items have been // initialized before manipulating the label if (!this._isInitialized) this.createChildren(); // Update the label in the body this.blurb.setContents(this.message); if (this.icon) { this.iconImg.setSrc(this.getImgURL(this.icon)); this.iconImg.show(); } else this.iconImg.hide(); // do immediate relayout so we don't wait for timers before we draw the new buttons, // especially because the destroy is immediate but the new draw is delayed, and in the // interim things react to the empty toolbar. this.toolbar.layoutChildren(); // since we're going to try to autoCenter on show(), we go ahead and get all relayout // done now if (this.blurb.isDirty()) this.blurb.redraw(); if (this.isDrawn()) { this.stack.layoutChildren(); this.body.layoutChildren(); this.layoutChildren(); } this.show(); // focus in the first button so you can hit Enter to do the default thing if (this.toolbar) { var firstButton = this.toolbar.getMember(0); /* this.logWarn("focusing on first button: " + firstButton + ", drawn: " + firstButton.isDrawn() + ", disabled: " + firstButton.isDisabled() + ", visible: " + firstButton.isVisible() + ", canFocus: " + firstButton._canFocus()); */ firstButton.focus(); } }};//> @classMethod isc.showMessage()// Show a modal dialog with a message, icon, and response buttons.//<isc.addGlobal("showMessage", function (message, messageType, callback, properties) { if ((isc.isA.String(properties) || isc.isA.Function(properties)) || (properties == null && isc.isAn.Object(callback) && callback.methodName == null && callback.action == null && callback.method == null)) { // swap arguments var realCallback = properties; properties = callback; callback = realCallback; } if (!isc.isA.Dialog(isc.Dialog.Warn)) isc.Dialog.Warn = isc.Dialog.create(isc.Dialog.Warn); if (!properties) properties = {}; // messageType is one of // "confirm" (confirm dialog) // "ask" (ask dialog) // "say", "warn" (info / warn dialog) if (!properties.buttons) { if (messageType == "confirm") { properties.buttons = [isc.Dialog.OK, isc.Dialog.CANCEL]; } else if (messageType == "ask") { properties.buttons = [isc.Dialog.YES, isc.Dialog.NO]; } else { properties.buttons = [isc.Dialog.OK]; } } // Title: If specified in properties, respect it, otherwise show the // appropriate default title based on the dialog type if (!properties.title) { if (messageType == "confirm") properties.title = isc.Dialog.CONFIRM_TITLE; else if (messageType == "ask") properties.title = isc.Dialog.ASK_TITLE; else if (messageType == "warn") properties.title = isc.Dialog.WARN_TITLE; else properties.title = isc.Dialog.SAY_TITLE; } isc._applyDialogHandlers(properties); if (!properties.icon) properties.icon = isc.Dialog.getInstanceProperty(messageType+"Icon"); if (callback) properties.callback = callback; isc.Dialog.Warn.showMessage(message, properties);});// shared with askForValue()isc._applyDialogHandlers = function (properties) { var defaultHandlers = this._defaultHandlers = this._defaultHandlers || ["okClick", "yesClick", "noClick", "cancelClick", "closeClick", "applyClick"]; for (var i = 0; i < defaultHandlers.length; i++) { var handlerName = defaultHandlers[i]; if (!properties[handlerName]) { properties[handlerName] = isc.Dialog.getInstanceProperty(handlerName); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -