1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-10-23 17:18:51 +02:00
phorge-phorge/webroot/rsrc/js/application/trigger/TriggerRule.js
epriestley f6658bf391 When changing the trigger type in the trigger editor, properly redraw the control
Summary: Ref T13269. I refactored this late in the game to organize things better and add table cells around stuff, and accidentally broke the relationship between the "Rule Type" selector and the value selector.

Test Plan: Switched rule type selector from "Change Status" to "Play Sound", saw secondary control update properly.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13269

Differential Revision: https://secure.phabricator.com/D20326
2019-03-26 11:50:31 -07:00

138 lines
2.8 KiB
JavaScript

/**
* @provides trigger-rule
* @javelin
*/
JX.install('TriggerRule', {
construct: function() {
},
properties: {
rowID: null,
type: null,
value: null,
editor: null,
isValidRule: true,
invalidView: null
},
statics: {
newFromDictionary: function(map) {
return new JX.TriggerRule()
.setType(map.type)
.setValue(map.value)
.setIsValidRule(map.isValidRule)
.setInvalidView(map.invalidView);
},
},
members: {
_typeCell: null,
_valueCell: null,
_readValueCallback: null,
newRowContent: function() {
if (!this.getIsValidRule()) {
var invalid_cell = JX.$N(
'td',
{
colSpan: 2,
className: 'invalid-cell'
},
JX.$H(this.getInvalidView()));
return [invalid_cell];
}
var type_cell = this._getTypeCell();
var value_cell = this._getValueCell();
this._rebuildValueControl();
return [type_cell, value_cell];
},
getValueForSubmit: function() {
this._readValueFromControl();
return {
type: this.getType(),
value: this.getValue()
};
},
_getTypeCell: function() {
if (!this._typeCell) {
var editor = this.getEditor();
var types = editor.getTypes();
var options = [];
for (var ii = 0; ii < types.length; ii++) {
var type = types[ii];
if (!type.getIsSelectable()) {
continue;
}
options.push(
JX.$N('option', {value: type.getType()}, type.getName()));
}
var control = JX.$N('select', {}, options);
control.value = this.getType();
var on_change = JX.bind(this, this._onTypeChange, control);
JX.DOM.listen(control, 'change', null, on_change);
var attributes = {
className: 'type-cell'
};
this._typeCell = JX.$N('td', attributes, control);
}
return this._typeCell;
},
_onTypeChange: function(control) {
this.setType(control.value);
this._rebuildValueControl();
},
_getValueCell: function() {
if (!this._valueCell) {
var attributes = {
className: 'value-cell'
};
this._valueCell = JX.$N('td', attributes);
}
return this._valueCell;
},
_rebuildValueControl: function() {
var value_cell = this._getValueCell();
var editor = this.getEditor();
var type = editor.getType(this.getType());
var control = type.getControl();
var input = control.newInput(this);
this._readValueCallback = input.get;
JX.DOM.setContent(value_cell, input.node);
},
_readValueFromControl: function() {
if (this._readValueCallback) {
this.setValue(this._readValueCallback());
}
}
}
});