init
This commit is contained in:
333
include/SugarDependentDropdown/SugarDependentDropdown.php
Executable file
333
include/SugarDependentDropdown/SugarDependentDropdown.php
Executable file
@@ -0,0 +1,333 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
/*********************************************************************************
|
||||
|
||||
* Description:
|
||||
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. All Rights
|
||||
* Reserved. Contributor(s): ______________________________________..
|
||||
*********************************************************************************/
|
||||
|
||||
class SugarDependentDropdown {
|
||||
/*
|
||||
* Holds processed metadata, ready for JSON
|
||||
*/
|
||||
var $metadata;
|
||||
|
||||
/*
|
||||
* Flag to suppress errors and/or log more heavily
|
||||
*/
|
||||
var $debugMode = false;
|
||||
|
||||
/*
|
||||
* Default metadata array that will be merged with any passed fields to
|
||||
* ensure uniformity
|
||||
*/
|
||||
var $defaults = array(
|
||||
'name' => '',
|
||||
'id' => '',
|
||||
'type' => 'none', // form element, valid "select", "input", "checkbox", "none"
|
||||
'label_pos' => 'left', // valid: 'left', 'right', 'top', 'bottom', 'none' (none)
|
||||
'hidden' => array(), // metadata to create hidden fields with values you choose
|
||||
);
|
||||
|
||||
/*
|
||||
* Fields that must exist in an element (single dropdown/field) metadata
|
||||
* array.
|
||||
*/
|
||||
var $elementRequired = array(
|
||||
'name',
|
||||
'id',
|
||||
//'values',
|
||||
//'onchange',
|
||||
//'force_render',
|
||||
);
|
||||
|
||||
/**
|
||||
* Fields that will be merged down into individual elements and handlers
|
||||
*/
|
||||
var $alwaysMerge = array(
|
||||
'force_render',
|
||||
);
|
||||
|
||||
/*
|
||||
* Valid 'types' for a dependent dropdown
|
||||
*/
|
||||
var $validTypes = array(
|
||||
"select", // select dropdown
|
||||
"input", // text input field
|
||||
"checkbox", // checkbox (radio buttons will not be supported)
|
||||
"none", // blank
|
||||
"multiple" // custom functionality
|
||||
);
|
||||
|
||||
/**
|
||||
* Sole constructor
|
||||
* @param string $metadata Path to metadata file to consume
|
||||
*/
|
||||
function SugarDependentDropdown($metadata='') {
|
||||
if(!empty($metadata)) {
|
||||
$this->init($metadata);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares an instance of SDD for use with a given set
|
||||
* @param string $metadata Path to metadata file to consume
|
||||
*/
|
||||
function init($metadata) {
|
||||
if(is_string($metadata)) {
|
||||
if($this->debugMode) {
|
||||
$this->debugOutput("Got metadata file [ {$metadata} ]");
|
||||
}
|
||||
if(file_exists($metadata)) {
|
||||
$sugarDependentDropdown = array();
|
||||
/*
|
||||
* The metadata file should be prepped in an associative array.
|
||||
* The array should be named "$sugarDependentDropdown".
|
||||
*
|
||||
* Examine:
|
||||
* "include/SugarDependentDropdown/metadata/dependentDropdown.
|
||||
* php" for a commented example.
|
||||
*/
|
||||
include($metadata); // provides $sugarDependentDropdown
|
||||
|
||||
foreach($sugarDependentDropdown as $key => $type) {
|
||||
if(is_array($type)) {
|
||||
foreach($type as $k => $v) {
|
||||
if($k == 'elements') {
|
||||
ksort($v); // order elements
|
||||
foreach($v as $index => $element) {
|
||||
$v[$index] = $this->initElement($element, $type['always_merge']);
|
||||
}
|
||||
} // end Work with elements block
|
||||
$type[$k] = $v;
|
||||
}
|
||||
|
||||
if(!$this->verifyMetadata($type)) {
|
||||
if($this->debugMode) {
|
||||
$this->debugOutput("SugarRouting: metadata initialization failed. Please check your metadata source.");
|
||||
}
|
||||
}
|
||||
}
|
||||
$sugarDependentDropdown[$key] = $type;
|
||||
} // end foreach of metadata
|
||||
|
||||
/* we made it through all checks so assign this to the output attribute */
|
||||
$this->metadata = $sugarDependentDropdown;
|
||||
} // end file_exists();
|
||||
else {
|
||||
if($this->debugMode) $this->debugOutput("SugarRouting could not find file [ {$metadata} ]");
|
||||
}
|
||||
} // end is_string();
|
||||
} // end init()
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//// PRIVATE UTILS
|
||||
/**
|
||||
* Verifies that an element is valid and has all the required info.
|
||||
*/
|
||||
function isValidElement($element) {
|
||||
if(is_array($element)) {
|
||||
foreach($this->elementRequired as $k => $req) {
|
||||
if(!array_key_exists($req, $element) && !isset($element['handlers'])) {
|
||||
if($this->debugMode) {
|
||||
$this->debugOutput("Element is missing required field: [ $req ]");
|
||||
$this->debugOutput($element);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if($this->debugMode) {
|
||||
$this->debugOutput("isValidElement is returning false. Passed the following as an argument:");
|
||||
$this->debugOutput($element);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes an element for processing
|
||||
* @param array $element Element metadata
|
||||
* @return array
|
||||
*/
|
||||
function initElement($element, $alwaysMerge) {
|
||||
if($this->isValidElement($element)) {
|
||||
$mergedElement = sugarArrayMerge($this->defaults, $element);
|
||||
|
||||
foreach($alwaysMerge as $key => $val) {
|
||||
if(!isset($mergedElement[$key]))
|
||||
$mergedElement[$key] = $val;
|
||||
}
|
||||
|
||||
if($this->debugMode) {
|
||||
foreach($this->elementRequired as $k => $v) {
|
||||
if(!array_key_exists($v, $mergedElement) && !isset($mergedElement['handlers'])) {
|
||||
$this->debugOutput("Element is missing required field after initialization: [ $v ].");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// iterate through "handlers - mini-elements"
|
||||
if(isset($mergedElement['handlers'])) {
|
||||
if(is_array($mergedElement['handlers']) && !empty($mergedElement['handlers'])) {
|
||||
foreach($mergedElement['handlers'] as $miniKey => $miniElement) {
|
||||
// apply parent element's properties to mini-element
|
||||
foreach($mergedElement as $key => $el) {
|
||||
if($key != 'handlers' && (!isset($miniElement[$key]))) {// || empty($miniElement[$key])
|
||||
$miniElement[$key] = $mergedElement[$key];
|
||||
}
|
||||
}
|
||||
|
||||
$miniElement = $this->initElement($miniElement, $alwaysMerge);
|
||||
$mergedElement['handlers'][$miniKey] = $miniElement;
|
||||
}
|
||||
} else {
|
||||
if($this->debugMode) {
|
||||
$this->debugOutput("SugarRouting: element contains 'handlers' but is not an array:");
|
||||
$this->debugOutput($mergedElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $mergedElement;
|
||||
} else {
|
||||
if($this->debugMode) {
|
||||
$this->debugOutput("SugarRouting is trying to initialize a non-element:");
|
||||
$this->debugOutput($element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that required metadata is present for all dependencies. Called after all metadata defaults are merged
|
||||
* and the final array is created.
|
||||
* @param array $metadata
|
||||
* @return bool
|
||||
*/
|
||||
function verifyMetadata($metadata) {
|
||||
if(isset($metadata['elements']) && !empty($metadata['elements']) && is_array($metadata['elements'])) {
|
||||
$elements = $metadata['elements'];
|
||||
|
||||
foreach($elements as $indexName => $element) {
|
||||
/* confirm each element has a valid type */
|
||||
if(!isset($element['type']) && in_array($element['type'], $this->validTypes)) {
|
||||
if($this->debugMode) {
|
||||
$this->debugOutput("SugarRouting: valid 'type' not found:"); $this->debugOutput($element);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/************************************************
|
||||
* Check based on "type"
|
||||
*/
|
||||
switch($element['type']) {
|
||||
case "select":
|
||||
if(isset($element['values'])) {
|
||||
$index = substr($indexName, 7, strlen($indexName));
|
||||
|
||||
|
||||
/* if we have an array to iterate through - this is not the case with lazy-loaded values */
|
||||
if(is_array($element['values']) && !empty($element['values'])) {
|
||||
$index++; // string to int conversion, i know, sucks
|
||||
$nextElementKey = "element".$index;
|
||||
$nextElement = $elements[$nextElementKey];
|
||||
|
||||
foreach($element['values'] as $key => $value) {
|
||||
if(!array_key_exists($key, $nextElement['handlers'])) {
|
||||
if($this->debugMode) {
|
||||
$this->debugOutput("SugarRouting: next-order element is missing a handler for value: [ {$key} ]");
|
||||
$this->debugOutput($elements);
|
||||
$this->debugOutput($nextElement);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if($this->debugMode) {
|
||||
$this->debugOutput("SugarRouting: 'select' element found, no 'values' defined."); $this->debugOutput($element);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
break; // end "select" check
|
||||
}
|
||||
|
||||
/*
|
||||
* Handler "handlers" mini-element metadata definition verification
|
||||
*/
|
||||
if(isset($element['handlers']) && !empty($element['handlers'])) {
|
||||
// fake metadata container
|
||||
$fakeMetadata = array('elements' => null);
|
||||
$fakeMetadata['elements'] = $element['handlers'];
|
||||
$result = $this->verifyMetadata($fakeMetadata);
|
||||
|
||||
if(!$result) {
|
||||
if($this->debugMode) {
|
||||
$this->debugOutput("SugarRouting: metadata verification for 'handlers' failed: "); $this->debugOutput($fakeMetadata);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($this->debugMode) {
|
||||
$this->debugOutput((count($metadata) > 1) ? "SugarRouting: all checks passed, valid metadata confirmed" : "SugarRouting: 'handlers' checks passed, valid metadata confirmed.");
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
if($this->debugMode) {
|
||||
$this->debugOutput("SugarRouting: Your metadata does not contain a valid 'elements' array:");$this->debugOutput($metadata);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints debug messages to the screen
|
||||
* @param mixed
|
||||
*/
|
||||
function debugOutput($v) {
|
||||
echo "\n<pre>\n";
|
||||
print_r($v);
|
||||
echo "\n</pre>\n";
|
||||
}
|
||||
//// END PRIVATE UTILS
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
} // end Class def
|
||||
@@ -0,0 +1,52 @@
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
SUGAR.dependentDropdown={currentAction:null,debugMode:false}
|
||||
SUGAR.dependentDropdown.handleDependentDropdown=function(el){}
|
||||
SUGAR.dependentDropdown.generateElement=function(focusElement,elementRow,index,elementIndex){if(SUGAR.dependentDropdown.debugMode)SUGAR.dependentDropdown.utils.debugStack('generateElement');var tmp=null;if(focusElement){var sandbox=SUGAR.dependentDropdown.utils.generateElementContainer(focusElement,elementRow,index,elementIndex);if(focusElement.label){focusLabel={tag:'span',cls:'routingLabel',html:" "+focusElement.label+" "}
|
||||
switch(focusElement.label_pos){case"top":focusLabel.html=focusElement.label+"<br />";break;case"bottom":focusLabel.html="<br />"+focusElement.label;break;}
|
||||
if(focusElement.label_pos=='left'||focusElement.label_pos=='top'){YAHOO.ext.DomHelper.append(sandbox,focusLabel);}}
|
||||
switch(focusElement.type){case'input':if(typeof(focusElement.values)=='string'){focusElement.values=eval(focusElement.values);}
|
||||
var preselect=SUGAR.dependentDropdown.utils.getPreselectKey(focusElement.name);if(preselect.match(/::/))
|
||||
preselect='';tmp=YAHOO.ext.DomHelper.append(sandbox,{tag:'input',id:focusElement.grouping+"::"+index+":::"+elementIndex+":-:"+focusElement.id,name:focusElement.grouping+"::"+index+"::"+focusElement.name,cls:'input',onchange:focusElement.onchange,value:preselect},true);var newElement=tmp.dom;break;case'select':tmp=YAHOO.ext.DomHelper.append(sandbox,{tag:'select',id:focusElement.grouping+"::"+index+":::"+elementIndex+":-:"+focusElement.id,name:focusElement.grouping+"::"+index+"::"+focusElement.name,cls:'input',onchange:focusElement.onchange},true);var newElement=tmp.dom;if(typeof(focusElement.values)=='string'){focusElement.values=eval(focusElement.values);}
|
||||
var preselect=SUGAR.dependentDropdown.utils.getPreselectKey(focusElement.name);var i=0;for(var key in focusElement.values){var selected=(preselect==key)?true:false;newElement.options[i]=new Option(focusElement.values[key],key,selected);if(selected){newElement.options[i].selected=true;}
|
||||
i++;}
|
||||
break;case'none':break;case'checkbox':alert('implement checkbox pls');break;case'multiple':alert('implement multiple pls');break;default:if(SUGAR.dependentDropdown.dropdowns.debugMode){alert("Improper type defined: [ "+focusElement.type+"]");}
|
||||
return;break;}
|
||||
if(focusElement.label){if(focusElement.label_pos=='right'||focusElement.label_pos=='bottom'){YAHOO.ext.DomHelper.append(sandbox,focusLabel);}}
|
||||
try{newElement.onchange();}catch(e){if(SUGAR.dependentDropdown.dropdowns.debugMode){debugger;}}}else{}}
|
||||
SUGAR.dependentDropdown.utils={generateElementContainer:function(focusElement,elementRow,index,elementIndex){var oldElement=document.getElementById('elementContainer'+focusElement.grouping+"::"+index+":::"+elementIndex);if(oldElement){SUGAR.dependentDropdown.utils.removeChildren(oldElement);}
|
||||
var tmp=YAHOO.ext.DomHelper.append(elementRow,{tag:'span',id:'elementContainer'+focusElement.grouping+"::"+index+":::"+elementIndex},true);return tmp.dom;},getPreselectKey:function(elementName){try{if(SUGAR.dependentDropdown.currentAction.action[elementName]){return SUGAR.dependentDropdown.currentAction.action[elementName];}else{return'';}}catch(e){if(SUGAR.dependentDropdown.dropdowns.debugMode){}
|
||||
return'';}},debugStack:function(func){if(!SUGAR.dependentDropdown._stack){SUGAR.dependentDropdown._stack=new Array();}
|
||||
SUGAR.dependentDropdown._stack.push(func);},removeChildren:function(el){for(i=el.childNodes.length-1;i>=0;i--){if(el.childNodes[i]){el.removeChild(el.childNodes[i]);}}}}
|
||||
342
include/SugarDependentDropdown/metadata/dependentDropdown.php
Executable file
342
include/SugarDependentDropdown/metadata/dependentDropdown.php
Executable file
@@ -0,0 +1,342 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
/*********************************************************************************
|
||||
|
||||
* Description:
|
||||
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. All Rights
|
||||
* Reserved. Contributor(s): ______________________________________..
|
||||
*********************************************************************************/
|
||||
global $app_strings; // coming from an include in a method call
|
||||
global $current_user;
|
||||
|
||||
|
||||
require_once("include/SugarRouting/SugarRouting.php");
|
||||
|
||||
$ie = new InboundEmail();
|
||||
$rules = new SugarRouting($ie, $current_user);
|
||||
$actions = $rules->getActionsDOM();
|
||||
|
||||
$strings = array();
|
||||
foreach($app_strings as $k => $v) {
|
||||
if(strpos($k, "LBL_ROUTING_") !== false) {
|
||||
$strings[$k] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$sugarDependentDropdown = array(
|
||||
/*
|
||||
* Turn on heavy logging and report errors
|
||||
*/
|
||||
'debugMode' => false,
|
||||
|
||||
/**
|
||||
* This is the actions' dependent dropdown metadata for Email 2.0's Rules
|
||||
* Wizard
|
||||
*/
|
||||
'actions' => array(
|
||||
/*
|
||||
* The array values below will be merged into all elements and handlers.
|
||||
* This is a good way to set a global that is overridable at the
|
||||
* individual element level.
|
||||
*/
|
||||
'always_merge' => array(
|
||||
/*
|
||||
* This flag tells the render engine to display all elements when
|
||||
* called. If set to 'false', the engine will allow 'onchange' calls to
|
||||
* render subsequent elements.
|
||||
*/
|
||||
'force_render' => false,
|
||||
/*
|
||||
* Used by Email 2.0 - this helps zero in on the DD-type when we
|
||||
* merge it with a saved Rule.
|
||||
*/
|
||||
'actionType' => 'actions',
|
||||
/*
|
||||
* User defined function to call when an element's value is changed
|
||||
* (select type only)
|
||||
*/
|
||||
'onchange' => '',
|
||||
),
|
||||
/*
|
||||
* This array will contain as many elements as there are dependencies. It
|
||||
* will be iterated through. The key is used for ordering; the SDD class
|
||||
* will ksort() this array
|
||||
*/
|
||||
'elements' => array(
|
||||
/*
|
||||
* Initial dropdown. Define the necessaries.
|
||||
*/
|
||||
'element0' => array(
|
||||
/*
|
||||
* 'name' will be prepended by the 'grouping' value and a delimiter "::". It then will be prepended by
|
||||
* a numeric index in increments of 100. If the user inserts actions inbetween retrieved action rows,
|
||||
* the index will be 1/2 of the delta (i. e., "50" if inserted between index 0 and index 100).
|
||||
*
|
||||
* This element will have the following as it's name in the form:
|
||||
* "actionGroup::0::action0"
|
||||
* Subsequent elements will have the following:
|
||||
* "actionGroup::100::action0"
|
||||
*/
|
||||
'name' => 'action0', // name of form element
|
||||
/*
|
||||
* The above applies to "id" in addition to:
|
||||
* "id" will further be appended by ":::" and a numeric index in increments of 1 (0, 1, 2, 3, etc). This is
|
||||
* to allow us to identify which element is currently being acted upon.
|
||||
*
|
||||
* The example below will ultimately have the id "actionGroup::0::action0" in the DOM.
|
||||
*/
|
||||
'id' => 'action0', // id of form element - an internal index will be appended to this value 0, 100, 200, etc.
|
||||
/*
|
||||
* 'type' denotes what kind of form element you wish to display. Of course "select" (drop-down) is the
|
||||
* default.
|
||||
* Valid values are "select" | "input" (text) | "checkbox" | "none".
|
||||
*/
|
||||
'type' => 'select',
|
||||
/*
|
||||
* If using multiple dependent-dropdowns on a single page, you
|
||||
* must differentiate them via this flag. This value is
|
||||
* arbitrary, but must be different from other sets of DDs.
|
||||
*/
|
||||
'grouping' => 'actionGroup',
|
||||
/*
|
||||
* In the interests of keeping this simple, you can pass an associative array as the argument for values.
|
||||
* However, you may also pass a string which will be eval()'d in JS. You can write a custom function to
|
||||
* return a Javascript object as an associative array which will be iterated over and rendered as options
|
||||
* for a dropdown. The return must be a JS object.
|
||||
*/
|
||||
'values' => $actions, // assoc array of dropdown values, if a STRING, it will be eval'd to lazy load the values
|
||||
/*
|
||||
* The 'selected' value must match one of the keys in the above array. If lazy-loading through a JS
|
||||
* call, there is a chance race-condition that may result in the selected value not being defaulted. In
|
||||
* this case, preload the values into local memory and retrieve via a non-async JS call.
|
||||
*/
|
||||
'selected' => '', // initially selected value (key value)
|
||||
/*
|
||||
* This attribute should map to a JS method/function that is loaded and available. It will be called on
|
||||
* initialization and can cascade the results to this element's children (this is how Email 2.0 Rules
|
||||
* Wizard works). If force_render is set to true, this call will still be made.
|
||||
*/
|
||||
'onchange' => 'SUGAR.routing.handleDependentDropdown(this, \'actions\');', // javascript onchange() call
|
||||
/*
|
||||
* The text that can accompany this element. Any string value is valid. Simple HTML formatting will be
|
||||
* honored (<B>, <I>, <EM>, etc.).
|
||||
*/
|
||||
'label' => ' ',
|
||||
/*
|
||||
* This attribute dictates where the above text will display relative to this element. Valid values are
|
||||
* "top" | "bottom" | "left" | "right"
|
||||
*/
|
||||
'label_pos' => 'left',
|
||||
),
|
||||
|
||||
/*
|
||||
* Subsequent dropdown/form elements must contain an array keyed to dropdown1's selected value.
|
||||
* I.e.:
|
||||
* if 'values' is
|
||||
* array(
|
||||
* 'option1' => 'This is option one',
|
||||
* 'option2' => 'This is option two',
|
||||
* );
|
||||
* dropdown2 must contain an array 'handlers' keyed by "option1" and "option2"
|
||||
*/
|
||||
'element1' => array(
|
||||
'name' => 'action1', // name of form element
|
||||
'id' => 'action1', // id of form element - an internal index will be appended to this value 0, 100, 200, etc.
|
||||
'label' => '', // label to be displayed next/above dropdown
|
||||
'label_pos' => 'none', // default 'left'
|
||||
'grouping' => 'actionGroup',
|
||||
/*
|
||||
* Correspond to the values in the preceding element for dependencies
|
||||
* - will be merged with parent's values (minus 'handlers' values)
|
||||
* - keys will override parent values
|
||||
*/
|
||||
'handlers' => array(
|
||||
/*
|
||||
* If the selected value is all that you are interested in,
|
||||
* create blank arrays like below. In this particular case
|
||||
* the form element "action1" will hold the value
|
||||
* "mark_read" which will be passed when the form is
|
||||
* submitted.
|
||||
*/
|
||||
'mark_read' => array(),
|
||||
'mark_unread' => array(),
|
||||
'mark_flagged' => array(),
|
||||
/*
|
||||
* If further processing is required (like more dropdowns
|
||||
* or input fields), create handlers that have "onchange"
|
||||
* handlers to further process subsequent elements.
|
||||
*
|
||||
* See SUGAR.routing.handleDependentDropdown() found in
|
||||
* "include/SugarDependentDropdown/javascript/SugarDependentDropdown.
|
||||
* js" for an example of how to continue cascading the
|
||||
* dropdowns.
|
||||
*/
|
||||
'move_mail' => array(
|
||||
//'name' => 'move_email_select',
|
||||
'type' => 'select', // create a 2nd order dropdown
|
||||
'values' => 'SUGAR.routing.ui.getElementValues("move_mail");',
|
||||
'label' => $strings['LBL_ROUTING_TO'], // label to be displayed next/above dropdown
|
||||
'label_pos' => 'left', // show "to" before this dropdown the dropdown
|
||||
//'onchange' => '', // override to prevent double-triggering of setup cascade calls
|
||||
),
|
||||
'copy_mail' => array(
|
||||
'type' => 'select', // create a 2nd order dropdown
|
||||
'values' => 'SUGAR.routing.ui.getElementValues("move_mail");',
|
||||
'label' => $strings['LBL_ROUTING_TO'], // label to be displayed next/above dropdown
|
||||
'label_pos' => 'left', // show "to" before this dropdown the dropdown
|
||||
),
|
||||
|
||||
'forward' => array(
|
||||
'type' => 'input',
|
||||
'label' => $strings['LBL_ROUTING_TO_ADDRESS'],
|
||||
'label_pos' => 'left',
|
||||
),
|
||||
'reply' => array(
|
||||
'type' => 'select',
|
||||
'label' => $strings['LBL_ROUTING_WITH_TEMPLATE'],
|
||||
'label_pos' => 'left',
|
||||
'values' => 'SUGAR.routing.ui.getElementValues("email_templates");',
|
||||
),
|
||||
|
||||
'delete_mail' => array(
|
||||
'onchange' => 'SUGAR.routing.handleDependentDropdown(this, \'actions\');', // javascript onchange() call
|
||||
'type' => 'none',
|
||||
),
|
||||
|
||||
|
||||
/* not implemented yet
|
||||
'delete_bean' => array(
|
||||
'onchange' => 'SUGAR.routing.handleDependentDropdown(this, \'actions\');', // javascript onchange() call
|
||||
),
|
||||
'delete_file' => array(
|
||||
'onchange' => 'SUGAR.routing.handleDependentDropdown(this, \'actions\');', // javascript onchange() call
|
||||
),*/
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
/**
|
||||
* This is the criteria dependent dropdown metadata for Email 2.0's Rules
|
||||
* Wizard
|
||||
*/
|
||||
'criteria' => array(
|
||||
'always_merge' => array(
|
||||
'force_render' => false,
|
||||
'grouping' => 'criteriaGroup',
|
||||
'onchange' => 'SUGAR.routing.handleDependentDropdown(this, \'criteria\');', // javascript onchange() call
|
||||
'label' => ' ',
|
||||
'label_pos' => 'left',
|
||||
'actionType' => 'criteria',
|
||||
),
|
||||
'elements' => array(
|
||||
'element0' => array(
|
||||
'name' => 'crit0', // name of form element
|
||||
'id' => 'crit0id', // id of form element - an internal index will be appended to this value 0, 100, 200, etc.
|
||||
'type' => 'select',
|
||||
'values' => 'SUGAR.routing.matchDom;', // assoc array of dropdown values, if a STRING, it will be eval'd to lazy load the values
|
||||
'selected' => '', // initially selected value (key value)
|
||||
),
|
||||
'element1' => array(
|
||||
'name' => 'crit1',
|
||||
'id' => 'crit1id',
|
||||
'type' => 'select',
|
||||
'values' => 'SUGAR.routing.matchTypeDom;',
|
||||
'handlers' => array(
|
||||
'from_addr' => array(),
|
||||
'to_addr' => array(),
|
||||
'cc_addr' => array(),
|
||||
'name' => array(),
|
||||
'description' => array(),
|
||||
'priority_high' => array(
|
||||
'type' => 'none',
|
||||
'label' => $app_strings['LBL_ROUTING_FLAGGED'],
|
||||
),
|
||||
'priority_normal' => array(
|
||||
'type' => 'none',
|
||||
'label' => $app_strings['LBL_ROUTING_FLAGGED'],
|
||||
),
|
||||
'priority_low' => array(
|
||||
'type' => 'none',
|
||||
'label' => $app_strings['LBL_ROUTING_FLAGGED'],
|
||||
),
|
||||
),
|
||||
),
|
||||
'element2' => array(
|
||||
'name' => 'crit2',
|
||||
'id' => 'crit2id',
|
||||
'type' => 'input',
|
||||
'values' => '',
|
||||
),
|
||||
),
|
||||
),
|
||||
/**
|
||||
* This is the "simple" (non-cascasding, force-rendered) version of the
|
||||
* above. It has since been deprecated, but is useful to demonstrate
|
||||
* how to make relatively static dependent dropdown.
|
||||
*/
|
||||
'criteriaSimple' => array(
|
||||
'always_merge' => array(
|
||||
'force_render' => true,
|
||||
'grouping' => 'criteriaGroup',
|
||||
'onchange' => '', // javascript onchange() call
|
||||
'label' => ' ',
|
||||
'label_pos' => 'left',
|
||||
),
|
||||
'elements' => array(
|
||||
'element0' => array(
|
||||
'name' => 'crit0', // name of form element
|
||||
'id' => 'crit0id', // id of form element - an internal index will be appended to this value 0, 100, 200, etc.
|
||||
'type' => 'select',
|
||||
'values' => 'SUGAR.routing.matchDom;', // assoc array of dropdown values, if a STRING, it will be eval'd to lazy load the values
|
||||
'selected' => '', // initially selected value (key value)
|
||||
),
|
||||
'element1' => array(
|
||||
'name' => 'crit1',
|
||||
'id' => 'crit1id',
|
||||
'type' => 'select',
|
||||
'values' => 'SUGAR.routing.matchTypeDom;',
|
||||
),
|
||||
'element2' => array(
|
||||
'name' => 'crit2',
|
||||
'id' => 'crit2id',
|
||||
'type' => 'input',
|
||||
'values' => '',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
Reference in New Issue
Block a user