home *** CD-ROM | disk | FTP | other *** search
- // Copyright 1998,1999 Macromedia, Inc. All rights reserved.
-
- //*************** GLOBALS VARS *****************
-
- var HELP_DOC = HELP_cmdConditionEditor;
-
- var MENUDATA_stdExprTypes = new Array("knowledge","segment","tag","javascript");
- var MENUDATA_allExprTypes = new Array("knowledge","segment","tag","javascript",
- "boolean","string","number");
- var MENUDATA_ordExprTypes = new Array("knowledge","segment","tag","javascript","ordinal");
- var MENUDATA_numExprTypes = new Array("knowledge","segment","tag","javascript","number");
- var MENUDATA_strExprTypes = new Array("knowledge","segment","tag","javascript","string");
- var MENUDATA_boolExprTypes = new Array("knowledge","segment","tag","javascript","boolean");
- var MENUDATA_ordCompTypes = new Array("==", "!=");
- var MENUDATA_numCompTypes = new Array("==", "!=", ">", "<", ">=", "<=");
- var MENUDATA_strCompTypes = new Array("==", "!=","contains", "!contains");
-
- var PROP_autoAddCondition = true;
- var PROP_autoNameCondition = true;
-
- // attainInfo
- var LABELDATA_elemTypes = new Array(
- "inpt","ibtn","hota","text","textComp","sldr","sldrRnge","timr","timrTrig",
- "both","drag","targ","dragTarg");
-
- // tagInfo
- var MENUDATA_tagNames = new Array(
- "LAYER","DIV","SPAN","IMG","FORM","INPUT/CHECKBOX","INPUT/RADIO",
- "INPUT/TEXT","TEXTAREA","INPUT/PASSWORD","SELECT");
-
- // propEditor
- var MENUDATA_boolOps = new Array("&&", "||");
- var MENUDATA_allCompTypes = new Array(
- "==", "!=", ">", "<", ">=", "<=","contains", "!contains");
- var MENUDATA_boolVals = new Array("true", "false");
-
-
- // Interface variables
- var COND_NAME = '';
- var COND_DATA = '';
- var IS_SET = false;
-
- var CURR_INT_INDEX = -1;
-
-
- var parser = '';
- var editor = '';
-
- var name = ''; // the name of the condition
- var condition = ''; // the JS condition string
-
- var autoName = ''; // whether to automatically name a condition
- var condData = ''; // the data structure representing the condition
- var isComplete = ''; // indicates if the condition is complete
-
- var rTypeStore = ''; // stores the right-hand type
-
- // layer and UI objects
- var exprList = ''; // the list of expressions
- var lSelLayer = ''; // Left Type layer
- var lSelPick = '';
- var lKoLayer = ''; // Left KO layer
- var lKoIntPick = '';
- var lKoElemPick = '';
- var lKoPropPick = '';
- var lDocLayer = ''; // Left Tag Layer
- var lDocTypePick = '';
- var lDocObjPick = '';
- var lDocPropEntry = ''
- var lJsLayer = ''; // Left JS Layer
- var lJsEntry = '';
-
- var compLayer = '';
- var compPick = '';
-
- var rSelLayer = ''; // Right Type layer
- var rSelPick = '';
- var rKoLayer = ''; // Right KO layer
- var rKoIntPick = '';
- var rKoElemPick = '';
- var rKoPropPick = '';
- var rDocLayer = ''; // Right Tag layer
- var rDocTypePick = '';
- var rDocObjPick = '';
- var rDocPropEntry = '';
- var rJsLayer = ''; // Right JS layer
- var rJsEntry = '';
- var rNumLayer = ''; // Right Num layer
- var rNumEntry = '';
- var rTextLayer = ''; // Right Text layer
- var rTextEntry = '';
- var rBoolLayer = ''; // Right Boolean layer
- var rBoolPick = '';
- var rOrdLayer = ''; // Right Ordinal layer
- var rOrdPick = '';
-
- var boolOpLayer = '';
- var boolOpPick = '';
-
-
- //******************* API **********************
-
- function commandButtons(){
- return new Array(BTN_OK,"cmdOK()",
- BTN_Cancel,"cmdCancel()",
- BTN_Help,"displayHelp()");
- }
-
- function cmdOK() {
- if (applyCommand()) {
- garbageCollect(true);
- window.close();
- }
- }
-
- function cmdCancel() {
- garbageCollect(true);
- window.close();
- }
-
- function applyCommand() {
- var retVal = false,theList,newName;
- if (!isComplete) {
- alert(MSG_condIncomplete);
- } else if (condData.length == 0) {
- alert(MSG_noConditions);
- } else {
- // auto name the condition, if necessary
- if (PROP_autoNameCondition && autoName) {
- theList = editor.getExprList(condData);
- newName = '';
- for (i=0; i < theList.length && newName.length <= PREF_autoCondNameLength; i++)
- newName += theList[i] + ((i+1 < theList.length) ? " " : "");
- if (newName.length > PREF_autoCondNameLength)
- newName = newName.substring(0, PREF_autoCondNameLength) + "...";
- name = (newName) ? newName : LABEL_defaultCondName;
- name = name.replace(/"/g, '');
- name = name.replace(/'/g, '');
- }
-
- condition = parser.getCondImage(condData);
-
- COND_NAME = name;
- COND_DATA = condition;
- IS_SET = true;
- retVal = true;
- }
- return retVal;
- }
-
- function inspectCommand(theName, theCondStr) {
- name = (theName!=null) ? theName : '';
- condition = (theCondStr!=null) ? theCondStr : '';
- COND_NAME = name;
- COND_DATA = condition;
- IS_SET = false;
-
- setupControls();
- }
-
-
- function setupControls() {
- parser = new PropParser();
- editor = new PropEditor();
-
- // Create the controls
- exprList = new ListControl('exprSelect');
-
- lSelLayer = findObject('leftSelector');
- lSelPick = new PickList('theLeftKind');
- lSelPick.setInfo(MENULIST_stdExprTypes, MENUDATA_stdExprTypes);
-
- lKoLayer = findObject('koLeftEdit');
- lKoIntPick = new PickList('theLeftInt');
- lKoElemPick = new PickList('theLeftElem');
- lKoPropPick = new PickList('theLeftProp');
-
- lDocLayer = findObject('docLeftEdit');
- lDocTypePick = new PickList('theLeftTagType');
- lDocTypePick.setInfo(MENULIST_tagNames, MENUDATA_tagNames);
- lDocObjPick = new PickList('theLeftTag');
- lDocPropEntry = findObject('theLeftTagProp' , lDocLayer);
-
- lJsLayer = findObject('jsLeftEdit');
- lJsEntry = findObject('theLeftJs' , lJsLayer);
-
- compLayer = findObject('operatorEdit');
- compPick = new PickList('theOperator');
- compPick.setInfo(MENULIST_allCompTypes, MENUDATA_allCompTypes);
-
- rSelLayer = findObject('rightSelector');
- rSelPick = new PickList('theRightKind');
- rSelPick.setInfo(MENULIST_allExprTypes, MENUDATA_allExprTypes);
-
- rKoLayer = findObject('koRightEdit');
- rKoIntPick = new PickList('theRightInt');
- rKoElemPick = new PickList('theRightElem');
- rKoPropPick = new PickList('theRightProp');
-
- rDocLayer = findObject('docRightEdit');
- rDocTypePick = new PickList('theRightTagType');
- rDocTypePick.setInfo(MENULIST_tagNames, MENUDATA_tagNames);
- rDocObjPick = new PickList('theRightTag');
- rDocPropEntry = findObject('theRightTagProp' , rDocLayer);
-
- rJsLayer = findObject('jsRightEdit');
- rJsEntry = findObject('theRightJs' , rJsLayer);
-
- rNumLayer = findObject('numRightEdit');
- rNumEntry = findObject('theRightNum' , rNumLayer);
-
- rTextLayer = findObject('textRightEdit');
- rTextEntry = findObject('theRightText' , rTextLayer);
-
- rBoolLayer = findObject('boolRightEdit');
- rBoolPick = new PickList('theRightBool');
- rBoolPick.setInfo(MENULIST_boolVals, MENUDATA_boolVals);
-
- rOrdLayer = findObject('ordRightEdit');
- rOrdPick = new PickList('theRightOrd');
-
- boolOpLayer = findObject('boolOpSelector');
- boolOpPick = new PickList('theBoolOp');
- boolOpPick.setInfo(MENULIST_boolOps, MENUDATA_boolOps);
-
-
- // Initialize the controls
-
- theObj=findObject('niceName');
- theObj.value = removeExt(name);
- autoName = (name.length == 0 || removeExt(name) == LABEL_defaultCondName);
-
- editor.init();
- if (CURR_INT_INDEX != -1)
- editor.intList.defIndex = CURR_INT_INDEX;
-
- with (editor.intList) {
- lKoIntPick.setInfo(names, ids, defIndex);
- rKoIntPick.setInfo(names, ids, defIndex);
- }
-
- rTypeStore = new Array();
-
- if (condition || !PROP_autoAddCondition) {
- // Parse the condition
- condData = parser.getCondData(condition);
- editor.isValidCond(condData, true);
-
- // display the expression list.
- showExprList();
- exprList.setIndex(0);
-
- // now update the editor displays
- updateEditors();
- } else {
- // Add a default condition
- condData = new Array();
- condData[0] = parser.newExprNode();
- condData[0].left.type = parser.koType;
- condData[0].right.type = parser.boolType;
- condData[0].right.bool = "true";
-
- // update the display
- updateEditors(true,0); // pick default values for new item
- showExprList(); // now show
- exprList.setIndex(0);
- }
- }
-
-
- //***************** LOCAL FUNCTIONS ******************
-
- function initializeUI() {
- document.theForm.niceName.focus();
- document.theForm.niceName.select();
- }
-
- function updateUI(theItemName) {
- var theObj;
-
- if (theItemName == 'niceName') {
- theObj = findObject(theItemName);
- if (removeExt(name) != theObj.value) {
- name = theObj.value;
- name = name.replace(/"/g, '');
- name = name.replace(/'/g, '');
- theObj.value = name;
- autoName = (name.length == 0 || removeExt(name) == LABEL_defaultCondName);
- }
-
- } else if (theItemName == 'exprAdd') {
- var addIndex = (condData.length == 0) ? 0 : exprList.index+1;
- // create the node
- var newNode = parser.newExprNode();
- newNode.left.type = parser.koType;
- newNode.right.type = parser.boolType;
- newNode.right.bool = "true";
- // insert the node in condData
- condData.splice(addIndex, 0, newNode);
- // update the display
- updateEditors(true, addIndex); // pick default values for new item
- showExprList(); // now show
- exprList.setIndex(addIndex);
-
- } else if (theItemName == 'exprDel') {
- if (condData.length == 1) {
- alert(MSG_cantDeleteLastExpr);
- return;
- }
- condData.splice(exprList.index, 1);
- if (exprList.index >= condData.length)
- exprList.setIndex(condData.length-1);
- showExprList();
- updateEditors();
-
- } else if (theItemName == 'exprSelect') {
- exprList.refresh();
- updateEditors();
-
- } else if (theItemName == 'theLeftKind') {
- lSelPick.change();
- // store the right-hand type for the current left-hand type
- with (condData[exprList.index]) {
- rTypeStore[left.type] = (right.isSegment) ? 'segment' : right.type;
- if (lSelPick.id == 'segment') {
- left.type = parser.koType;
- left.isSegment = true;
- left.propIsFn = true;
- if (left.propArgs.length == 0) {
- left.propArgs[0] = parser.newOperNode();
- left.propArgs[0].type = parser.strType;
- }
- } else {
- left.type = lSelPick.id;
- left.isSegment = false;
- left.propIsFn = false;
- }
- right.type = (rTypeStore[left.type]) ? rTypeStore[left.type] : parser.boolType;
- right.isOrdinal = false;
- right.isSegment = false;
- right.propIsFn = false;
- if (right.type == 'segment') {
- right.type = parser.koType;
- right.isSegment = true;
- right.propIsFn = true;
- if (right.propArgs.length == 0) {
- right.propArgs[0] = parser.newOperNode();
- right.propArgs[0].type = parser.strType;
- }
- }
- }
- updateEditors(true);
- updateExprList();
- lSelPick.list.object.focus();
-
- } else if (theItemName == 'theLeftInt') {
- lKoIntPick.change();
- condData[exprList.index].left.interaction = lKoIntPick.id.value;
- updateEditors(true);
- updateExprList();
- lKoIntPick.list.object.focus();
- } else if (theItemName == 'theLeftElem') {
- lKoElemPick.change();
- with (condData[exprList.index]) {
- if (!left.isSegment) {
- left.element = lKoElemPick.id.elem;
- left.choice = lKoElemPick.id.choice;
- } else {
- left.propArgs[0].text = lKoElemPick.id;
- }
- }
- updateEditors(true);
- updateExprList();
- lKoElemPick.list.object.focus();
- } else if (theItemName == 'theLeftProp') {
- lKoPropPick.change();
- condData[exprList.index].left.property = lKoPropPick.id.value;
- updateEditors(true);
- updateExprList();
- lKoPropPick.list.object.focus();
-
- } else if (theItemName == 'theLeftTagType') {
- lDocTypePick.change();
- condData[exprList.index].left.objType = lDocTypePick.id;
- updateEditors();
- updateExprList();
- lDocTypePick.list.object.focus();
- } else if (theItemName == 'theLeftTag') {
- lDocObjPick.change();
- condData[exprList.index].left.objName = lDocObjPick.id.value;
- updateExprList();
- lDocObjPick.list.object.focus();
- } else if (theItemName == 'theLeftTagProp') {
- condData[exprList.index].left.objProp = lDocPropEntry.value;
- updateExprList();
-
- } else if (theItemName == 'theLeftJs') {
- condData[exprList.index].left.script = parser.makeValidJSCond(lJsEntry.value);
- updateExprList();
-
- } else if (theItemName == 'theOperator') {
- compPick.change();
- condData[exprList.index].operator = compPick.id;
- updateExprList();
- compPick.list.object.focus();
-
- } else if (theItemName == 'theRightKind') {
- rSelPick.change();
- with (condData[exprList.index]) {
- right.type = rSelPick.id;
- right.isOrdinal = false;
- right.isSegment = false;
- right.propIsFn = false;
- if (rSelPick.id == 'ordinal') { // selected an ordinal
- right.type = lKoPropPick.id.type;
- right.isOrdinal = true;
- } else if (rSelPick.id == 'segment') { // selected an AM property
- right.type = parser.koType;
- right.isSegment = true;
- right.propIsFn = true;
- if (right.propArgs.length == 0) {
- right.propArgs[0] = parser.newOperNode();
- right.propArgs[0].type = parser.strType;
- }
- }
- }
- updateEditors();
- updateExprList();
- rSelPick.list.object.focus();
-
- } else if (theItemName == 'theRightInt') {
- rKoIntPick.change();
- condData[exprList.index].right.interaction = rKoIntPick.id.value;
- updateEditors();
- updateExprList();
- rKoIntPick.list.object.focus();
- } else if (theItemName == 'theRightElem') {
- rKoElemPick.change();
- with (condData[exprList.index]) {
- if (!right.isSegment) {
- right.element = rKoElemPick.id.elem;
- right.choice = rKoElemPick.id.choice;
- } else {
- right.propArgs[0].text = rKoElemPick.id;
- }
- }
- updateEditors();
- updateExprList();
- rKoElemPick.list.object.focus();
- } else if (theItemName == 'theRightProp') {
- rKoPropPick.change();
- condData[exprList.index].right.property = rKoPropPick.id.value;
- updateExprList();
- rKoPropPick.list.object.focus();
-
- } else if (theItemName == 'theRightTagType') {
- rDocTypePick.change();
- condData[exprList.index].right.objType = rDocTypePick.id;
- updateEditors();
- updateExprList();
- rDocTypePick.list.object.focus();
- } else if (theItemName == 'theRightTag') {
- rDocObjPick.change();
- condData[exprList.index].right.objName = rDocObjPick.id.value;
- updateExprList();
- rDocObjPick.list.object.focus();
- } else if (theItemName == 'theRightTagProp') {
- condData[exprList.index].right.objProp = rDocPropEntry.value;
- updateExprList();
-
- } else if (theItemName == 'theRightJs') {
- condData[exprList.index].right.script = parser.makeValidJSCond(rJsEntry.value);
- updateExprList();
-
- } else if (theItemName == 'theRightNum') {
- if (isNumber(rNumEntry.value)) {
- condData[exprList.index].right.number = rNumEntry.value;
- updateExprList();
- } else {
- alert(MSG_numbersOnly);
- rNumEntry.value = condData[exprList.index].right.number;
- }
-
- } else if (theItemName == 'theRightText') {
- condData[exprList.index].right.text = rTextEntry.value;
- updateExprList();
-
- } else if (theItemName == 'theRightBool') {
- rBoolPick.change();
- condData[exprList.index].right.bool = rBoolPick.id;
- updateExprList();
- rBoolPick.list.object.focus();
-
- } else if (theItemName == 'theRightOrd') {
- rOrdPick.change();
- // set the appropriate value for the current type
- if (condData[exprList.index].right.type == parser.strType)
- condData[exprList.index].right.text = rOrdPick.id;
- else if (condData[exprList.index].right.type == parser.numType)
- condData[exprList.index].right.number = rOrdPick.id;
- else if (condData[exprList.index].right.type == parser.jsType)
- condData[exprList.index].right.script = rOrdPick.id;
- updateExprList();
- rOrdPick.list.object.focus();
-
- } else if (theItemName == 'theBoolOp') {
- boolOpPick.change();
- condData[exprList.index].boolOp = boolOpPick.id;
- updateExprList();
- boolOpPick.list.object.focus();
- }
- }
-
-
- //Shows the expression list display.
- //
- function showExprList() {
- var theList = '';
-
- theList = editor.getExprList(condData);
- isComplete = editor.isComplete;
- exprList.setAll(theList);
- }
-
-
- //Updates the current expression
- //
- function updateExprList() {
- var theList = '', expr;
- var theIndex = exprList.index;
-
- theList = editor.getExprList(condData);
- isComplete = editor.isComplete;
-
- // convert HTML escape sequences
- expr = theList[theIndex];
- expr = expr.replace(/>[;]?/g, ">");
- expr = expr.replace(/<[;]?/g, "<");
-
- exprList.set(expr);
- }
-
-
- function updateEditors(changeRightType, index) {
- index = (index != null) ? index : exprList.index;
- changeRightType = (changeRightType != null) ? changeRightType : false;
-
- if (index < 0 || index >= condData.length) {
- var emptyNode = parser.newExprNode();
- updateExpression(emptyNode);
- } else
- updateExpression(condData[index], changeRightType);
- }
-
-
- function updateExpression(theExprNode, changeRightType) {
- with (theExprNode) {
-
- if (left.type != parser.noType) {
- lSelLayer.visibility = "inherit";
- if (left.isSegment)
- lSelPick.pickValue('segment');
- else
- lSelPick.pickValue(left.type);
- } else
- lSelLayer.visibility = "hidden";
-
-
- editor.updateKObject(left, lKoLayer, lKoIntPick, lKoElemPick, lKoPropPick, false);
- editor.updateTag(left, lDocLayer, lDocTypePick, lDocObjPick, lDocPropEntry);
- editor.updateEntry(parser.jsType, left, lJsLayer, lJsEntry, left.script);
-
- if (changeRightType) { // set the right operand based on the property type
- if (left.type == parser.koType) {
- if (right.type != parser.koType && right.type != parser.tagType) {
- right.type = lKoPropPick.id.type;
- right.isOrdinal = (lKoPropPick.id.ordValues) ? true : false;
- }
- }
- }
-
- if (left.type == parser.jsType) right.type = parser.noType;
-
- // set the operator and right selection list,
- // based on the property type
- if (left.type == parser.koType) {
- if (lKoPropPick.id.ordValues) {
- compPick.setInfo(MENULIST_ordCompTypes, MENUDATA_ordCompTypes);
- rSelPick.setInfo(MENULIST_ordExprTypes, MENUDATA_ordExprTypes);
- } else if (lKoPropPick.id.type == parser.strType) {
- compPick.setInfo(MENULIST_strCompTypes, MENUDATA_strCompTypes);
- rSelPick.setInfo(MENULIST_strExprTypes, MENUDATA_strExprTypes);
- } else if (lKoPropPick.id.type == parser.numType) {
- compPick.setInfo(MENULIST_numCompTypes, MENUDATA_numCompTypes);
- rSelPick.setInfo(MENULIST_numExprTypes, MENUDATA_numExprTypes);
- } else if (lKoPropPick.id.type == parser.boolType) {
- compPick.setInfo(MENULIST_ordCompTypes, MENUDATA_ordCompTypes);
- rSelPick.setInfo(MENULIST_boolExprTypes, MENUDATA_boolExprTypes);
- } else {
- compPick.setInfo(MENULIST_allCompTypes, MENUDATA_allCompTypes);
- rSelPick.setInfo(MENULIST_allExprTypes, MENUDATA_allExprTypes);
- }
- } else {
- compPick.setInfo(MENULIST_allCompTypes, MENUDATA_allCompTypes);
- rSelPick.setInfo(MENULIST_allExprTypes, MENUDATA_allExprTypes);
- }
-
- if (right.type != parser.noType) {
- compLayer.visibility = "inherit";
- compPick.pickValue(operator);
- operator = compPick.id;
- } else
- compLayer.visibility = "hidden";
-
- if (right.type != parser.noType) {
- rSelLayer.visibility = "inherit";
- if (right.isOrdinal)
- rSelPick.pickValue('ordinal');
- else if (right.isSegment)
- rSelPick.pickValue('segment');
- else
- rSelPick.pickValue(right.type);
- } else
- rSelLayer.visibility = "hidden";
-
- editor.updateKObject(right, rKoLayer, rKoIntPick, rKoElemPick, rKoPropPick, false);
- editor.updateTag(right, rDocLayer, rDocTypePick, rDocObjPick, rDocPropEntry);
- editor.updateEntry(parser.jsType, right, rJsLayer, rJsEntry, right.script);
- editor.updateEntry(parser.numType, right, rNumLayer, rNumEntry, right.number);
- editor.updateEntry(parser.strType, right, rTextLayer, rTextEntry, right.text);
- editor.updateBoolean(right, rBoolLayer, rBoolPick);
- editor.updateOrdinal(right, rOrdLayer, rOrdPick, lKoPropPick.id);
-
- if (left.type != parser.noType) {
- boolOpLayer.visibility = "inherit";
- boolOpPick.pickValue(boolOp);
- boolOp = boolOpPick.id;
- } else
- boolOpLayer.visibility = "hidden";
- }
- }
-