Merge pull request #17 from lostcharlie/master
Added validation of flow name.
This commit is contained in:
commit
168f37733e
|
@ -344,20 +344,23 @@ HAFlow.Main.prototype.onFlowClicked = function(instance, flowId) {
|
||||||
HAFlow.Main.prototype.saveFlowName = function(instance, flowId) {
|
HAFlow.Main.prototype.saveFlowName = function(instance, flowId) {
|
||||||
if (instance.flows[flowId]) {
|
if (instance.flows[flowId]) {
|
||||||
var value = $("#" + "flow_" + flowId + "_name").val();
|
var value = $("#" + "flow_" + flowId + "_name").val();
|
||||||
instance.flows[flowId].name = value;
|
if (this.checkFlowName(instance, instance.flows[flowId].name, value)) {
|
||||||
instance.getFlowBriefById(instance, flowId).name = value;
|
instance.flows[flowId].name = value;
|
||||||
var pane = dijit.byId("flowContainerPane_" + flowId);
|
instance.getFlowBriefById(instance, flowId).name = value;
|
||||||
pane.title = value;
|
var pane = dijit.byId("flowContainerPane_" + flowId);
|
||||||
instance.ui.centerContainer.removeChild(pane);
|
pane.title = value;
|
||||||
instance.ui.centerContainer.addChild(pane);
|
instance.ui.centerContainer.removeChild(pane);
|
||||||
instance.ui.centerContainer.selectChild(pane);
|
instance.ui.centerContainer.addChild(pane);
|
||||||
instance.flowListStore.remove(flowId);
|
instance.ui.centerContainer.selectChild(pane);
|
||||||
instance.flowListStore.put({
|
instance.flowListStore.remove(flowId);
|
||||||
id : instance.flows[flowId].id,
|
instance.flowListStore.put({
|
||||||
name : instance.flows[flowId].name,
|
id : instance.flows[flowId].id,
|
||||||
node : true
|
name : instance.flows[flowId].name,
|
||||||
});
|
node : true
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
HAFlow.showDialog("Error", "Invalid flow name");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
HAFlow.showDialog("Error",
|
HAFlow.showDialog("Error",
|
||||||
"Please load the flow before saving flow metadata!");
|
"Please load the flow before saving flow metadata!");
|
||||||
|
@ -401,7 +404,7 @@ HAFlow.Main.prototype.doAddModule = function(instance, flowId, moduleId, left,
|
||||||
newNode["id"] = id;
|
newNode["id"] = id;
|
||||||
newNode["flowId"] = flowId;
|
newNode["flowId"] = flowId;
|
||||||
newNode["moduleId"] = moduleId;
|
newNode["moduleId"] = moduleId;
|
||||||
newNode["name"] = "NewNode-" + id;
|
newNode["name"] = "Node-" + id;
|
||||||
newNode["position"] = {};
|
newNode["position"] = {};
|
||||||
newNode.position["left"] = left;
|
newNode.position["left"] = left;
|
||||||
newNode.position["top"] = top;
|
newNode.position["top"] = top;
|
||||||
|
@ -427,6 +430,23 @@ HAFlow.Main.prototype.checkNodeName = function(instance, flowId, oldName,
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
HAFlow.Main.prototype.checkFlowName = function(instance, oldName, newName) {
|
||||||
|
var i;
|
||||||
|
if (oldName == newName) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
var regex = /^[a-zA-Z_][a-zA-Z_0-9]{0,38}$/;
|
||||||
|
if (!regex.test(newName)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (i = 0; i < instance.flows.length; i++) {
|
||||||
|
if (newName == instance.flows[i].name) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
HAFlow.Main.prototype.paintFlow = function(flowId) {
|
HAFlow.Main.prototype.paintFlow = function(flowId) {
|
||||||
this.initJsPlumb(flowId);
|
this.initJsPlumb(flowId);
|
||||||
this.paintNodes(flowId);
|
this.paintNodes(flowId);
|
||||||
|
@ -846,7 +866,7 @@ HAFlow.Main.prototype.newFlow = function() {
|
||||||
var newFlowId = HAFlow.generateUUID();
|
var newFlowId = HAFlow.generateUUID();
|
||||||
this.flows[newFlowId] = {};
|
this.flows[newFlowId] = {};
|
||||||
this.flows[newFlowId].id = newFlowId;
|
this.flows[newFlowId].id = newFlowId;
|
||||||
this.flows[newFlowId].name = "New Flow";
|
this.flows[newFlowId].name = "NewFlow";
|
||||||
this.flows[newFlowId].nodes = new Array();
|
this.flows[newFlowId].nodes = new Array();
|
||||||
this.flows[newFlowId].edges = new Array();
|
this.flows[newFlowId].edges = new Array();
|
||||||
var _currentInstance = this;
|
var _currentInstance = this;
|
||||||
|
|
Loading…
Reference in New Issue