Commit a0b568dd authored by Jérome Perrin's avatar Jérome Perrin

GUI: temporarilly revert back to the same feature set as before the new format

Pre input module and Expandable field will be handled later
parent 48a0c148
......@@ -29,11 +29,7 @@
/////////////////////////////////////////////////////////////////
.declareMethod("render", function () {
var gadget = this;
return gadget.aq_allDocs({
"include_docs": true,
"query": 'type:= "Dream"',
"select_list": ["title", "modified"]
})
return gadget.aq_allDocs({"select_list": ["title", "modified"]})
.push(function (document_list) {
var result_list = [],
doc,
......@@ -75,6 +71,7 @@
parameter_list.sort(function (a, b) {
return b.date - a.date;
});
// gadget.props.element.querySelector('a').href = document_list[0];
gadget.props.element.querySelector('.document_list').innerHTML =
......
......@@ -42,8 +42,7 @@
throw error;
})
.push(function (sim_json) {
var document = JSON.parse(sim_json),
document_list = [],
var document_list = JSON.parse(sim_json),
result_list = [],
i;
if (document.result) {
......
......@@ -18,9 +18,8 @@
<script id="panel-template" type="text/x-handlebars-template">
<ul data-role="listview">
<li><a class="pre_input_link ui-btn ui-icon-grid ui-btn-icon-left" data-icon="grid">Documents</a></li>
<!--li><a class="home_link ui-btn ui-icon-home ui-btn-icon-left" data-icon="home">Documents</a></li-->
<!--li><a class="fast_input_link ui-btn ui-icon-plus ui-btn-icon-left" data-icon="plus">New Document</a></li-->
<li><a class="home_link ui-btn ui-icon-home ui-btn-icon-left" data-icon="home">Documents</a></li>
<li><a class="fast_input_link ui-btn ui-icon-plus ui-btn-icon-left" data-icon="plus">New Document</a></li>
{{#navigationlist}}
<li><a href="{{link}}">{{title}}</a></li>
{{/navigationlist}}
......
......@@ -16,14 +16,7 @@
/////////////////////////////////////////////////////////////////
// XXX we should use lists instead to keep ordering
var portal_types = {
"Pre Input Module": {
view: {
gadget: "InputModule_viewAddInstanceDefinitionDialog",
type: "object_fast_input",
title: "Choose Instance Definition"
}
}//,
/*"Input Module": {
"Input Module": {
"view": {
"gadget": "InputModule_viewInputList",
"type": "object_list",
......@@ -34,9 +27,9 @@
"type": "object_fast_input",
"title": "Create Document"
}
}*/
},
// TODO: remove this once everything is merged.
/*"Input": {
"Input": {
"view": {
"gadget": "Input_viewProductionLine",
"type": "object_view",
......@@ -45,61 +38,62 @@
"view_wip_part_spreadsheet": {
"gadget": "Input_viewWipPartSpreadsheet",
"type": "object_view",
"title": "WIP Part Spreadsheet",
"title": "WIP Part Spreadsheet" /* ,
"condition": function (gadget) {
console.log("-------------------+----------------------");
console.log(gadget);
console.log(gadget.props);
console.log(gadget.props.configuration_dict);
console.log("-------------------+----------------------");
return (gadget.props.configuration_dict['Dream-Configuration']
.gui.wip_part_spreadsheet);
}
*/
},
"view_shift_spreadsheet": {
"gadget": "Input_viewShiftSpreadsheet",
"type": "object_view",
"title": "Shift Spreadsheet",
"title": "Shift Spreadsheet" /* ,
"condition": function (gadget) {
return (gadget.props.configuration_dict['Dream-Configuration']
.gui.shift_spreadsheet);
}
*/
},
"view_available_capacity_spreadsheet": {
"gadget": "Input_viewAvailableCapacitySpreadsheet",
"type": "object_view",
"title": "Available Capacity Spreadsheet",
"title": "Available Capacity Spreadsheet" /* ,
"condition": function (gadget) {
return (gadget.props.configuration_dict['Dream-Configuration']
.gui.capacity_by_project_spreadsheet);
}
*/
},
"view_required_capacity_spreadsheet": {
"gadget": "Input_viewRequiredCapacitySpreadsheet",
"type": "object_view",
"title": "Required Capacity Spreadsheet",
"title": "Required Capacity Spreadsheet" /* ,
"condition": function (gadget) {
return (gadget.props.configuration_dict['Dream-Configuration']
.gui.capacity_by_station_spreadsheet);
}
*/
},
"view_dp_capacity_spreadsheet": {
"gadget": "Input_viewDemandPlanningCapacitySpreadsheet",
"type": "object_view",
"title": "Demand Planning Required Capacity Spreadsheet",
"title": "Demand Planning Required Capacity Spreadsheet" /* ,
"condition": function (gadget) {
return (gadget.props.configuration_dict['Dream-Configuration']
.gui.dp_capacity_spreadsheet);
}
*/
},
"view_dp_route_spreadsheet": {
"gadget": "Input_viewDemandPlanningRouteSpreadsheet",
"type": "object_view",
"title": "Demand Planning Route Spreadsheet",
"title": "Demand Planning Route Spreadsheet" /* ,
"condition": function (gadget) {
return (gadget.props.configuration_dict['Dream-Configuration']
.gui.dp_route_spreadsheet);
}
*/
},
"view_simu": {
"gadget": "Input_viewSimulation",
......@@ -117,80 +111,88 @@
"title": "Results"
}
},
"output": {
"Output": {
"view": {
"gadget": "Output_viewStationUtilisationGraph",
"type": "object_view",
"title": "Stations Utilization",
"title": "Stations Utilization" /* ,
"condition": function (gadget) {
return (gadget.props.configuration_dict['Dream-Configuration']
.gui.station_utilisation_graph);
}
*/
},
"download_excel_spreadsheet": {
"gadget": "Output_viewDownloadExcelSpreadsheet",
"type": "object_view",
"title": "Download Excel Spreadsheet",
"title": "Download Excel Spreadsheet" /* ,
"condition": function (gadget) {
return (gadget.props.configuration_dict['Dream-Configuration']
.gui.download_excel_spreadsheet);
}
*/
},
"view_capacity_utilization": {
"gadget": "Output_viewCapacityUtilisationGraph",
"type": "object_view",
"title": "Capacity Utilization",
"title": "Capacity Utilization" /* ,
"condition": function (gadget) {
return (gadget.props.configuration_dict['Dream-Configuration']
.gui.capacity_utilisation_graph);
}
*/
},
"view_queue_stat": {
"gadget": "Output_viewQueueStatGraph",
"type": "object_view",
"title": "Queues Statistics",
"title": "Queues Statistics" /* ,
"condition": function (gadget) {
return (gadget.props.configuration_dict['Dream-Configuration']
.gui.queue_stat);
}
*/
},
"view_exit_stat": {
"gadget": "Output_viewExitStatistics",
"type": "object_view",
"title": "Exit Statistics",
"title": "Exit Statistics" /* ,
"condition": function (gadget) {
return (gadget.props.configuration_dict['Dream-Configuration']
.gui.exit_stat);
}
*/
},
"view_gantt": {
"gadget": "Output_viewJobGantt",
"type": "object_view",
"title": "Job Gantt",
"title": "Job Gantt" /* ,
"condition": function (gadget) {
return (gadget.props.configuration_dict['Dream-Configuration']
.gui.job_gantt);
}
*/
},
"view_schedule": {
"gadget": "Output_viewJobScheduleSpreadsheet",
"type": "object_view",
"title": "Job Schedule",
"title": "Job Schedule" /* ,
"condition": function (gadget) {
return (gadget.props.configuration_dict['Dream-Configuration']
.gui.job_schedule_spreadsheet);
}
*/
},
"view_debug": {
"gadget": "Output_viewDebugJson",
"type": "object_view",
"title": "Debug JSON",
"title": "Debug JSON" /* ,
"condition": function (gadget) {
return (gadget.props.configuration_dict['Dream-Configuration']
.gui.debug_json);
}
*/
}
}*/
}
},
panel_template,
navigation_template,
......@@ -198,15 +200,7 @@
error_template,
gadget_klass = rJS(window);
function calculateTabHTML(gadget, options, key, title, active) {
/*console.log('________________________');
console.log(key);
console.log(gadget);
console.log(options);
console.log(title);
console.log(active);
console.log('________________________');*/
return new RSVP.Queue()
.push(function () {
var kw = {
......@@ -219,14 +213,6 @@
return gadget.aq_pleasePublishMyState(kw);
})
.push(function (url) {
/*console.log('<><><><><><><>><><><><><><><calculating tab url:');
console.log(key);
if (url === undefined) {
console.log('tab url:');
console.log(url);
} else {
console.log('undefined url');
}*/
var kw = {
title: title,
link: url
......@@ -243,9 +229,9 @@
function getNextLink(gadget, portal_type, options) {
var forward_kw = {action: options.action || "view"},
queue = new RSVP.Queue();
if (portal_type === "input") {
if (portal_type === "Input") {
forward_kw.id = options.id;
} else if (portal_type === "output") {
} else if (portal_type === "Output") {
forward_kw.id = options.id;
queue
.push(function () {
......@@ -266,7 +252,7 @@
forward_kw.result = current + 1;
}
});
} else if (portal_type !== "Pre Input Module") {
} else if (portal_type !== "Input Module") {
throw new Error("Unknown portal type: " + portal_type);
}
return queue.push(function () {
......@@ -276,9 +262,9 @@
function getTitle(gadget, portal_type, options) {
var title;
if (portal_type === "Pre Input Module") {
if (portal_type === "Input Module") {
title = "Documents";
} else if (portal_type === "input") {
} else if (portal_type === "Input") {
title = gadget.getDeclaredGadget("jio")
.push(function (jio_gadget) {
return jio_gadget.get({_id: options.id});
......@@ -286,7 +272,7 @@
.push(function (jio_doc) {
return jio_doc.data.title + " (" + jio_doc.data.modified + ")";
});
} else if (portal_type === "output") {
} else if (portal_type === "Output") {
title = gadget.getDeclaredGadget("jio")
.push(function (jio_gadget) {
return jio_gadget.getAttachment({
......@@ -295,7 +281,7 @@
});
})
.push(function (sim_json) {
var document_list = JSON.parse(sim_json).result.result_list;
var document_list = JSON.parse(sim_json);
return document_list[options.result].score + " " +
document_list[options.result].key;
});
......@@ -306,15 +292,6 @@
}
function calculateNavigationHTML(gadget, portal_type, options) {
/*console.log('.............................');
console.log(gadget);
console.log(portal_type);
console.log(options);
console.log(options.action);
console.log(portal_types[portal_type]);
console.log(portal_types[portal_type][options.action]);
console.log(portal_types[portal_type][options.action].type);
console.log('<<<<<<<<<<<<<<<<<<<<<<<<<<<<');*/
var nav_html,
action;
if (portal_types[portal_type][options.action].type ===
......@@ -335,16 +312,12 @@
);
}
}
}
}
/*console.log('url_list');
console.log(url_list);
console.log('>>>>>>>>>>>>>>>>>>>>>>>>');*/
return RSVP.all(url_list);
})
.push(function (entry_list) {
/*console.log('entry_list');
console.log(entry_list);*/
var i;
nav_html =
'<nav data-role="navbar" data-collapsible="true"><ul>';
......@@ -358,9 +331,6 @@
}
initGadgetMixin(gadget_klass);
/*console.log('AaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAa');
console.log(gadget_klass);
console.log('AaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAa');*/
gadget_klass
/////////////////////////////////////////////////////////////////
// Acquired methods
......@@ -413,22 +383,7 @@
return jio_gadget.getAttachment.apply(jio_gadget, param_list);
});
})
.allowPublicAcquisition("startListenTo", function (param_list) {
//console.log('arkoudesarkoudesarkoudesarkoudesarkoudes');
var obj, type, fn;
obj = param_list[0];
type = param_list[1];
fn = param_list[2];
if (obj.addEventListener) {
obj.addEventListener(type, fn, false);
} else if (obj.attachEvent) {
obj["e" + type + fn] = fn;
obj[type + fn] = function () {
obj["e" + type + fn](window.event);
};
obj.attachEvent("on" + type, obj[type + fn]);
}
})
.allowPublicAcquisition("whoWantsToDisplayHome", function () {
// Hey, I want to display some URL
return this.aq_pleasePublishMyState({});
......@@ -443,9 +398,6 @@
if (param_list[0] !== undefined) {
kw.id = param_list[0];
}
/*console.log(1010101010101);
console.log(kw);
console.log(param_list);*/
return this.aq_pleasePublishMyState(kw);
})
.allowPublicAcquisition("whoWantsToDisplayThisResult",
......@@ -454,9 +406,9 @@
// We'll display the result using the first enabled action
var action = "view", action_info, action_id;
for (action_id in portal_types.output) {
if (portal_types.output.hasOwnProperty(action_id)) {
action_info = portal_types.output[action_id];
for (action_id in portal_types.Output) {
if (portal_types.Output.hasOwnProperty(action_id)) {
action_info = portal_types.Output[action_id];
if ((action_info.condition === undefined) ||
(action_info.condition(this))) {
action = action_id;
......@@ -470,41 +422,6 @@
result: param_list[1]
});
})
.allowPublicAcquisition("getConfigurationDict", function () {
return this.props.configuration_dict;
})
.allowPublicAcquisition("configurationIsSet", function () {
this.props.configSet = true;
})
.allowPublicAcquisition("setConfigurationDict", function (conf_dict) {
this.props.configuration_dict = JSON.parse(conf_dict);
})
// Configure jIO to use localstorage
// And load configuration from server
.allowPublicAcquisition("getDefaultConfigurationDict", function () {
var jio_gadget, g = this;
//console.log('@@@@@@@@@@@@@@@getting DeclalredGadget@@@@@@@@@@@@@@@');
//console.log(g);
return g.getDeclaredGadget("jio")
/*.push(function (gadget) {
jio_gadget = gadget;
console.log(jio_gadget);
return jio_gadget.createJio({
type: "local",
username: "dream",
applicationname: "dream"
});
})*/
.push(function (gadget) {
jio_gadget = gadget;
// XXX Hardcoded relative URL
return jio_gadget.ajax({url: "../../getConfigurationDict"});
})
.push(function (evt) {
g.props.configuration_dict = JSON.parse(evt.target.responseText);
return g.props.configuration_dict;
});
})
/////////////////////////////////////////////////////////////////
// ready
......@@ -516,70 +433,42 @@
panel_template = Handlebars.compile(
document.getElementById("panel-template").innerHTML
);
//console.log(123123123123123);
//console.log('panel_template');
//console.log(document.getElementById("panel-template").innerHTML);
navigation_template = Handlebars.compile(
document.getElementById("navigation-template").innerHTML
);
/*console.log(123123123123);
console.log('navigation_template');
console.log(document.getElementById("navigation-template")
.innerHTML);*/
active_navigation_template = Handlebars.compile(
document.getElementById("active-navigation-template").innerHTML
);
/*console.log(123123123123);
console.log('active_navigation_template');
console.log(
document.getElementById("active-navigation-template").innerHTML
);*/
error_template = Handlebars.compile(
document.getElementById("error-template").innerHTML
);
/*console.log(123123123123);
console.log('error_template');
console.log(document.getElementById("error-template").innerHTML);*/
}
})
// Create some link on the page
.ready(function (g) {
//console.log('ggggggggggggggggggggg');
//console.log(g);
return new RSVP.Queue()
.push(function () {
//console.log('**********************************1');
//console.log(g);
return RSVP.all([
g.aq_pleasePublishMyState({}),
//g.aq_pleasePublishMyState({action: "view_fast_input"}),
g.aq_pleasePublishMyState({action: "view"})
g.aq_pleasePublishMyState({action: "view_fast_input"})
]);
})
.push(function (link_list) {
//console.log('____________________link_List*********************');
//console.log(link_list);
//console.log('_________________________*************************');
var panel = g.props.element.querySelector("#leftpanel");
panel.innerHTML =
panel_template({navigationlist: []});
panel.getElementsByClassName("pre_input_link")[0].href =
link_list[0];
//panel.getElementsByClassName("home_link")[0].href = link_list[0];
//panel.getElementsByClassName("fast_input_link")[0].href =
// link_list[1];
panel.getElementsByClassName("home_link")[0].href = link_list[0];
panel.getElementsByClassName("fast_input_link")[0].href =
link_list[1];
// XXX JQuery mobile
$(panel).trigger("create");
});
})
// Configure jIO to use localstorage
// And load configuration from server
.ready(function (g) {
//console.log('@@@@@@@@@@@@@@@getting DeclalredGadget@@@@@@@@@@@@@@@');
//console.log(g);
return g.getDeclaredGadget("jio")
.push(function (gadget) {
return gadget.createJio({
......@@ -587,33 +476,7 @@
username: "dream",
applicationname: "dream"
});
});
/*.push(function () {
g.props.configuration_dict = {
"Dream-Configuration": {
"_class": "Dream.Configuration",
"gui": {
"debug_json": 1,
"download_excel_spreadsheet": 0,
"exit_stat": 1,
"job_gantt": 0,
"job_schedule_spreadsheet": 0,
"queue_stat": 1,
"shift_spreadsheet": 0,
"station_utilisation_graph": 1,
"wip_part_spreadsheet": 0,
"wip_spreadsheet": 0
},
"property_list": [{
"_class": "Dream.Property",
"_default": 10,
"id": "numberOfReplications",
"name": "Number of replications",
"type": "number"
}]
}
};
});*/
});
})
/////////////////////////////////////////////////////////////////
......@@ -624,14 +487,12 @@
var gadget = this,
back_kw = {action: "view"},
page_gadget,
portal_type = "Pre Input Module",
portal_type = "Input Module",
nav_element = gadget.props.element
.getElementsByClassName("nav_container")[0],
element = gadget.props.element
.getElementsByClassName("gadget_container")[0];
console.log('!!!!!!!!!!!!!!!!!!!!!!options!!!!!!!!!!!!!!!!!!!!!!!');
console.log(options);
console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
if (options.action === undefined) {
// Redirect to the view action
options.action = "view";
......@@ -639,35 +500,18 @@
.push(gadget.pleaseRedirectMyHash.bind(gadget));
}
/*// if configuration_dict is defined
// then Pre Input Module should not be loaded
if (gadget.props.configSet === true) {
portal_type = "Input Module";
$('.pre_input_link').hide();
}*/
if (gadget.props.configSet === true) {
portal_types.input =
gadget.props.configuration_dict.application_configuration.input;
portal_types.output =
gadget.props.configuration_dict.application_configuration.output;
}
// Detect what is the kind of document displayed
if (options.id !== undefined) {
if (options.result === undefined) {
portal_type = "input";
portal_type = "Input";
} else {
portal_type = "output";
portal_type = "Output";
back_kw.action = "view_result";
back_kw.id = options.id;
}
}
console.log('__________________portal_types__________________');
console.log(portal_types);
console.log(portal_type);
console.log(options);
console.log(portal_types[portal_type]);
/*return gadget.getDeclaredGadget("jio")
return gadget.getDeclaredGadget("jio")
.push(function(jio_gadget) {
if (options.id) {
return jio_gadget.getAttachment({
......@@ -681,17 +525,14 @@
if (result) {
data = JSON.parse(result);
gadget.props.data = data;
portal_types.input = data.application_configuration.input;
portal_types.output = data.application_configuration.output;
portal_types.Input = data.application_configuration.input;
portal_types.Output = data.application_configuration.output;
}
// Get the action information
// Get the action information
return gadget.declareGadget(
portal_types[portal_type][options.action].gadget + ".html"
);
})*/
return gadget.declareGadget(
portal_types[portal_type][options.action].gadget + ".html"
)
})
.push(function (g) {
page_gadget = g;
if (page_gadget.render !== undefined) {
......@@ -706,9 +547,6 @@
getNextLink(gadget, portal_type, options)
]);
}).push(function (result_list) {
console.log('????????????????????????????????????????????');
console.log(result_list);
console.log('????????????????????????????????????????????');
var nav_html = result_list[1],
page_element = result_list[0];
......
/* ====================== listview checkbox ======================== */
/* allow checkbox and radio in split listview */
html body .ui-listview li.ui-li-has-checkbox {
padding-right: 2.25em;
border-top-right-radius: 0;
border-bottom-right-radius: 0;
-webkit-border-top-right-radius: 0;
-webkit-border-bottom-right-radius: 0;
}
html body .ui-listview li.ui-li-has-checkbox label {
border-left-width: 0px;
-moz-box-sizing: border-box;
}
html .ui-listview li.ui-li-has-alt a.ui-btn.ui-icon-caret-right:after,
html .ui-listview li.ui-li-has-alt a.ui-btn.ui-icon-carat-r:after {
content: "";
}
html .ui-listview li div.ui-radio,
html .ui-listview li div.ui-checkbox {
height: 100%;
margin: 0;
padding: 0;
position: absolute;
right: 0;
top: 0;
width: 2.5em;
z-index: 2;
}
html body .ui-listview li div.ui-radio label.ui-btn,
html body .ui-listview li div.ui-checkbox label.ui-btn {
border-radius: .375em;
height: 100%;
min-height: 1em;
padding: 0;
width: auto;
}
html body .ui-listview li div.ui-radio,
html body .ui-listview li div.ui-radio label.ui-btn,
html body .ui-listview li div.ui-checkbox,
html body .ui-listview li div.ui-checkbox label.ui-btn {
box-shadow: 0;
-webkit-box-shadow: 0;
border-radius: 0;
-webkit-border-radius: 0;
}
html body .ui-listview li.ui-first-child div.ui-radio,
html body .ui-listview li.ui-first-child div.ui-radio label.ui-btn,
html body .ui-listview li.ui-first-child div.ui-checkbox,
html body .ui-listview li.ui-first-child div.ui-checkbox label.ui-btn {
border-top-right-radius: .375em;
-webkit-border-top-right-radius: .375em;
}
html body .ui-listview li.ui-last-child div.ui-radio,
html body .ui-listview li.ui-last-child div.ui-radio label,
html body .ui-listview li.ui-last-child div.ui-checkbox,
html body .ui-listview li.ui-last-child div.ui-checkbox label {
border-bottom-right-radius: .375em;
-webkit-border-bottom-right-radius: .375em;
border-bottom-width: 1px;
margin-bottom: -1px;
}
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Choose Instance</title>
<link rel="stylesheet" href="InputModule_viewAddInstanceDefinitionDialog.css" />
<script src="../lib/rsvp.min.js" type="text/javascript"></script>
<script src="../<%= copy.handlebars.relative_dest %>" type="text/javascript"></script>
<script src="../lib/renderjs.min.js" type="text/javascript"></script>
<script src="mixin_gadget.js" type="text/javascript"></script>
<script src="mixin_promise.js" type="text/javascript"></script>
<script src="InputModule_viewAddInstanceDefinitionDialog.js" type="text/javascript"></script>
<script id="table-template" type="text/x-handlebars-template">
<ul data-role="listview" data-inset="true" class="document-listview">
{{#documentlist}}
<li>
<div>
<!--div class="ui-btn ui-input-btn">{{title}} -->
<input type="submit" value="{{title}}" name= "{{name}}">
</div>
<div class="ui-checkbox">
<label class="ui-corner-all ui-btn-inherit ui-btn-icon-left ui-icon-checkbox-off ui-checkbox-off">
<!--label class="ui-corner-all ui-btn-inherit"-->
<input type="checkbox" value="" name="{{name}}">
</label>
</div>
</li>
{{/documentlist}}
</ul>
</script>
</head>
<body>
<div class="ui-grid-a ui-responsive">
<div class="ui-block-a">
<form class="new_form">
<button type="submit" class="ui-btn ui-btn ui-btn-inline ui-icon-plus ui-btn-icon-right">Default</button>
</form>
<form class="import_form">
<input id="dream_import" type="file" required=""
name="dream_import" class="ui-btn ui-btn-b ui-btn-inline">
<button type="submit" class="ui-btn ui-btn ui-btn-inline ui-icon-plus ui-btn-icon-right">Import</button>
</form>
</div>
<div class="ui-block-b">
<form method="post" action="#">
<input type="hidden" name="method" value="delete_status" ></input>
<section class="document_list"></section>
<!--ul data-role="listview" class="document-list" data-inset="true"></ul-->
<div class="ui-input-btn ui-btn ui-icon-delete ui-btn-inline ui-btn-icon-left">
Delete
<input type="submit" data-enhanced="true" value="Delete">
</div>
</form>
</div>
</div>
</body>
</html>
/*global $, rJS, RSVP, promiseEventListener, promiseReadAsText,
initGadgetMixin, Handlebars, console */
(function (window, rJS, RSVP, promiseEventListener,
promiseReadAsText, initGadgetMixin, Handlebars) { /* Handlebars*/
"use strict";
// delete last session document
function removeLastSession(gadget, name) {
var now = new Date(), documents, element_list,
element, i, len, promise_list;
promise_list = [];
gadget.aq_allDocs({
"include_docs": true,
"query": 'type:= "DreamLastInstance"',
"select_list": ["title", "modified"]
})
.push(function (docs) {
documents = docs;
if (documents.data.total_rows === undefined) {
console.log("Last instance data is undefined");
} else if (documents.data.total_rows === 0) {
console.log("There is no record of DreamLastInstance type");
} else if (documents.data.total_rows > 0) {
//aq_remove should be performed here
element_list = documents.data.rows;
for (i = 0, len = element_list.length; i < len; i += 1) {
element = element_list[i];//.nextSibling;
promise_list[i] = gadget.aq_remove({"_id": element.id});
}
}
});
// create last instance jIO document
promise_list[promise_list.length] = gadget.aq_post({
title: name,
type: "DreamLastInstance",
format: "application/json",
modified: now.toUTCString(),
date: now.getFullYear() + "-" + (now.getMonth() + 1) + "-" +
now.getDate()
});
return RSVP.all(promise_list);
}
// create a jIO document
function createDocument(gadget, name) {
var now = new Date(), documents, element_list,
element, i, len, promise_list;
promise_list = [];
gadget.aq_allDocs({
"include_docs": true,
"query": 'type:= "DreamLastInstance"',
"select_list": ["title", "modified"]
})
.push(function (docs) {
documents = docs;
if (documents.data.total_rows === undefined) {
console.log("Last instance data is undefined");
} else if (documents.data.total_rows === 0) {
console.log("There is no record in the last",
"instance list, can proceed without deleting");
} else if (documents.data.total_rows > 0) {
//aq_remove should be performed here
element_list = documents.data.rows;
for (i = 0, len = element_list.length; i < len; i += 1) {
element = element_list[i];//.nextSibling;
promise_list[i] = gadget.aq_remove({"_id": element.id});
}
}
});
// Create jIO document
promise_list[promise_list.length] = gadget.aq_post({
title: name,
type: "DreamInstance",
format: "application/json",
modified: now.toUTCString(),
date: now.getFullYear() + "-" + (now.getMonth() + 1) + "-" +
now.getDate()
});
// create last instance jIO document
promise_list[promise_list.length] = gadget.aq_post({
title: name,
type: "DreamLastInstance",
format: "application/json",
modified: now.toUTCString(),
date: now.getFullYear() + "-" + (now.getMonth() + 1) + "-" +
now.getDate()
});
return RSVP.all(promise_list);
}
function waitForImport(gadget) {
// here import definition dict from a local file
var json_data, name;
return new RSVP.Queue()
.push(function () {
return promiseEventListener(
gadget.props.element.getElementsByClassName("import_form")[0],
"submit",
false
);
})
.push(function (evt) {
// Prevent double click
evt.target.getElementsByClassName("ui-btn")[0].disabled = true;
var file = evt.target.dream_import.files[0];
name = file.name;
return promiseReadAsText(file);
})
.push(function (json) {
json_data = json;
gadget.configurationIsSet(true);
gadget.setConfigurationDict(json_data);
return createDocument(gadget, name);
})
.push(function (jio_document_list) {
// Add JSON as attachment
return RSVP.all([
gadget.aq_putAttachment({
"_id": jio_document_list[0].id,
"_attachment": "body.json",
"_data": json_data,
"_mimetype": "application/json"
}),
gadget.aq_putAttachment({
"_id": jio_document_list[1].id,
"_attachment": "body.json",
"_data": json_data,
"_mimetype": "application/json"
})
]);
});
}
function waitForDefault(gadget) {
var name = "DefaultInstance", json_data = {};
return new RSVP.Queue()
.push(function () {
return promiseEventListener(
gadget.props.element.getElementsByClassName("new_form")[0],
"submit",
false
);
})
.push(function (evt) {
// Prevent double click
evt.target.getElementsByClassName("ui-btn")[0].disabled = true;
})
.push(function () {
//return gadget.getConfigurationDict();
return gadget.getDefaultConfigurationDict();
})
.push(function (data) {
json_data = data || {};
gadget.configurationIsSet(true);
return createDocument(gadget, name);
})
.push(function (jio_document_list) {
// Add JSON as attachment
return RSVP.all([
gadget.aq_putAttachment({
"_id": jio_document_list[0].id,
"_attachment": "body.json",
"_data": JSON.stringify(json_data),
"_mimetype": "application/json"
}),
gadget.aq_putAttachment({
"_id": jio_document_list[1].id,
"_attachment": "body.json",
"_data": JSON.stringify(json_data),
"_mimetype": "application/json"
})
]);
});
}
var gadget_klass = rJS(window),
source = gadget_klass.__template_element
.getElementById("table-template")
.innerHTML,
table_template = Handlebars.compile(source);
initGadgetMixin(gadget_klass);
gadget_klass.declareAcquiredMethod("aq_post", "jio_post")
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("aq_allDocs", "jio_allDocs")
.declareAcquiredMethod("aq_putAttachment", "jio_putAttachment")
.declareAcquiredMethod("aq_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("aq_remove", "jio_remove")
.declareAcquiredMethod("whoWantsToDisplayHome", "whoWantsToDisplayHome")
.declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash")
.declareAcquiredMethod("whoWantsToDisplayThisDocument",
"whoWantsToDisplayThisDocument")
.declareAcquiredMethod("aq_startListenTo", "startListenTo")
.declareAcquiredMethod("getConfigurationDict", "getConfigurationDict")
.declareAcquiredMethod("getDefaultConfigurationDict",
"getDefaultConfigurationDict")
.declareAcquiredMethod("configurationIsSet", "configurationIsSet")
.declareAcquiredMethod("setConfigurationDict", "setConfigurationDict")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.ready(function (gadget) {
gadget.state_parameter_dict = {};
})
.declareMethod("render", function () {
console.log("VIEWADDINSTANCE RENDER 1");
var gadget, doc_list, innerHTML;
gadget = this;
doc_list = gadget.props.element.querySelector(".document_list");
// helper: add options to selects
function makeListItems(row_list) {
console.log("MAKEDOCUMENTLIST 1");
var i, len, record, item, //button, box, label, fragment
param_list; //test;
param_list = [];
//fragment = document.createDocumentFragment();
len = row_list.length;
if (len === 1) {
if (row_list[0].doc === "none") {
item = document.createElement("div");
item.innerHTML = "no records";
doc_list.appendChild(item);
} else {
record = row_list[0].doc;
param_list[0] = {
title: record.title + " (" + record.date + ")",
name: "record_" + record._id,
date: new Date(record.date)
};
}
} else {
for (i = 0; i < len; i += 1) {
record = row_list[i].doc;
param_list[i] = {
title: record.title + " (" + record.date + ")",
name: "record_" + record._id,
date: new Date(record.date)
};
}
param_list.sort(function (a, b) {
return b.date - a.date;
});
}
innerHTML = table_template({
documentlist: param_list
});
console.log("MAKEDOCUMENTLIST 2");
//return fragment;
}
// helper: select a configuration dictionary from a doc
function handleDictSelect(e) {
var form, element, id, json_data;
//prevent default
e.preventDefault();
form = e.target;
element = form.querySelector("div.ui-focus");
if (element === null || element === "undefined") {
element = form.querySelector("input.ui-state-focus");
id = element.name.replace("record_", "");
} else {
id = element.childNodes[1].name.replace("record_", "");
}
return gadget.aq_getAttachment({
"_id": id,
"_attachment": "body.json"
})
.push(function (json) {
json_data = json;
gadget.configurationIsSet(true);
gadget.setConfigurationDict(json_data);
})
.push(function () {
console.log("to remove last session");
return removeLastSession(gadget);
})
.push(function (jio_document_list) {
// receive jio_document_list
return gadget.aq_putAttachment({
"_id": jio_document_list[0].id,
"_attachment": "body.json",
"_data": JSON.stringify(json_data),
"_mimetype": "application/json"
});
})
.push(function () {
return gadget.whoWantsToDisplayThisDocument(id);
})
.push(function (url) {
return gadget.pleaseRedirectMyHash(url);
});
}
// helper: delete a doc
function handleDelete(e) {
var form, element_list, promise_list, i, len,
element, list_element, id, fragment, $doc;
//prevent default
console.log("HANDLING DELETE 1");
e.preventDefault();
form = e.target;
promise_list = [];
element_list = form.querySelectorAll("label.ui-checkbox-on");
if (element_list) {
for (i = 0, len = element_list.length; i < len; i += 1) {
element = element_list[i].nextSibling;
id = element.name.replace("record_", "");
list_element = element.parentNode.parentNode.parentNode;
list_element.parentNode.removeChild(list_element);
if (form.querySelector("ul").children.length === 0) {
fragment = document.createElement("li");
fragment.innerHTML = "No records";
form.querySelector("ul").appendChild(fragment);
}
promise_list[i] = gadget.aq_remove({"_id": id});
}
// enhance/refresh
$doc = $(doc_list);
if ($doc.listview("instance")) {
$doc.listview("refresh");
}
}
console.log("HANDLING DELETE 2");
return RSVP.all(promise_list);
}
return gadget.aq_allDocs({
"include_docs": true,
"query": 'type:= "DreamInstance"',
"select_list": ["title", "modified"]
})
.push(function (document_list) {
var len, data, $doc;
data = document_list.data;
len = data.total_rows;
if (len > 0) {
makeListItems(data.rows);
} else {
makeListItems([{doc: "none"}]);
}
// append
while (doc_list.firstChild) {
doc_list.removeChild(doc_list.firstChild);
}
doc_list.innerHTML = innerHTML;
// enhance/refresh
$doc = $(doc_list);
if ($doc.listview("instance")) {
$doc.listview("refresh");
}
})
.push(function () {
console.log("VIEWADDINSTANCE RENDER 3");
if (!gadget.state_parameter_dict.bound) {
gadget.state_parameter_dict.bound = true;
return RSVP.all([
gadget.aq_startListenTo(
gadget.props.element.getElementsByTagName("FORM")[2],
"submit",
handleDelete
),
// XXXXXXXXXXXXXXXXXXXXX
gadget.aq_startListenTo(
gadget.props.element.getElementsByTagName("FORM")[2],
"submit",
handleDictSelect
)
]);
}
});/*.fail(console.log);*/
})
.declareMethod("startService", function () {
console.log("VIEWADDINSTANCE STARTSERVICE 1");
var gadget = this;
return new RSVP.Queue()
.push(function () {
return RSVP.any([ waitForImport(gadget), waitForDefault(gadget) ]);
})
.push(function (result) {
return gadget.whoWantsToDisplayThisDocument(result[0].id);
})
.push(function (url) {
console.log("VIEWADDINSTANCE STARTSERVICE 4");
return gadget.pleaseRedirectMyHash(url);
});
});
}(window, rJS, RSVP, promiseEventListener, promiseReadAsText,
initGadgetMixin, Handlebars)); /* Handlebars*/
\ No newline at end of file
/*global rJS, RSVP, jQuery, Handlebars,
promiseEventListener, initGadgetMixin, console */
promiseEventListener, initGadgetMixin*/
/*jslint nomen: true */
(function (window, rJS, RSVP, Handlebars, initGadgetMixin) {
"use strict";
......@@ -23,20 +23,15 @@
var gadget = this,
queue;
console.log("FIELDSET RENDER 1");
console.log(options);
console.log(node_id);
gadget.props.key = options.key; // used for recursive fieldsets
gadget.props.field_gadget_list = [];
function addField(property_id, property_definition,
value) {
function addField(property_id, property_definition, value) {
var sub_gadget;
queue
.push(function () {
// XXX this is incorrect for recursive fieldsets.
// we should use nested fieldset with legend
console.log("insertingAdjacentHTML for:" + property_id);
gadget.props.element.insertAdjacentHTML(
'beforeend',
label_template({
......@@ -46,22 +41,6 @@
property_id )
})
);
console.log("....................");
console.log(property_id);
console.log(property_definition);
console.log(value);
// XXX maybe type should be used instead
if (property_definition.allOf) {
// if there is type property then remove it
if (property_definition.allOf[0].type) {
delete property_definition.allOf[0].type;
}
return gadget.declareGadget("../expandable_field/index.html");
}
if (property_definition.properties) {
// Create a recursive fieldset for this key.
return gadget.declareGadget("../fieldset/index.html");
}
if (property_definition.type === "object") {
// Create a recursive fieldset for this key.
return gadget.declareGadget("../fieldset/index.html");
......@@ -93,82 +72,27 @@
queue = new RSVP.Queue()
.push(function () {
var reserved_keys = [];
if (node_id) {
addField('id', {'type': 'string'}, node_id);
}
Object.keys(options.property_definition.properties)
.forEach(function (property_name) {
var property_definition =
options.property_definition.properties[property_name],
value,
i=0, property,
index;
if (property_definition) {
value = property_definition.default || {};
if (property_definition.allOf) {
if (property_definition.allOf[0].properties) {
for (property in property_definition
.allOf[0].properties) {
if (property_definition.allOf[0]
.properties.hasOwnProperty(property)) {
i += 1;
if (i > 1) {console.log("something is wrong!");}
value = property_definition.allOf[0]
.properties[property].default;
}
}
}
}
}
console.log("TRYING TO FIND A VALUE!!!!");
console.log(options);
console.log(options.value);
console.log(property_name);
// XXX if the field is complex then the value may be complex
// eg options.value > "time_to_failure":{},"time_to_repair":{}...
// while the property_names are abstract as allOf_1 corresponding
// to (for example) time_to_failure
if (options.property_definition
.properties[property_name].allOf) {
if ((options.value || {})[property_name] === undefined) {
if (typeof options.value === 'object') {
if (Object.keys(options.value).length > 0) {
for (index = 0;
index < Object.keys(options.value).length-1;
index += 1) {
if (!(reserved_keys
.indexOf(Object.keys(options.value)[index])
> -1)) {
reserved_keys.push(
Object.keys(options.value)[index]
);
value =
options.value[Object.keys(options.value)[index]];
break;
}
}
}
}
}
}
Object.keys(options.property_definition.properties
).forEach(function (property_name) {
var property_definition =
options.property_definition.properties[property_name],
value = (options.value || {})[property_name] === undefined
? value : options.value[property_name];
if (property_name !== 'coordinate'
&& property_name !== '_class'
&& property_name !== 'id') {
? property_definition._default : options.value[property_name];
// XXX some properties are not editable
// XXX should not be defined here
addField(property_name, property_definition, value);
}
});
if (property_name !== 'coordinate' && property_name !== '_class') {
addField(property_name, property_definition, value);
}
});
});
return queue;
return queue;
})
// getContent of all subfields
.declareMethod("getContent", function () {
console.log("GET CONTENT SIMPLE FIELDSET");
var i, promise_list = [], gadget = this;
for (i = 0; i < this.props.field_gadget_list.length; i += 1) {
promise_list.push(this.props.field_gadget_list[i].getContent());
......@@ -176,8 +100,6 @@
return RSVP.Queue()
.push(function () { return RSVP.all(promise_list); })
.push(function (result_list) {
console.log("(*)(/)(*)");
console.log(result_list);
var name, result = {}, content = result;
if (gadget.props.key) {
content = result[gadget.props.key] = {};
......@@ -189,23 +111,9 @@
}
}
}
console.log("GET CONTENT SIMPLE FIELDSET 2");
console.log(result);
return result;
});
})
.declareMethod('startService', function () {
console.log("startservice FIElDSET 1");
var gadget = this,
i,
promise_list = [];
for (i = 0; i < gadget.props.field_gadget_list.length; i += 1) {
if (gadget.props.field_gadget_list[i].startService) {
promise_list.push(gadget.props.field_gadget_list[i].startService());
}
}
console.log("there are " + promise_list.length + " subgadget promises");
return RSVP.all(promise_list);
});
}(window, rJS, RSVP, Handlebars, initGadgetMixin));
......@@ -18,7 +18,7 @@
* ==========================================================================*/
/*global RSVP, rJS, $, jsPlumb, Handlebars,
loopEventListener, promiseEventListener, DOMParser, confirm, console*/
loopEventListener, promiseEventListener, DOMParser */
/*jslint unparam: true todo: true */
(function (RSVP, rJS, $, jsPlumb, Handlebars,
loopEventListener, promiseEventListener, DOMParser) {
......@@ -93,7 +93,6 @@
}
function getNodeId(gadget, element_id) {
console.log("getNODEID 1");
// returns the ID of the node in the graph from its DOM element id
var node_id;
$.each(gadget.props.node_id_to_dom_element_id, function (k, v) {
......@@ -106,11 +105,10 @@
}
function generateNodeId(gadget, element) {
console.log("generateNODEID 1");
// Generate a node id
var n = 1,
class_def = gadget.props.data.class_definition[element._class],
id = class_def.allOf[1].properties.id.default || element._class;
id = class_def.short_id || element._class;
while (gadget.props.data.graph.node[id + n] !== undefined) {
n += 1;
}
......@@ -139,7 +137,6 @@
}
if (remove) {
delete gadget.props.data.graph.edge[connection.id];
//delete gadget.props.data.graph.main_graph.node[connection.id];
} else {
var edge_data = gadget.props.data.graph.edge[connection.id] || {
_class: getDefaultEdgeClass(gadget)
......@@ -180,7 +177,6 @@
}
function updateElementCoordinate(gadget, node_id, coordinate) {
console.log("updateELEMENTCOORDINATE 1");
var element_id = gadget.props.node_id_to_dom_element_id[node_id],
element,
relative_position;
......@@ -241,7 +237,7 @@
});
}
function updateNodeStyle(gadget, element_id, class_definition) {
function updateNodeStyle(gadget, element_id) {
// Update node size according to the zoom level
// XXX does nothing for now
var zoom_level = gadget.props.zoom_level * 1.1111,
......@@ -252,9 +248,6 @@
.replace('px', '') * zoom_level + 'px';
element.css(j, new_value);
});
Object.keys(class_definition.css || {}).forEach(function (k) {
element.css(k, class_definition.css[k]);
});
}
// function positionGraph(gadget) {
......@@ -284,7 +277,6 @@
function removeElement(gadget, node_id) {
console.log("removeELEMENT 1");
var element_id = gadget.props.node_id_to_dom_element_id[node_id];
gadget.props.jsplumb_instance.removeAllEndpoints(
$(gadget.props.element).find("#" + element_id)
......@@ -293,7 +285,6 @@
delete gadget.props.data.graph.node[node_id];
delete gadget.props.node_id_to_dom_element_id[node_id];
//$.each(gadget.props.data.graph.main_graph.node, function (k, v) {
$.each(gadget.props.data.graph.edge, function (k, v) {
if (node_id === v.source || node_id === v.destination) {
delete gadget.props.data.graph.edge[k];
......@@ -301,11 +292,9 @@
});
gadget.notifyDataChanged();
console.log("removeELEMENT 4");
}
function updateElementData(gadget, node_id, data) {
console.log("updateELEMENTDATA 1");
var element_id = gadget.props.node_id_to_dom_element_id[node_id],
new_id = data.id;
if (data.data.name) {
......@@ -315,7 +304,6 @@
gadget.props.data.graph.node[node_id].name = data.data.name;
}
delete data.id;
//$.extend(gadget.props.data.graph.main_graph.node[node_id], data.data);
$.extend(gadget.props.data.graph.node[node_id], data.data);
if (new_id && new_id !== node_id) {
gadget.props.data.graph.node[new_id]
......@@ -326,8 +314,6 @@
= gadget.props.node_id_to_dom_element_id[node_id];
delete gadget.props.node_id_to_dom_element_id[node_id];
//delete gadget.props.data.graph.main_graph.node[new_id].id;
//$.each(gadget.props.data.graph.main_graph.node, function (k, v) {
delete gadget.props.data.graph.node[new_id].id;
$.each(gadget.props.data.graph.edge, function (k, v) {
if (v.source === node_id) {
......@@ -338,7 +324,6 @@
}
});
}
console.log("updateELEMENTDATA 7");
gadget.notifyDataChanged();
}
......@@ -396,300 +381,36 @@
connection.id = edge_id;
}
/* function expandSchema(class_definition, full_schema) {
function expandSchema(class_definition, full_schema) {
// minimal expanding of json schema, supports merging allOf and $ref
// references
// TODO: check for a library that would provide full support
var property, referenced, i, j, len,
var property, referenced, i,
expanded_class_definition = {properties:
class_definition.properties || {}},
ref_word_list, ref_word, ref_definition_list,
ref_definition_word, ref_definition_root, ref_definition,
sub_ref_def, sub_ref_def_list,
sub_ref_def_word, sub_ref_def_root, prop;
console.log("expandSCHEMA 1");
console.log(class_definition);
console.log(full_schema);
console.log(expanded_class_definition);
class_definition.properties || {}};
if (class_definition.allOf) {
for (i = 0; i < class_definition.allOf.length; i += 1) {
referenced = class_definition.allOf[i];
if (referenced.$ref) {
ref_word_list = referenced.$ref.split("/");
ref_word = ref_word_list[ref_word_list.length-1];
referenced = expandSchema(
full_schema.class_definition[ref_word],
full_schema.class_definition[
// 2 here is for #/
referenced.$ref.substr(2, referenced.$ref.length)
],
full_schema);
}
// console.log(full_schema.class_definition.definitions);
if (referenced.properties) {
console.log("[[[[[[[[[[]]]]]]]]]]");
console.log(referenced.properties);
for (property in referenced.properties) {
if (referenced.properties.hasOwnProperty(property)) {
if (referenced.properties[property].type ||
referenced.properties[property].$ref) {
console.log("..");
console.log(property);
console.log(referenced.properties[property]);
if (referenced.properties[property].$ref) {
ref_definition_list
= referenced.properties[property].$ref.split("/");
ref_definition_word
= ref_definition_list[ref_definition_list.length-1];
ref_definition
= full_schema.class_definition
.definitions[ref_definition_word];
if (ref_definition.allOf) {
if (ref_definition.allOf[1].oneOf) {
len = ref_definition.allOf[1].oneOf.length - 1;
for (j = 0; j <= len; j += 1) {
if (ref_definition.allOf[1]
.oneOf[j].$ref) {
sub_ref_def_list = ref_definition.allOf[1]
.oneOf[j].$ref.split("/");
sub_ref_def_word
= sub_ref_def_list[sub_ref_def_list.length-1];
sub_ref_def_root
= sub_ref_def_list[sub_ref_def_list.length-2];
sub_ref_def = full_schema.class_definition
.definitions[sub_ref_def_root][sub_ref_def_word];
ref_definition.allOf[1].oneOf[j] = sub_ref_def;
}
}
}
}
expanded_class_definition.properties[property]
= ref_definition;
//console.log("for property " + property + ", definition:");
//console.log(ref_definition);
} else {
if (referenced.properties[property].properties) {
console.log("not a reference");
console.log(referenced.properties[property].properties);
for (prop in referenced.properties[property]
.properties) {
if (referenced.properties[property]
.properties.hasOwnProperty(prop)) {
console.log(7);
console.log(prop);
console.log(referenced.properties[property]
.properties[prop]);
if (referenced.properties[property]
.properties[prop].$ref) {
console.log("!!!!");
ref_definition_list
= referenced.properties[property]
.properties[prop].$ref.split("/");
console.log(ref_definition_list);
ref_definition_word
= ref_definition_list[
ref_definition_list.length-1
];
console.log(ref_definition_word);
ref_definition_root
= ref_definition_list[
ref_definition_list.length-2
];
console.log(ref_definition_root);
ref_definition = full_schema
.class_definition[
ref_definition_root
][ref_definition_word];
console.log(ref_definition);
if (ref_definition.allOf) {
if (ref_definition.allOf[1].oneOf) {
len = ref_definition.allOf[1].oneOf.length - 1;
for (j = 0; j <= len; j += 1) {
if (ref_definition.allOf[1]
.oneOf[j].$ref) {
sub_ref_def_list = ref_definition.allOf[1]
.oneOf[j].$ref.split("/");
sub_ref_def_word
= sub_ref_def_list[
sub_ref_def_list.length-1
];
sub_ref_def_root
= sub_ref_def_list[
sub_ref_def_list.length-2
];
sub_ref_def = full_schema.class_definition
.definitions[
sub_ref_def_root
][sub_ref_def_word];
ref_definition.allOf[1].oneOf[j]
= sub_ref_def;
}
}
}
}
referenced.properties[property].properties[prop]
= ref_definition;
}
}
}
}
expanded_class_definition.properties[property]
= referenced.properties[property];
}
if (referenced.properties[property].type) {
expanded_class_definition.properties[property]
= referenced.properties[property];
}
}
}
}
}
}
// console.log("expandSCHEMA 2");
// console.log(expanded_class_definition);
return expanded_class_definition;
} */
function expandOneOf(definition, fullSchema) {
var j, len = definition.allOf[1].oneOf.length - 1,
def_ref_list, def_ref_word,
def_ref_root, referenced_def;
for (j = 0; j <= len; j += 1) {
if (definition.allOf[1].oneOf[j].$ref) {
def_ref_list = definition.allOf[1].oneOf[j].$ref.split("/");
def_ref_word = def_ref_list[def_ref_list.length - 1];
def_ref_root = def_ref_list[def_ref_list.length - 2];
referenced_def
= fullSchema.class_definition
.definitions[def_ref_root][def_ref_word];
definition.allOf[1].oneOf[j] = referenced_def;
}
}
return definition;
}
function expandReference(definition, fullSchema) {
var ref_definition_list
= definition.$ref.split("/"),
ref_definition_word
= ref_definition_list[ref_definition_list.length - 1],
ref_definition_root
= ref_definition_list[ref_definition_list.length - 2],
ref_definition = fullSchema
.class_definition[ref_definition_root][ref_definition_word];
console.log("expandingReference");
if (ref_definition.allOf) {
if (ref_definition.allOf[1].oneOf) {
console.log("there is oneOf");
ref_definition = expandOneOf(ref_definition, fullSchema);
}
}
definition = ref_definition;
console.log("* * *");
console.log(definition);
return definition;
}
function expandProperties(definition, expanded_class_def, fullSchema) {
console.log("expanding properties");
console.log(definition);
var property, temp1, temp2, i, subProp, temp3;
for (property in definition.properties) {
if (definition.properties.hasOwnProperty(property)) {
console.log("...");
console.log(property);
if (definition.properties[property].allOf
|| definition.properties[property].properties
|| definition.properties[property].type
|| definition.properties[property].$ref) {
if (definition.properties[property].$ref) {
temp1
= expandReference(
definition.properties[property], fullSchema
);
console.log("there is a referenced property # #");
console.log(property);
expanded_class_def.properties[property]
= temp1;
if (temp1.allOf) {
if (temp1.allOf[1].oneOf) {
for (i = 0; i <= temp1.allOf[1].oneOf.length-1; i += 1) {
if (temp1.allOf[1].oneOf[i].properties) {
for (subProp in temp1.allOf[1].oneOf[i].properties) {
if (temp1.allOf[1].oneOf[i]
.properties.hasOwnProperty(subProp)) {
if (temp1.allOf[1].oneOf[i].properties[subProp].$ref) {
console.log("there is referenced sub-property");
console.log(subProp);
temp3
= expandReference(
temp1.allOf[1].oneOf[i].properties[subProp],
fullSchema
);
expanded_class_def.properties[property]
.allOf[1].oneOf[i].properties[subProp]
= temp3;
}
}
}
}
}
}
}
} else {
if (definition.properties[property].properties) {
console.log("there is a property property --> recursive");
console.log(property);
expanded_class_def.properties[property] = {properties: {}};
temp2 = expandProperties(
definition.properties[property],
expanded_class_def.properties[property],
fullSchema
);
definition.properties[property] = temp2;
}
console.log("before expanding definition");
console.log(property);
expanded_class_def.properties[property]
= definition.properties[property];
}
}
}
}
console.log("- * - * -");
console.log(expanded_class_def);
return expanded_class_def;
}
function expandSchema(class_definition, full_schema) {
// minimal expanding of json schema, supports merging allOf and $ref
// references
// TODO: check for a library that would provide full support
console.log("EXPANDING SCHEMA FOR :");
console.log(class_definition);
var referenced, i,
expanded_class_definition = {
properties: class_definition.properties || {}
},
ref_word_list, ref_word;
if (class_definition.allOf) {
for (i = 0; i < class_definition.allOf.length; i += 1) {
referenced = class_definition.allOf[i];
if (referenced.$ref) {
ref_word_list = referenced.$ref.split("/");
ref_word = ref_word_list[ref_word_list.length - 1];
console.log("# there is reference");
referenced = expandSchema(
full_schema.class_definition[ref_word],
full_schema
);
}
if (referenced.properties) {
console.log("# there are properties");
expanded_class_definition = expandProperties(
referenced,
expanded_class_definition,
full_schema
);
}
}
}
console.log("EXPANDED SCHEMA FOR : 2");
console.log(expanded_class_definition);
return expanded_class_definition;
}
......@@ -794,7 +515,6 @@
}
function openNodeEditionDialog(gadget, element) {
console.log("openNODEDIALOG 1");
var node_id = getNodeId(gadget, element.id),
node_data = gadget.props.data.graph.node[node_id],
node_edit_popup = $(gadget.props.element).find('#popup-edit-template'),
......@@ -803,21 +523,15 @@
delete_promise;
// If we have no definition for this, we do not allow edition.
//TODO: node_data._class may not exist
if ( gadget.props.data.class_definition[node_data._class] === undefined ) {
return;
}
console.log("OPEN DIALOG FOR NODE");
console.log(gadget.props);
console.log(gadget.props.data.class_definition);
console.log(node_data);
schema = expandSchema(
gadget.props.data.class_definition[node_data._class],
gadget.props.data
);
console.log("----schema----");
console.log(schema);
console.log("----schema----");
if (node_edit_popup.length !== 0) {
node_edit_popup.remove();
}
......@@ -826,12 +540,6 @@
document.importNode(popup_edit_template.content, true).children[0]
);
node_edit_popup = $(gadget.props.element).find('#edit-popup');
console.log("openNODEDIALOG 1.3");
console.log(node_edit_popup);
console.log(node_edit_popup.find(".node_class"));
console.log(gadget.props.data.graph.node);
console.log(node_data);
console.log(node_edit_popup.find(".node_class").text(node_data._class));
// Set the name of the popup to the node class
node_edit_popup.find('.node_class').text(node_data._class);
fieldset_element = node_edit_popup.find('fieldset')[0];
......@@ -855,20 +563,12 @@
"data": {}
};
return fieldset_gadget.getContent().then(function (r) {
console.log("******");
console.log("******");
console.log("******");
console.log(r);
console.log("******");
console.log("******");
console.log("******");
$.extend(data.data, r);
updateElementData(gadget, node_id, data);
});
});
}
console.log("openNODEDIALOG 3");
delete_promise = new RSVP.Queue()
.push(function () {
return promiseEventListener(
......@@ -881,46 +581,24 @@
return removeElement(gadget, node_id);
});
console.log("openNODEDIALOG 4");
return gadget.declareGadget("../fieldset/index.html", {
element: fieldset_element,
scope: 'fieldset'
})
.push(function (fieldset_gadget) {
console.log("^^^^^^^^^^^^^^^^^^^");
console.log("^^^^^^^^^^^^^^^^^^^");
console.log("^^^^^^^^^^^^^^^^^^^");
console.log(fieldset_gadget);
console.log("^^^^^^^^^^^^^^^^^^^");
console.log("^^^^^^^^^^^^^^^^^^^");
console.log("^^^^^^^^^^^^^^^^^^^");
return RSVP.all([fieldset_gadget,
fieldset_gadget.render({value: node_data,
property_definition: schema},
node_id)]);
})
.push(function (fieldset_gadget) {
console.log(fieldset_gadget[0]);
return RSVP.Queue()
.push(function () {
console.log(fieldset_gadget[0]);
fieldset_gadget[0].startService();
})
.push(function () {
console.log(":::::::::::::::::::::::::::");
console.log(fieldset_gadget);
console.log(":::::::::::::::::::::::::::");
node_edit_popup.enhanceWithin();
node_edit_popup.popup('open');
return fieldset_gadget[0];
});
node_edit_popup.enhanceWithin();
node_edit_popup.popup('open');
return fieldset_gadget[0];
})
.push(function (fieldset_gadget) {
// Expose the dialog handling promise so that we can wait for it in
// test.
console.log("=======:::::::::::::::::::=======");
console.log(fieldset_gadget);
console.log("=======:::::::::::::::::::=======");
gadget.props.dialog_promise = RSVP.any([
save_promise(fieldset_gadget, node_id),
delete_promise
......@@ -933,16 +611,14 @@
delete gadget.props.dialog_promise;
});
}
//function waitForNodeClick(gadget, node, config_dict) {
function waitForNodeClick(gadget, node) {
console.log("waitFORNODEclick 1");
gadget.props.nodes_click_monitor
.monitor(loopEventListener(
node,
'dblclick',
false,
openNodeEditionDialog.bind(null, gadget, node)
//openNodeDialog.bind(null, gadget, node, config_dict)
));
}
......@@ -967,7 +643,6 @@
}
function addNode(gadget, node_id, node_data) {
console.log("addNODE 0");
var render_element = $(gadget.props.main),
class_definition = gadget.props.data.class_definition[node_data._class],
coordinate = node_data.coordinate,
......@@ -980,7 +655,6 @@
gadget.props.node_id_to_dom_element_id[node_id] = dom_element_id;
node_data.name = node_data.name || class_definition.name;
//gadget.props.data.graph.main_graph.node[node_id] = node_data;
gadget.props.data.graph.node[node_id] = node_data;
if (coordinate === undefined) {
......@@ -1005,8 +679,8 @@
"text/html"
).querySelector('.window');
render_element.append(domElement);
waitForNodeClick(gadget, domElement);
//waitForNodeClick(gadget, domElement, class_definition);
box = $(gadget.props.element).find("#" + dom_element_id);
absolute_position = convertToAbsolutePosition(
......@@ -1016,7 +690,7 @@
);
box.css("top", absolute_position[1]);
box.css("left", absolute_position[0]);
updateNodeStyle(gadget, dom_element_id, class_definition);
updateNodeStyle(gadget, dom_element_id);
draggable(gadget); // XXX make only this element draggable.
// Add some flowchart endpoints
......@@ -1037,22 +711,17 @@
gadget.notifyDataChanged();
console.log("addNODE 7");
}
function waitForDrop(gadget) {
console.log("wait for DROP 1");
var callback;
function canceller() {
console.log("wait for DROP canceler1");
if (callback !== undefined) {
console.log("wait for DROP canceller2");
gadget.props.main.removeEventListener('drop', callback, false);
}
}
/*jslint unparam: true*/
function resolver(resolve, reject) {
console.log("wait for DROP resolver1");
callback = function (evt) {
try {
var class_name = JSON.parse(
......@@ -1074,13 +743,11 @@
_class: class_name
});
} catch (e) {
console.log("wait for DROP resolver100");
reject(e);
}
};
gadget.props.main.addEventListener('drop', callback, false);
}
console.log("wait for DROP 2");
return new RSVP.all( [
// loopEventListener adds an event listener that will prevent default for
......@@ -1090,7 +757,6 @@
RSVP.Promise(resolver, canceller) ]);
}
//initGadgetMixin(gadget_klass);
gadget_klass
.ready(function (g) {
g.props = {};
......@@ -1109,10 +775,9 @@
.declareAcquiredMethod('notifyDataChanged', 'notifyDataChanged')
.declareMethod('render', function (data) {
// var gadget = this;
console.log("RENDEERING WORKFLOW EDITOR1");
this.props.data = JSON.parse(data);
this.props.jsplumb_instance = jsPlumb.getInstance();
console.log("RENDEERING WORKFLOW EDITOR3");
// XXX data loading is done in startService
/*
$.each(this.props.data.graph.node, function (key, value) {
......@@ -1125,18 +790,10 @@
})
.declareMethod('getContent', function () {
console.log("£££££££");
console.log("£££££££");
console.log("£££££££");
console.log(this.props.data);
console.log("£££££££");
console.log("£££££££");
console.log("£££££££");
return JSON.stringify(this.props.data);
})
.declareMethod('startService', function () {
console.log("startservice WORKFLOW EDITOR1");
var gadget = this,
jsplumb_instance = gadget.props.jsplumb_instance;
this.props.main = this.props.element.querySelector('#main');
......@@ -1160,7 +817,7 @@
],
Container: this.props.main
});
console.log("startservice WORKFLOW EDITOR2");
draggable(gadget);
this.props.nodes_click_monitor = RSVP.Monitor();
......@@ -1169,11 +826,10 @@
$.each(this.props.data.graph.node, function (key, value) {
addNode(gadget, key, value);
});
console.log("startservice WORKFLOW EDITOR3");
$.each(this.props.data.graph.edge, function (key, value) {
addEdge(gadget, key, value);
});
console.log("startservice WORKFLOW EDITOR4");
return RSVP.all([
waitForDrop(gadget),
waitForConnection(gadget),
......@@ -1182,6 +838,5 @@
gadget.props.nodes_click_monitor
]);
});
}(RSVP, rJS, $, jsPlumb, Handlebars, loopEventListener,
promiseEventListener, DOMParser));
......@@ -40,21 +40,19 @@
*/
tools_container.className = 'tools-container';
Object.keys(data.class_definition).forEach(function (key) {
var _class_object = data.class_definition[key], tool;
var _class = data.class_definition[key], tool;
// XXX "expand" the json schema "allOF" etc
if (_class_object.allOf) {
if (_class_object.allOf[0].$ref === "#/node") {
tool = document.createElement('div');
// XXX maybe allow to configure the class name ?
tool.className = "tool " + key;
tool.textContent = _class_object.name || key;
tool.draggable = true;
tool.dataset.class_name = JSON.stringify(key);
Object.keys(_class_object.css || {}).forEach(function (k) {
tool.style[k] = _class_object.css[k];
});
tools_container.appendChild(tool);
}
if (_class._class === 'node') {
tool = document.createElement('div');
// XXX maybe allow to configure the class name ?
tool.className = "tool " + key;
tool.textContent = _class.name || key;
tool.draggable = true;
tool.dataset.class_name = JSON.stringify(key);
Object.keys(_class.css || {}).forEach(function (k) {
tool.style[k] = _class.css[k];
});
tools_container.appendChild(tool);
}
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment