Path: blob/master/webroot/rsrc/js/application/trigger/TriggerRule.js
12242 views
/**1* @provides trigger-rule2* @javelin3*/45JX.install('TriggerRule', {67construct: function() {8},910properties: {11rowID: null,12type: null,13value: null,14editor: null,15isValidRule: true,16invalidView: null17},1819statics: {20newFromDictionary: function(map) {21return new JX.TriggerRule()22.setType(map.type)23.setValue(map.value)24.setIsValidRule(map.isValidRule)25.setInvalidView(map.invalidView);26},27},2829members: {30_typeCell: null,31_valueCell: null,32_readValueCallback: null,3334newRowContent: function() {35if (!this.getIsValidRule()) {36var invalid_cell = JX.$N(37'td',38{39colSpan: 2,40className: 'invalid-cell'41},42JX.$H(this.getInvalidView()));4344return [invalid_cell];45}4647var type_cell = this._getTypeCell();48var value_cell = this._getValueCell();495051this._rebuildValueControl();5253return [type_cell, value_cell];54},5556getValueForSubmit: function() {57this._readValueFromControl();5859return {60type: this.getType(),61value: this.getValue()62};63},6465_getTypeCell: function() {66if (!this._typeCell) {67var editor = this.getEditor();68var types = editor.getTypes();6970var options = [];71for (var ii = 0; ii < types.length; ii++) {72var type = types[ii];7374if (!type.getIsSelectable()) {75continue;76}7778options.push(79JX.$N('option', {value: type.getType()}, type.getName()));80}8182var control = JX.$N('select', {}, options);8384control.value = this.getType();8586var on_change = JX.bind(this, this._onTypeChange, control);87JX.DOM.listen(control, 'change', null, on_change);8889var attributes = {90className: 'type-cell'91};9293this._typeCell = JX.$N('td', attributes, control);94}9596return this._typeCell;97},9899_onTypeChange: function(control) {100var new_type = control.value;101102this.setType(new_type);103104// Before we build a new control, change the rule value to be appropriate105// for the new rule type.106107// TODO: Currently, we set the rule value to the default value for the108// type. This works most of the time, but if the user selects type "A",109// makes a change to the value, selects type "B", then changes back to110// type "A", it would be better to retain their edit. This is currently111// difficult because of tokenizers: if you save their value, you get a112// list of PHIDs which do not restore cleanly into tokens later.113114var editor = this.getEditor();115var type = editor.getType(new_type);116this.setValue(type.getDefaultValue());117118this._rebuildValueControl();119},120121_getValueCell: function() {122if (!this._valueCell) {123var attributes = {124className: 'value-cell'125};126127this._valueCell = JX.$N('td', attributes);128}129130return this._valueCell;131},132133_rebuildValueControl: function() {134var value_cell = this._getValueCell();135136var editor = this.getEditor();137var type = editor.getType(this.getType());138var control = type.getControl();139140var input = control.newInput(this);141this._readValueCallback = input.get;142143JX.DOM.setContent(value_cell, input.node);144},145146_readValueFromControl: function() {147if (this._readValueCallback) {148this.setValue(this._readValueCallback());149}150}151152}153154});155156157