/** * Magento * * NOTICE OF LICENSE * * This source file is subject to the Academic Free License (AFL 3.0) * that is bundled with this package in the file LICENSE_AFL.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/afl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@magento.com so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade Magento to newer * versions in the future. If you wish to customize Magento for your * needs please refer to http://www.magento.com for more information. * * @category Mage * @package Mage_Adminhtml * @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ var VarienRulesForm = new Class.create(); VarienRulesForm.prototype = { initialize : function(parent, newChildUrl){ this.parent = $(parent); this.newChildUrl = newChildUrl; this.shownElement = null; this.updateElement = null; this.chooserSelectedItems = $H({}); this.readOnly = false; var elems = this.parent.getElementsByClassName('rule-param'); for (var i=0; i=0) { // var str = elem.options[elem.selectedIndex].text; // label.innerHTML = str!='' ? str : '...'; // } } elem = Element.down(container, 'input.input-text'); if (elem) { var str = elem.value.replace(/(^\s+|\s+$)/g, ''); elem.value = str; if (str=='') { str = '...'; } else if (str.length>30) { str = str.substr(0, 30)+'...'; } label.innerHTML = str.escapeHTML(); } } else { elem = Element.down(container, '.element-value-changer'); if (elem.value) { this.addRuleNewChild(elem); } elem.value = ''; } if (elem && elem.id && elem.id.match(/__value$/)) { this.hideChooser(container, event); this.updateElement = null; } this.shownElement = null; }, addRuleNewChild: function (elem) { var parent_id = elem.id.replace(/^.*__(.*)__.*$/, '$1'); var children_ul = $(elem.id.replace(/__/g, ':').replace(/[^:]*$/, 'children').replace(/:/g, '__')); var max_id = 0, i; var children_inputs = Selector.findChildElements(children_ul, $A(['input.hidden'])); if (children_inputs.length) { children_inputs.each(function(el){ if (el.id.match(/__type$/)) { i = 1 * el.id.replace(/^.*__.*?([0-9]+)__.*$/, '$1'); max_id = i > max_id ? i : max_id; } }); } var new_id = parent_id + '--' + (max_id + 1); var new_type = elem.value; var new_elem = document.createElement('LI'); new_elem.className = 'rule-param-wait'; new_elem.innerHTML = Translator.translate('Please wait, loading...'); children_ul.insertBefore(new_elem, $(elem).up('li')); new Ajax.Request(this.newChildUrl, { evalScripts: true, parameters: {form_key: FORM_KEY, type:new_type.replace('/','-'), id:new_id }, onComplete: this.onAddNewChildComplete.bind(this, new_elem), onSuccess: function(transport) { if(this._processSuccess(transport)) { $(new_elem).update(transport.responseText); } }.bind(this), onFailure: this._processFailure.bind(this) }); }, _processSuccess : function(transport) { if (transport.responseText.isJSON()) { var response = transport.responseText.evalJSON() if (response.error) { alert(response.message); } if(response.ajaxExpired && response.ajaxRedirect) { setLocation(response.ajaxRedirect); } return false; } return true; }, _processFailure : function(transport) { location.href = BASE_URL; }, onAddNewChildComplete: function (new_elem) { if (this.readOnly) { return false; } $(new_elem).removeClassName('rule-param-wait'); var elems = new_elem.getElementsByClassName('rule-param'); for (var i=0; i