зеркало из https://github.com/mozilla/pjs.git
Bug 374404 - Don't ship WidgetStateManager as part of toolkit/mailr=bsmedberg
This commit is contained in:
Родитель
1c7340a2a7
Коммит
0b1d9b96a9
|
@ -32,7 +32,6 @@ toolkit.jar:
|
|||
*+ content/global/inlineSpellCheckUI.js (inlineSpellCheckUI.js)
|
||||
+ content/global/mozilla.xhtml (mozilla.xhtml)
|
||||
*+ content/global/nsDragAndDrop.js (nsDragAndDrop.js)
|
||||
*+ content/global/nsWidgetStateManager.js (nsWidgetStateManager.js)
|
||||
+ content/global/selectDialog.js (selectDialog.js)
|
||||
+ content/global/selectDialog.xul (selectDialog.xul)
|
||||
*+ content/global/viewZoomOverlay.js (viewZoomOverlay.js)
|
||||
|
|
|
@ -1,399 +0,0 @@
|
|||
# -*- Mode: Java; tab-width: 2; c-basic-offset: 2; -*-
|
||||
#
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public License Version
|
||||
# 1.1 (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
# http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
# for the specific language governing rights and limitations under the
|
||||
# License.
|
||||
#
|
||||
# The Original Code is mozilla.org Code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is
|
||||
# Netscape Communications Corporation.
|
||||
# Portions created by the Initial Developer are Copyright (C) 1998
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Ben Goodger <mozilla@bengoodger.com> (Original Author)
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
# of those above. If you wish to allow use of your version of this file only
|
||||
# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
# use your version of this file under the terms of the MPL, indicate your
|
||||
# decision by deleting the provisions above and replace them with the notice
|
||||
# and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this file under
|
||||
# the terms of any one of the MPL, the GPL or the LGPL.
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
|
||||
# ... and so it came to pass that on the 4th day of June, A.D. 2003, this file
|
||||
# was excised of the cruel and unfortunate brace/indentation scheme perpetrated
|
||||
# upon it by the same author who now writes these words, some three years and
|
||||
# two months after the original act. Note that while cvs blame shifts like leaves
|
||||
# in the autumn breeze, by and large the responsibility for this code remains
|
||||
# with me.
|
||||
|
||||
var wsm;
|
||||
|
||||
// For panels displayed inside the main dialog, this value will be the child iframe
|
||||
// window. For panels displayed in sub-dialogs, those launched by panels of the main
|
||||
// dialog, this will be the sub dialog window.
|
||||
var gCurrentWindow = null;
|
||||
|
||||
function nsWidgetStateManager (aFrameID)
|
||||
{
|
||||
|
||||
this.dataManager = {
|
||||
/** Persisted Data Hash Table
|
||||
* Page_ID -> Element_ID -> Property -> Value
|
||||
**/
|
||||
pageData: { },
|
||||
|
||||
setPageData: function (aPageTag, aDataObject)
|
||||
{
|
||||
this.pageData[aPageTag] = aDataObject;
|
||||
},
|
||||
|
||||
getPageData: function (aPageTag)
|
||||
{
|
||||
if (!(aPageTag in this.pageData))
|
||||
this.pageData[aPageTag] = { };
|
||||
|
||||
if (!('elementIDs' in this.pageData[aPageTag]))
|
||||
this.pageData[aPageTag].elementIDs = new Object();
|
||||
|
||||
if (!('userData' in this.pageData[aPageTag]))
|
||||
this.pageData[aPageTag].userData = new Object();
|
||||
|
||||
return this.pageData[aPageTag];
|
||||
},
|
||||
|
||||
setItemData: function (aPageTag, aItemID, aDataObject)
|
||||
{
|
||||
if (!(aPageTag in this.pageData))
|
||||
this.pageData[aPageTag] = new Object();
|
||||
|
||||
this.pageData[aPageTag].elementIDs[aItemID] = aDataObject;
|
||||
},
|
||||
|
||||
getItemData: function (aPageTag, aItemID)
|
||||
{
|
||||
if (!(aItemID in this.pageData[aPageTag].elementIDs))
|
||||
this.pageData[aPageTag].elementIDs[aItemID] = new Object();
|
||||
return this.pageData[aPageTag].elementIDs[aItemID];
|
||||
}
|
||||
}
|
||||
|
||||
this.contentID = aFrameID;
|
||||
|
||||
wsm = this;
|
||||
|
||||
/** Element Handlers
|
||||
* Provides default get and set handler functions for supported
|
||||
* widgets. Clients can override or add new widgets.
|
||||
**/
|
||||
this.handlers = {
|
||||
menulist:
|
||||
{ get: wsm.get_Menulist, set: wsm.set_Menulist },
|
||||
radiogroup:
|
||||
{ get: wsm.get_Radiogroup, set: wsm.set_Radiogroup },
|
||||
checkbox:
|
||||
{ get: wsm.get_Checkbox, set: wsm.set_Checkbox },
|
||||
textbox:
|
||||
{ get: wsm.get_Textbox, set: wsm.set_Textbox },
|
||||
listitem:
|
||||
{ get: wsm.get_Listitem, set: wsm.set_Listitem },
|
||||
data:
|
||||
{ get: wsm.get_Data, set: wsm.set_Data },
|
||||
default_handler:
|
||||
{ get: wsm.get_Default, set: wsm.set_Default }
|
||||
}
|
||||
|
||||
// extra attributes to scan and save.
|
||||
this.attributes = [];
|
||||
}
|
||||
|
||||
nsWidgetStateManager.prototype =
|
||||
{
|
||||
get contentArea ()
|
||||
{
|
||||
return window.frames[this.contentID];
|
||||
},
|
||||
|
||||
savePageData: function (aPageTag, aWindow)
|
||||
{
|
||||
gCurrentWindow = aWindow || this.contentArea;
|
||||
|
||||
if (!(aPageTag in this.dataManager.pageData))
|
||||
return;
|
||||
|
||||
if ("GetFields" in gCurrentWindow) {
|
||||
// save page data based on user supplied function in content area
|
||||
var dataObject = gCurrentWindow.GetFields();
|
||||
if (dataObject)
|
||||
this.dataManager.pageData[aPageTag].userData = dataObject;
|
||||
}
|
||||
|
||||
// Automatic element retrieval. This is done in two ways.
|
||||
// 1) if an element id array is present in the document, this is
|
||||
// used to build a list of elements to persist. <-- performant
|
||||
// 2) otherwise, all elements with "wsm_persist" set to true
|
||||
// are persisted <-- non-performant.
|
||||
var elements;
|
||||
if ("_elementIDs" in gCurrentWindow) {
|
||||
elements = [];
|
||||
for (var i = 0; i < gCurrentWindow._elementIDs.length; i++) {
|
||||
var elt = gCurrentWindow.document.getElementById(gCurrentWindow._elementIDs[i]);
|
||||
if (elt)
|
||||
elements[elements.length] = elt;
|
||||
else {
|
||||
// see bug #40329. People forget this too often, and it breaks Prefs
|
||||
dump("*** FIX ME: '_elementIDs' in '" + gCurrentWindow.location.href.split('/').pop() +
|
||||
"' contains a reference to a non-existent element ID '" +
|
||||
gCurrentWindow._elementIDs[i] + "'.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
elements = gCurrentWindow.document.getElementsByAttribute("wsm_persist", "true");
|
||||
|
||||
for (var ii = 0; ii < elements.length; ii++) {
|
||||
var elementID = elements[ii].id;
|
||||
var elementType = elements[ii].localName;
|
||||
|
||||
// persist attributes
|
||||
var get_Func = (elementType in this.handlers) ?
|
||||
this.handlers[elementType].get :
|
||||
this.handlers.default_handler.get;
|
||||
this.dataManager.setItemData(aPageTag, elementID, get_Func(elementID));
|
||||
}
|
||||
},
|
||||
|
||||
setPageData: function (aPageTag, aWindow)
|
||||
{
|
||||
gCurrentWindow = aWindow || this.contentArea;
|
||||
|
||||
var pageData = this.dataManager.getPageData(aPageTag);
|
||||
if ("SetFields" in gCurrentWindow)
|
||||
gCurrentWindow.SetFields(pageData.userData)
|
||||
|
||||
if (!('elementIDs' in pageData))
|
||||
return;
|
||||
|
||||
for (var elementID in pageData.elementIDs) {
|
||||
var element = gCurrentWindow.document.getElementById(elementID);
|
||||
if (element) {
|
||||
var elementType = element.localName;
|
||||
var set_Func = (elementType in this.handlers) ?
|
||||
this.handlers[elementType].set :
|
||||
this.handlers.default_handler.set;
|
||||
set_Func(elementID, pageData.elementIDs[elementID]);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
/** Widget Get/Set Function Implementations
|
||||
* These can be overridden by the client.
|
||||
**/
|
||||
generic_Set: function (aElement, aDataObject)
|
||||
{
|
||||
if (aElement) {
|
||||
for (var property in aDataObject) {
|
||||
if (property == "localname")
|
||||
continue;
|
||||
if (!aDataObject[property] && typeof aDataObject[property] == "boolean")
|
||||
aElement.removeAttribute(property);
|
||||
else
|
||||
aElement.setAttribute(property, aDataObject[property]);
|
||||
}
|
||||
|
||||
if (!aElement.getAttribute("disabled","true"))
|
||||
aElement.removeAttribute("disabled");
|
||||
}
|
||||
},
|
||||
|
||||
generic_Get: function (aElement)
|
||||
{
|
||||
if (aElement) {
|
||||
var dataObject = new Object();
|
||||
var wsmAttributes = aElement.getAttribute("wsm_attributes");
|
||||
var attributes = wsm.attributes; // make a copy
|
||||
if (wsmAttributes != "")
|
||||
attributes.push(wsmAttributes.split(" ")); // modify the copy
|
||||
|
||||
for (var i = 0; i < attributes.length; i++)
|
||||
dataObject[attributes[i]] = aElement.getAttribute(attributes[i]);
|
||||
|
||||
dataObject.localname = aElement.localName;
|
||||
return dataObject;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
// <menulist>
|
||||
set_Menulist: function (aElementID, aDataObject)
|
||||
{
|
||||
var element = gCurrentWindow.document.getElementById(aElementID);
|
||||
// set all generic properties
|
||||
wsm.generic_Set(element, aDataObject);
|
||||
// set menulist specific properties
|
||||
if ("value" in aDataObject) {
|
||||
try {
|
||||
element.value = aDataObject.value;
|
||||
}
|
||||
catch (ex) {
|
||||
dump(aElementID + ", ex: " + ex + "\n");
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
get_Menulist: function (aElementID)
|
||||
{
|
||||
var element = gCurrentWindow.document.getElementById(aElementID);
|
||||
// retrieve all generic attributes
|
||||
var dataObject = wsm.generic_Get(element);
|
||||
// retrieve all menulist specific attributes
|
||||
if (dataObject) {
|
||||
dataObject.value = element.getAttribute("value");
|
||||
return dataObject;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
// <radiogroup>
|
||||
set_Radiogroup: function (aElementID, aDataObject)
|
||||
{
|
||||
var element = gCurrentWindow.document.getElementById(aElementID);
|
||||
wsm.generic_Set(element, aDataObject);
|
||||
if ("value" in aDataObject)
|
||||
element.value = aDataObject.value;
|
||||
if ("disabled" in aDataObject)
|
||||
element.disabled = aDataObject.disabled;
|
||||
},
|
||||
|
||||
get_Radiogroup: function (aElementID)
|
||||
{
|
||||
var element = gCurrentWindow.document.getElementById(aElementID);
|
||||
var dataObject = wsm.generic_Get(element);
|
||||
if (dataObject) {
|
||||
dataObject.value = element.getAttribute("value");
|
||||
return dataObject;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
// <textbox>
|
||||
set_Textbox: function (aElementID, aDataObject)
|
||||
{
|
||||
var element = gCurrentWindow.document.getElementById(aElementID);
|
||||
wsm.generic_Set(element, aDataObject);
|
||||
},
|
||||
|
||||
get_Textbox: function (aElementID)
|
||||
{
|
||||
var element = gCurrentWindow.document.getElementById(aElementID);
|
||||
var dataObject = wsm.generic_Get(element);
|
||||
if (dataObject) {
|
||||
dataObject.value = element.value;
|
||||
return dataObject;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
// <checkbox>
|
||||
set_Checkbox: function (aElementID, aDataObject)
|
||||
{
|
||||
var element = gCurrentWindow.document.getElementById(aElementID);
|
||||
// Set generic properites.
|
||||
wsm.generic_Set(element, aDataObject);
|
||||
// Handle reversed boolean values.
|
||||
if ("checked" in aDataObject && element.hasAttribute("reversed"))
|
||||
element.checked = !aDataObject.checked;
|
||||
},
|
||||
|
||||
get_Checkbox: function (aElementID)
|
||||
{
|
||||
var element = gCurrentWindow.document.getElementById(aElementID);
|
||||
var dataObject = wsm.generic_Get(element);
|
||||
if (dataObject) {
|
||||
var checked = element.checked;
|
||||
dataObject.checked = element.getAttribute("reversed") == "true" ? !checked : checked;
|
||||
return dataObject;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
// <listitem>
|
||||
set_Listitem: function (aElementID, aDataObject)
|
||||
{
|
||||
var element = gCurrentWindow.document.getElementById(aElementID);
|
||||
wsm.generic_Set(element, aDataObject);
|
||||
},
|
||||
|
||||
get_Listitem: function (aElementID)
|
||||
{
|
||||
var element = gCurrentWindow.document.getElementById(aElementID);
|
||||
var dataObject = wsm.generic_Get(element);
|
||||
if (dataObject) {
|
||||
if (element.getAttribute("type") == "checkbox")
|
||||
dataObject.checked = element.checked;
|
||||
return dataObject;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
// <data>
|
||||
set_Data: function (aElementID, aDataObject)
|
||||
{
|
||||
var element = gCurrentWindow.document.getElementById(aElementID);
|
||||
wsm.generic_Set(element, aDataObject);
|
||||
if ("value" in aDataObject)
|
||||
element.setAttribute("value", aDataObject.value);
|
||||
},
|
||||
|
||||
get_Data: function (aElementID)
|
||||
{
|
||||
var element = gCurrentWindow.document.getElementById(aElementID);
|
||||
var dataObject = wsm.generic_Get(element);
|
||||
if (dataObject) {
|
||||
dataObject.value = element.getAttribute("value");
|
||||
return dataObject;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
// <default>
|
||||
set_Default: function (aElementID, aDataObject)
|
||||
{
|
||||
var element = gCurrentWindow.document.getElementById(aElementID);
|
||||
wsm.generic_Set(element, aDataObject);
|
||||
},
|
||||
|
||||
get_Default: function (aElementID)
|
||||
{
|
||||
var element = gCurrentWindow.document.getElementById(aElementID);
|
||||
var dataObject = wsm.generic_Get(element);
|
||||
return dataObject ? dataObject : null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# M:tHoF Greatest Hits Section (Append one line per edit):
|
||||
# it will be dark soon
|
||||
# MANOS MADE ME PERMANENT!
|
||||
# there is no way out of here
|
||||
# [The Master is] not dead as you know it. He is with us always..
|
||||
# My name is Torgo, I take care of the place while the Master is away.
|
||||
# The car won't start
|
|
@ -1,464 +0,0 @@
|
|||
/* -*- Mode: Java; tab-width: 2; c-basic-offset: 2; -*-
|
||||
*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org Code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Ben "Count XULula" Goodger <rgoodger@ihug.co.nz>
|
||||
* Alec Flett <alecf@netscape.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
|
||||
/** class WizardStateManager ( string frame_id, object pageMap )
|
||||
* - purpose: object for managing data in iframe multi-panel dialogs.
|
||||
* - in: string frame id/name set of iframe, pageMap showing navigation of wizard
|
||||
* - out: nothing (object)
|
||||
**/
|
||||
function WidgetStateManager( frame_id, panelPrefix, panelSuffix )
|
||||
{
|
||||
// data members
|
||||
/**
|
||||
* hash table for data values:
|
||||
* page1 => id1 => value1
|
||||
* page1 => id2 => value2
|
||||
* page2 => id1 => value1
|
||||
* page2 => id2 => value2
|
||||
**/
|
||||
this.PageData = [];
|
||||
this.content_frame = window.frames[frame_id];
|
||||
|
||||
this.panelPrefix = ( panelPrefix ) ? panelPrefix : null;
|
||||
this.panelSuffix = ( panelSuffix ) ? panelSuffix : null;
|
||||
|
||||
// member functions
|
||||
this.SavePageData = WSM_SavePageData;
|
||||
this.SetPageData = WSM_SetPageData;
|
||||
this.PageIsValid = WSM_PageIsValid;
|
||||
this.GetTagFromURL = WSM_GetTagFromURL;
|
||||
this.GetURLFromTag = WSM_GetURLFromTag;
|
||||
this.toString = WSM_toString;
|
||||
this.AddAttributes = WSM_AddAttributes;
|
||||
this.ElementIsIgnored = WSM_ElementIsIgnored;
|
||||
this.HasValidElements = WSM_HasValidElements;
|
||||
this.LookupElement = WSM_LookupElement;
|
||||
this.GetDataForTag = WSM_GetDataForTag;
|
||||
this.SetDataForTag = WSM_SetDataForTag;
|
||||
}
|
||||
|
||||
/** void SavePageData() ;
|
||||
* - purpose: retrieves form/widget data from a generic page stored in a frame.
|
||||
* - useful for retrieving and persisting wizard/prefs page data that
|
||||
* - has not been added to permanent storage.
|
||||
* - for full reference, please refer to user manual at:
|
||||
* - http://www.mozilla.org/xpapps/ui/wizards.html
|
||||
* - in: nothing
|
||||
* - out: nothing
|
||||
**/
|
||||
function WSM_SavePageData( currentPageTag, optAttributes, exclElements, inclElements )
|
||||
{
|
||||
// 11/26/99: changing this to support the saving of an optional number of extra
|
||||
// attributes other than the default value. these attributes are specified as
|
||||
// strings in an array passed in as the second parameter. these values are stored
|
||||
// in the table associated with the element:
|
||||
//
|
||||
// this.wsm.PageData[pageTag][element][id] - id of element (default)
|
||||
// this.wsm.PageData[pageTag][element][value] - value of element (default)
|
||||
// this.wsm.PageData[pageTag][element][foo] - optional attribute (default)
|
||||
// 11/27/99: changing this to support the exclusion of specified elements.
|
||||
// typically this is includes fieldsets, legends and labels. These are default
|
||||
// and do not need to be passed.
|
||||
|
||||
if( !currentPageTag )
|
||||
currentPageTag = this.GetTagFromURL( this.content_frame.location.href, this.panelPrefix, this.panelSuffix, true );
|
||||
|
||||
var doc = this.content_frame.document;
|
||||
var thisTagData = this.GetDataForTag(currentPageTag);
|
||||
|
||||
if( this.content_frame.GetFields ) {
|
||||
// user GetFields function
|
||||
this.SetDataForTag(currentPageTag, this.content_frame.GetFields());
|
||||
var string = "";
|
||||
for( var i in thisTagData )
|
||||
{
|
||||
string += "element: " + i + "\n";
|
||||
}
|
||||
}
|
||||
else if (doc && doc.controls) {
|
||||
var fields = doc.controls;
|
||||
var data = [];
|
||||
for( i = 0; i < fields.length; i++ )
|
||||
{
|
||||
data[i] = [];
|
||||
var formElement = fields[i];
|
||||
var elementEntry = thisTagData[formElement.id] = [];
|
||||
|
||||
// check to see if element is excluded
|
||||
if( !this.ElementIsIgnored( formElement, exclElements ) )
|
||||
elementEntry.excluded = false;
|
||||
else
|
||||
elementEntry.excluded = true;
|
||||
|
||||
if( formElement.localName.toLowerCase() == "select" ) { // select & combo
|
||||
/* commenting out until select fields work properly, or someone tells me how
|
||||
to do this (also, is it better to store .value, or .text?):*/
|
||||
if( formElement.getAttribute("multiple") ) {
|
||||
// multiple selections
|
||||
for( var j = 0, idx = 0; j < formElement.options.length; j++ )
|
||||
{
|
||||
if( formElement.options[j].selected ) {
|
||||
elementEntry.value[idx] = formElement.options[j].value;
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// single selections
|
||||
if (formElement.options[formElement.selectedIndex]) {
|
||||
var value = formElement.options[formElement.selectedIndex].value;
|
||||
dump("*** VALUE=" + value + "\n");
|
||||
formElement.arbitraryvalue = value;
|
||||
this.AddAttributes( formElement, elementEntry, "arbitraryvalue", optAttributes );
|
||||
this.AddAttributes( formElement, elementEntry, "value", optAttributes);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( formElement.getAttribute("type") &&
|
||||
( formElement.type.toLowerCase() == "checkbox" ||
|
||||
formElement.type.toLowerCase() == "radio" ) ) {
|
||||
// XXX 11/04/99
|
||||
this.AddAttributes( formElement, elementEntry, "checked", optAttributes );
|
||||
}
|
||||
else if( formElement.type == "text" &&
|
||||
formElement.getAttribute( "datatype" ) == "nsIFileSpec" &&
|
||||
formElement.value ) {
|
||||
try {
|
||||
var filespec = Components.classes["@mozilla.org/filespec;1"].createInstance();
|
||||
filespec = filespec.QueryInterface( Components.interfaces.nsIFileSpec );
|
||||
}
|
||||
catch(e) {
|
||||
dump("*** Failed to create filespec object\n");
|
||||
}
|
||||
filespec.nativePath = formElement.value;
|
||||
this.AddAttributes( formElement, elementEntry, "filespec", optAttributes )
|
||||
}
|
||||
else
|
||||
this.AddAttributes( formElement, elementEntry, "value", optAttributes ); // generic
|
||||
|
||||
elementEntry.id = formElement.id;
|
||||
elementEntry.localName = formElement.localName;
|
||||
// save the type attribute on the element if one is present
|
||||
elementEntry.elType = ( formElement.type ) ? formElement.type : null;
|
||||
}
|
||||
}
|
||||
if( !this.HasValidElements( thisTagData ) )
|
||||
thisTagData.noData = true; // page has no (valid) elements
|
||||
}
|
||||
|
||||
/** void SetPageData() ;
|
||||
* - purpose: populates the loaded page with appropriate data from the data
|
||||
* - table.
|
||||
* - for full reference, please refer to user manual at:
|
||||
* - http://www.mozilla.org/xpapps/ui/wizards.html
|
||||
* - in: nothing.
|
||||
* - out: nothing.
|
||||
**/
|
||||
function WSM_SetPageData( currentPageTag, hasExtraAttributes )
|
||||
{
|
||||
if( !currentPageTag )
|
||||
currentPageTag = this.GetTagFromURL( this.content_frame.location.href, this.panelPrefix, this.panelSuffix, true );
|
||||
|
||||
var doc = this.content_frame.document;
|
||||
var thisTagData = this.GetDataForTag(currentPageTag);
|
||||
if ( thisTagData && !thisTagData.nodata) {
|
||||
for( var i in thisTagData ) {
|
||||
if( thisTagData[i].excluded || !i )
|
||||
continue; // element is excluded, goto next
|
||||
|
||||
var id = thisTagData[i].id;
|
||||
var value = thisTagData[i].value;
|
||||
|
||||
dump("*** id & value: " + id + " : " + value + "\n");
|
||||
|
||||
if( this.content_frame.SetFields && !hasExtraAttributes )
|
||||
this.content_frame.SetFields( id, value ); // user provided setfields
|
||||
else if( this.content_frame.SetFields && hasExtraAttributes )
|
||||
this.content_frame.SetFields( id, value, thisTagData[i]); // SetFields + attrs
|
||||
else { // automated data provision
|
||||
var formElement = doc.getElementById( i );
|
||||
|
||||
if( formElement && hasExtraAttributes ) { // if extra attributes are set, set them
|
||||
for( var attName in thisTagData[i] )
|
||||
{
|
||||
// for each attribute set for this element
|
||||
if( attName == "value" || attName == "id" )
|
||||
continue; // don't set value/id (value = default, id = dangerous)
|
||||
var attValue = thisTagData[i][attName];
|
||||
formElement.setAttribute( attName, attValue );
|
||||
}
|
||||
}
|
||||
|
||||
// default "value" attributes
|
||||
if( formElement && formElement.localName.toLowerCase() == "input" ) {
|
||||
if( formElement.type.toLowerCase() == "checkbox" ||
|
||||
formElement.type.toLowerCase() == "radio" ) {
|
||||
if( value == undefined )
|
||||
formElement.checked = formElement.defaultChecked;
|
||||
else
|
||||
formElement.checked = value;
|
||||
/* oops.. appears we've reimplemented 'reversed'. this will be why its not working for alecf.
|
||||
if( formElement.getAttribute( "reversed" ) )
|
||||
formElement.checked = !value;
|
||||
else
|
||||
formElement.checked = value;
|
||||
*/
|
||||
}
|
||||
else if( formElement.type.toLowerCase() == "text" &&
|
||||
formElement.getAttribute( "datatype" ) == "nsIFileSpec" ) {
|
||||
// formElement has something to do with fileSpec. looked important
|
||||
if( value ) {
|
||||
var filespec = value.QueryInterface( Components.interfaces.nsIFileSpec );
|
||||
try {
|
||||
formElement.value = filespec.nativePath;
|
||||
}
|
||||
catch( ex ) {
|
||||
dump("Still need to fix uninitialized filespec problem!\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
formElement.value = formElement.defaultValue;
|
||||
}
|
||||
else { // some other type of form element
|
||||
if( value == undefined )
|
||||
formElement.value = formElement.defaultValue;
|
||||
else
|
||||
formElement.value = value;
|
||||
}
|
||||
}
|
||||
else if( formElement && formElement.localName.toLowerCase() == "select" ) {
|
||||
/* commenting this out until select widgets work properly */
|
||||
if( formElement.getAttribute("multiple") &&
|
||||
typeof(value) == "object" ) {
|
||||
// multiple selected items
|
||||
for( var j = 0; j < value.length; j++ )
|
||||
{
|
||||
for ( var k = 0; k < formElement.options.length; k++ )
|
||||
{
|
||||
if( formElement.options[k].value == value[j] )
|
||||
formElement.options[k].selected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// single selected item
|
||||
for ( k = 0; k < formElement.options.length; k++ )
|
||||
{
|
||||
dump("*** value=" + value + "; options[k].value=" + formElement.options[k].value + "\n");
|
||||
if( formElement.options[k].value == value )
|
||||
formElement.options[k].selected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( formElement && formElement.localName.toLowerCase() == "textarea" )
|
||||
formElement.value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
// initialize the pane
|
||||
if (this.content_frame.onInit) {
|
||||
dump("Calling custom onInit()\n");
|
||||
this.content_frame.onInit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** boolean PageIsValid()
|
||||
* - purpose: returns whether the given page is in a valid state
|
||||
* - in:
|
||||
* - out:
|
||||
*/
|
||||
function WSM_PageIsValid()
|
||||
{
|
||||
if( this.content_frame.validate )
|
||||
return this.content_frame.validate();
|
||||
|
||||
// page is valid by default
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/** string GetTagFromURL( string tag, string prefix, string postfix ) ;
|
||||
* - purpose: fetches a tag from a URL
|
||||
* - in: string url representing the complete location of the page.
|
||||
* - out: string tag representing the specific page to be loaded
|
||||
**/
|
||||
function WSM_GetTagFromURL( url, prefix, suffix, mode )
|
||||
{
|
||||
// NOTE TO SELF: this is an accident WAITING to happen
|
||||
if (!prefix) return undefined;
|
||||
if( mode )
|
||||
return url.substring( prefix.length, url.lastIndexOf(suffix) );
|
||||
else
|
||||
return url.substring( url.lastIndexOf(prefix) + 1, url.lastIndexOf(suffix) );
|
||||
}
|
||||
|
||||
/** string GetUrlFromTag( string tag, string prefix, string postfix ) ;
|
||||
* - purpose: creates a complete URL based on a tag.
|
||||
* - in: string tag representing the specific page to be loaded
|
||||
* - out: string url representing the complete location of the page.
|
||||
**/
|
||||
function WSM_GetURLFromTag( tag, prefix, postfix )
|
||||
{
|
||||
return prefix + tag + postfix;
|
||||
}
|
||||
|
||||
/** string toString() ;
|
||||
* - purpose: returns a string representation of the object
|
||||
* - in: nothing;
|
||||
* - out: nothing;
|
||||
**/
|
||||
function WSM_toString()
|
||||
{
|
||||
var string = "";
|
||||
for( var i in this.PageData ) {
|
||||
for( var j in this.PageData[i] ) {
|
||||
for( var k in this.PageData[i][j] ) {
|
||||
string += "WSM.PageData[" + i + "][" + j + "][" + k + "] : " + this.PageData[i][j][k] + ";\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
/** void AddAttributes( DOMElement formElement, AssocArray elementEntry,
|
||||
String valueAttribute, StringArray optAttributes ) ;
|
||||
* - purpose: adds name/value entries to associative array.
|
||||
* - in: formElement - element to add attributes from
|
||||
* - elementEntry - the associative array to add data to
|
||||
* - valueAttribute - string representing which attribute represents
|
||||
* - value (e.g. "value", "checked")
|
||||
* - optAttributes - array of extra attributes to store.
|
||||
* - out: nothing;
|
||||
**/
|
||||
function WSM_AddAttributes( formElement, elementEntry, valueAttribute, optAttributes )
|
||||
{
|
||||
// 07/01/00 adding in a reversed thing here for alecf's ultra picky mail prefs :P:P
|
||||
if( formElement.getAttribute("reversed") )
|
||||
elementEntry.value = !formElement[valueAttribute]; // get the value (e.g. "checked")
|
||||
else
|
||||
elementEntry.value = formElement[valueAttribute]; // get the value (e.g. "checked")
|
||||
|
||||
if( optAttributes ) { // if we've got optional attributes, add em
|
||||
for(var k = 0; k < optAttributes.length; k++ )
|
||||
{
|
||||
attValue = formElement.getAttribute( optAttributes[k] );
|
||||
if( attValue )
|
||||
elementEntry[optAttributes[k]] = attValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** string ElementIsIgnored( DOMElement element, StringArray exclElements ) ;
|
||||
* - purpose: check to see if the current element is one of the ignored elements
|
||||
* - in: element - element to check,
|
||||
* - exclElements - array of string ignored attribute localNames;
|
||||
* - out: boolean if element is ignored (true) or not (false);
|
||||
**/
|
||||
function WSM_ElementIsIgnored( element, exclElements )
|
||||
{
|
||||
if (!exclElements) return false;
|
||||
for( var i = 0; i < exclElements.length; i++ )
|
||||
{
|
||||
if( element.localName.toLowerCase() == exclElements[i] )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** string HasValidElements( AssocArray dataStore ) ;
|
||||
* - purpose: checks to see if there are any elements on this page that are
|
||||
* - valid.
|
||||
* - in: associative array representing the page;
|
||||
* - out: boolean whether or not valid elements are present (true) or not (false);
|
||||
**/
|
||||
function WSM_HasValidElements( dataStore )
|
||||
{
|
||||
for( var i in dataStore )
|
||||
{
|
||||
if( !dataStore[i].excluded )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
function WSM_LookupElement( element, lookby, property )
|
||||
{
|
||||
for(var i in this.PageData )
|
||||
{
|
||||
for( var j in this.PageData[i] )
|
||||
{
|
||||
if(!lookby)
|
||||
lookby = "id"; // search by id by default
|
||||
if( j[lookby] == element && !property )
|
||||
return j;
|
||||
else if( j[lookby] == element ) {
|
||||
var container = [];
|
||||
for( var k = 0; k < property.length; k++ )
|
||||
{
|
||||
container[k] = this.PageData[i][k][property[k]];
|
||||
}
|
||||
return container; // only support one single match per hash just now
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* array GetDataForTag(string tag)
|
||||
* - purpose: to get the array associated with this tag
|
||||
* creates the array if one doesn't already exist
|
||||
* - in: tag
|
||||
* - out: the associative array for this page
|
||||
*/
|
||||
function WSM_GetDataForTag(tag) {
|
||||
if (!this.PageData[tag])
|
||||
this.PageData[tag] = [];
|
||||
return this.PageData[tag];
|
||||
}
|
||||
|
||||
function WSM_SetDataForTag(tag, data) {
|
||||
this.PageData[tag] = data;
|
||||
}
|
||||
|
||||
/* it will be dark soon */
|
|
@ -7,4 +7,3 @@ toolkit.jar:
|
|||
+ content/global/nsTreeSorting.js (content/nsTreeSorting.js)
|
||||
+ content/global/nsUserSettings.js (content/nsUserSettings.js)
|
||||
+ content/global/strres.js (content/strres.js)
|
||||
+ content/global/widgetStateManager.js (content/widgetStateManager.js)
|
||||
|
|
Загрузка…
Ссылка в новой задаче