new intro-page, inputList and add new model are present in the same page....

new intro-page, inputList and add new model are present in the same page. Default getConfigurateion from server not updated yet. Buggy back to parrent as list does not update correctly. Storing lastSession in local storage. DreamInstance document to be dropped
parent 074c85c8
......@@ -29,7 +29,11 @@
/////////////////////////////////////////////////////////////////
.declareMethod("render", function () {
var gadget = this;
return gadget.aq_allDocs({"select_list": ["title", "modified"]})
return gadget.aq_allDocs({
"include_docs": true,
"query": 'type:= "Dream"',
"select_list": ["title", "modified"]
})
.push(function (document_list) {
var result_list = [],
doc,
......@@ -71,7 +75,6 @@
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 =
......@@ -80,4 +83,4 @@
});
});
});
}(window, rJS, RSVP, Handlebars, initGadgetMixin));
}(window, rJS, RSVP, Handlebars, initGadgetMixin));
\ No newline at end of file
......@@ -18,8 +18,9 @@
<script id="panel-template" type="text/x-handlebars-template">
<ul data-role="listview">
<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="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-->
{{#navigationlist}}
<li><a href="{{link}}">{{title}}</a></li>
{{/navigationlist}}
......
......@@ -16,7 +16,14 @@
/////////////////////////////////////////////////////////////////
// XXX we should use lists instead to keep ordering
var portal_types = {
"Input Module": {
"Pre Input Module": {
view: {
gadget: "InputModule_viewAddInstanceDefinitionDialog",
type: "object_fast_input",
title: "Choose Instance Definition"
}
}//,
/*"Input Module": {
"view": {
"gadget": "InputModule_viewInputList",
"type": "object_list",
......@@ -27,9 +34,9 @@
"type": "object_fast_input",
"title": "Create Document"
}
},
}*/
// TODO: remove this once everything is merged.
"Input": {
/*"Input": {
"view": {
"gadget": "Input_viewProductionLine",
"type": "object_view",
......@@ -38,62 +45,61 @@
"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",
......@@ -115,84 +121,76 @@
"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,
......@@ -200,7 +198,15 @@
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 = {
......@@ -213,6 +219,14 @@
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
......@@ -252,7 +266,7 @@
forward_kw.result = current + 1;
}
});
} else if (portal_type !== "Input Module") {
} else if (portal_type !== "Pre Input Module") {
throw new Error("Unknown portal type: " + portal_type);
}
return queue.push(function () {
......@@ -262,7 +276,7 @@
function getTitle(gadget, portal_type, options) {
var title;
if (portal_type === "Input Module") {
if (portal_type === "Pre Input Module") {
title = "Documents";
} else if (portal_type === "Input") {
title = gadget.getDeclaredGadget("jio")
......@@ -292,6 +306,15 @@
}
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 ===
......@@ -312,12 +335,16 @@
);
}
}
}
}
/*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>';
......@@ -331,6 +358,9 @@
}
initGadgetMixin(gadget_klass);
/*console.log('AaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAa');
console.log(gadget_klass);
console.log('AaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAa');*/
gadget_klass
/////////////////////////////////////////////////////////////////
// Acquired methods
......@@ -383,7 +413,22 @@
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({});
......@@ -398,6 +443,9 @@
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",
......@@ -425,6 +473,38 @@
.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
......@@ -436,42 +516,70 @@
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_fast_input"}),
g.aq_pleasePublishMyState({action: "view"})
]);
})
.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("home_link")[0].href = link_list[0];
panel.getElementsByClassName("fast_input_link")[0].href =
link_list[1];
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];
// 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({
......@@ -479,7 +587,33 @@
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"
}]
}
};
});*/
})
/////////////////////////////////////////////////////////////////
......@@ -490,12 +624,14 @@
var gadget = this,
back_kw = {action: "view"},
page_gadget,
portal_type = "Input Module",
portal_type = "Pre 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";
......@@ -503,6 +639,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) {
......@@ -514,6 +662,11 @@
}
}
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")
.push(function(jio_gadget) {
if (options.id) {
......@@ -550,6 +703,9 @@
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="../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><a href="{{link}}">{{title}}</a></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">
<!--section class="document_list"></section-->
<form method="post" action="#">
<input type="hidden" name="method" value="delete_status" ></input>
<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, console */
(function (window, rJS, RSVP, promiseEventListener,
promiseReadAsText, initGadgetMixin) {
"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);
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 () {
var gadget, doc_list;
gadget = this;
doc_list = gadget.props.element.querySelector("ul.document-list");
// helper: add options to selects
function makeListItems(row_list) {
var i, len, fragment, item, record, button, box, label; /*text_node*/
fragment = document.createDocumentFragment();
for (i = 0, len = row_list.length; i < len; i += 1) {
record = row_list[i].doc;
item = document.createElement("li");
button = document.createElement("input");
button.type = "submit";
button.value = record.title + " (" + record.date + ")";
/*jslint nomen: true*/
button.setAttribute("name", "record_" + record._id);
/*jslint nomen: false*/
label = document.createElement("label");
box = document.createElement("input");
box.type = "checkbox";
box.value = " ";
/*jslint nomen: true*/
box.setAttribute("name", "record_" + record._id);
/*jslint nomen: false*/
label.appendChild(box);
item.appendChild(button);
item.appendChild(label);
fragment.appendChild(item);
}
return fragment;
}
// helper: select a configuration dictionary from a doc
function handleDictSelect(e) {
//console.log('SELECTING CONFIGURATION DICTIONARY??????');
var form, element, id, json_data;
//prevent default
e.preventDefault();
form = e.target;
element = form.querySelector("div.ui-focus");
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("happiness");
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
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;
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");
}
}
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, fragment;
data = document_list.data;
len = data.total_rows;
if (len > 0) {
fragment = makeListItems(data.rows);
} else {
fragment = document.createElement("li");
fragment.innerHTML = "no records";
}
// append
while (doc_list.firstChild) {
doc_list.removeChild(doc_list.firstChild);
}
doc_list.appendChild(fragment);
// enhance/refresh
$doc = $(doc_list);
if ($doc.listview("instance")) {
$doc.listview("refresh");
}
})
.push(function () {
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 () {
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) {
return gadget.pleaseRedirectMyHash(url);
});
});
}(window, rJS, RSVP, promiseEventListener, promiseReadAsText,
initGadgetMixin));
\ No newline at end of file
/*global window, document, RSVP, rJS, initGadgetMixin*/
/*global window, document, RSVP, rJS, initGadgetMixin, console*/
(function (window, document, RSVP, rJS, initGadgetMixin) {
"use strict";
......@@ -38,21 +38,31 @@
tools_container = document.createElement('div');
/* display all nodes in the palette.
*/
console.log("RENDERING TOOLBOX");
tools_container.className = 'tools-container';
Object.keys(data.class_definition).forEach(function (key) {
var _class = data.class_definition[key], tool;
var _class_object = data.class_definition[key], tool;
// XXX "expand" the json schema "allOF" etc
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);
console.log(_class_object);
if (_class_object.allOf) {
console.log("yupi");
if (_class_object.allOf[0].$ref === "#/class_definition/node") {
console.log("yupi2");
tool = document.createElement('div');
// XXX maybe allow to configure the class name ?
tool.className = "tool " + key;
console.log("..");
console.log(tool.className);
tool.textContent = _class_object.name || key;
console.log(tool.textContent);
tool.draggable = true;
tool.dataset.class_name = JSON.stringify(key);
console.log(tool.dataset.class_name);
Object.keys(_class_object.css || {}).forEach(function (k) {
tool.style[k] = _class_object.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