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 567dea5449 Mostly make the editor UI for triggers work
Summary:
Ref T5474. This provides a Herald-like UI for editing workboard trigger rules.

This probably has some missing pieces and doesn't actually save anything to the database yet, but the basics at least roughly work.

Test Plan: {F6299886}

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T5474

Differential Revision: https://secure.phabricator.com/D20301
2019-03-25 13:25:14 -07:00

140 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);
JX.DOM.listen(control, 'onchange', null, on_change);
var attributes = {
className: 'type-cell'
};
this._typeCell = JX.$N('td', attributes, control);
}
return this._typeCell;
},
_onTypeChange: function() {
var control = this._getTypeCell();
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());
}
}
}
});