1
0
Fork 0

GraphViewer: Create and Edit dialogs now the correct text on the submit button

This commit is contained in:
Michael Hackstein 2013-06-04 15:00:17 +02:00
parent 8a8dde506f
commit 555322214a
3 changed files with 74 additions and 60 deletions

View File

@ -39,7 +39,7 @@
"use strict";
describe('Event Dispatcher UI', function () {
var svg, dispatcherUI, list,
var svg, dispatcherUI, list, $list,
nodeShaper, edgeShaper, layouter,
nodes, edges, adapter,
mousePointerbox,
@ -133,7 +133,7 @@
list = document.createElement("ul");
document.body.appendChild(list);
list.id = "control_event_list";
$list = $(list);
mousePointerbox = document.createElement("svg");
mousePointerbox.id = "mousepointer";
mousePointerbox.className = "mousepointer";
@ -212,9 +212,9 @@
runs(function() {
dispatcherUI.addControlNewNode();
expect($("#control_event_list #control_event_newnode").length).toEqual(1);
expect($("#control_event_new_node", $list).length).toEqual(1);
helper.simulateMouseEvent("click", "control_event_newnode");
helper.simulateMouseEvent("click", "control_event_new_node");
expect(nodeShaper.changeTo).toHaveBeenCalledWith({
actions: {
@ -236,6 +236,8 @@
//$("#control_event_node_edit_name_value").val("Bob");
expect($("#control_event_new_node_submit").text()).toEqual("Create");
helper.simulateMouseEvent("click", "control_event_new_node_submit");
expect(adapter.createNode).toHaveBeenCalledWith(
@ -528,7 +530,7 @@
expect($("#control_event_list #control_event_expand").length).toEqual(1);
expect($("#control_event_list #control_event_delete").length).toEqual(1);
expect($("#control_event_list #control_event_connect").length).toEqual(1);
expect($("#control_event_list #control_event_newnode").length).toEqual(1);
expect($("#control_event_list #control_event_new_node").length).toEqual(1);
});
});

View File

@ -136,17 +136,17 @@ function EventDispatcherControls(list, cursorIconBox, nodeShaper, edgeShaper, di
});
this.addControlNewNode = function() {
var prefix = "control_event_newnode",
var prefix = "control_event_new_node",
idprefix = prefix + "_",
icon = "plus-sign",
createCallback = function(n) {
modalDialogHelper.createModalEditDialog(
modalDialogHelper.createModalCreateDialog(
"Create New Node",
"control_event_new_node_",
idprefix,
{},
function(data) {
dispatcher.events.CREATENODE(data, function() {
$("#control_event_new_node_modal").modal('hide');
$("#" + idprefix + "modal").modal('hide');
})();
}
);
@ -157,7 +157,7 @@ function EventDispatcherControls(list, cursorIconBox, nodeShaper, edgeShaper, di
rebindEdges();
rebindSVG({click: createCallback});
};
createIcon(icon, "newnode", callback);
createIcon(icon, "new_node", callback);
};

View File

@ -33,8 +33,62 @@ var modalDialogHelper = modalDialogHelper || {};
(function dialogHelper() {
"use strict";
modalDialogHelper.modalDivTemplate = function (title, idprefix, callback) {
var createDialogWithObject = function (title, buttonTitle, idprefix, object, callback) {
var tableToJSON,
callbackCapsule = function() {
callback(tableToJSON);
},
table = modalDialogHelper.modalDivTemplate(title, buttonTitle, idprefix, callbackCapsule);
tableToJSON = function() {
var result = {};
_.each($("#" + idprefix + "table tr"), function(tr) {
var key = tr.children[0].children[0].value,
value = tr.children[1].children[0].value;
result[key] = value;
});
return result;
};
_.each(object, function(value, key) {
var internalRegex = /^_(id|rev|key|from|to)/,
tr = document.createElement("tr"),
keyTh = document.createElement("th"),
valueTh = document.createElement("th"),
keyInput,
valueInput;
if (internalRegex.test(key)) {
return;
}
table.appendChild(tr);
tr.appendChild(keyTh);
keyTh.className = "collectionTh";
keyInput = document.createElement("input");
keyInput.type = "text";
keyInput.id = idprefix + key + "_key";
keyInput.value = key;
keyTh.appendChild(keyInput);
tr.appendChild(valueTh);
valueTh.className = "collectionTh";
valueInput = document.createElement("input");
valueInput.type = "text";
valueInput.id = idprefix + key + "_value";
valueInput.value = value;
valueTh.appendChild(valueInput);
}
);
$("#" + idprefix + "modal").modal('show');
};
modalDialogHelper.modalDivTemplate = function (title, buttonTitle, idprefix, callback) {
// Create needed Elements
buttonTitle = buttonTitle || "Switch";
var div = document.createElement("div"),
headerDiv = document.createElement("div"),
buttonDismiss = document.createElement("button"),
@ -78,7 +132,7 @@ var modalDialogHelper = modalDialogHelper || {};
buttonSubmit.id = idprefix + "submit";
buttonSubmit.className = "btn btn-success pull-right";
buttonSubmit.appendChild(document.createTextNode("Switch"));
buttonSubmit.appendChild(document.createTextNode(buttonTitle));
// Append in correct ordering
div.appendChild(headerDiv);
@ -111,7 +165,7 @@ var modalDialogHelper = modalDialogHelper || {};
};
modalDialogHelper.createModalDialog = function(title, idprefix, objects, callback) {
var table = modalDialogHelper.modalDivTemplate(title, idprefix, callback);
var table = modalDialogHelper.modalDivTemplate(title, null, idprefix, callback);
_.each(objects, function(o) {
var tr = document.createElement("tr"),
@ -161,53 +215,11 @@ var modalDialogHelper = modalDialogHelper || {};
};
modalDialogHelper.createModalEditDialog = function(title, idprefix, object, callback) {
var tableToJSON,
callbackCapsule = function() {
callback(tableToJSON);
},
table = modalDialogHelper.modalDivTemplate(title, idprefix, callbackCapsule);
tableToJSON = function() {
var result = {};
_.each($("#" + idprefix + "table tr"), function(tr) {
var key = tr.children[0].children[0].value,
value = tr.children[1].children[0].value;
result[key] = value;
});
return result;
};
_.each(object, function(value, key) {
var internalRegex = /^_(id|rev|key|from|to)/,
tr = document.createElement("tr"),
keyTh = document.createElement("th"),
valueTh = document.createElement("th"),
keyInput,
valueInput;
if (internalRegex.test(key)) {
return;
}
table.appendChild(tr);
tr.appendChild(keyTh);
keyTh.className = "collectionTh";
keyInput = document.createElement("input");
keyInput.type = "text";
keyInput.id = idprefix + key + "_key";
keyInput.value = key;
keyTh.appendChild(keyInput);
tr.appendChild(valueTh);
valueTh.className = "collectionTh";
valueInput = document.createElement("input");
valueInput.type = "text";
valueInput.id = idprefix + key + "_value";
valueInput.value = value;
valueTh.appendChild(valueInput);
}
);
$("#" + idprefix + "modal").modal('show');
createDialogWithObject(title, "Edit", idprefix, object, callback);
};
modalDialogHelper.createModalCreateDialog = function(title, idprefix, object, callback) {
createDialogWithObject(title, "Create", idprefix, object, callback);
};
}());