Skip to content

Commit

Permalink
Add callback for ProjectVariable.fields.value field.
Browse files Browse the repository at this point in the history
polemarch/ce#222
  • Loading branch information
akhmadullin committed Aug 6, 2019
1 parent dbe605e commit 25d29d5
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions polemarch/static/js/pmProjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,4 +394,40 @@ tabSignal.connect("views[/project/].filters.beforeInit", filters => {
filter.enum = [''].concat(app.models['Project'].fields.status.options.enum);
}
}
});

/**
* Variable, that stores pairs (key, value), where:
* - key - value of the 'key' field of ProjectVariable model;
* - value - value of the 'value' field of ProjectVariable model.
*/
var ProjectVariable_value_from_key = {
ci_template: {
additionalProperties: {
list_paths: ["/project/{" + path_pk_key + "}/template/"],
view_field: 'name',
value_field: 'id',
}
},
};

/**
* Function - onchange callback of dynamic field - ProjectVariable.fields.value.
* @param {object} parent_values Values of parent fields.
*/
function ProjectVariable_value_callback(parent_values={}) {
if(parent_values.key && Object.keys(ProjectVariable_value_from_key).includes(parent_values.key)) {
return ProjectVariable_value_from_key[parent_values.key];
}

return {};
}

/**
* Adds callback for dynamic 'value' field of ProjectVariable model.
*/
tabSignal.connect("models[ProjectVariable].fields.beforeInit", (fields) => {
if(fields['value'] && fields['value'].additionalProperties) {
fields['value'].additionalProperties.callback = ProjectVariable_value_callback;
}
});

0 comments on commit 25d29d5

Please sign in to comment.