parent (back) load of initial page problem fixed - have to correct handleDictDelete

parent ef6c4d98
...@@ -14,18 +14,24 @@ ...@@ -14,18 +14,24 @@
<script src="InputModule_viewAddInstanceDefinitionDialog.js" type="text/javascript"></script> <script src="InputModule_viewAddInstanceDefinitionDialog.js" type="text/javascript"></script>
<!--script id="table-template" type="text/x-handlebars-template"> <script id="table-template" type="text/x-handlebars-template">
<ul data-role="listview" data-inset="true" class="document-listview"> <ul data-role="listview" data-inset="true" class="document-listview">
{{#documentlist}} {{#documentlist}}
<li><a href="{{link}}">{{title}}</a></li> <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}} {{/documentlist}}
</ul> </ul>
</script--> </script>
<!--script id="li-template" type="text/x-handlebars-template">
<div class="ui-btn ui-input-btn ui-corner-all ui-shadow"> {{value}}
<input type="submit" value="{{value}}" name= "{{name}}">
</div>
</script-->
</head> </head>
<body> <body>
...@@ -44,10 +50,10 @@ ...@@ -44,10 +50,10 @@
</div> </div>
<div class="ui-block-b"> <div class="ui-block-b">
<!--section class="document_list"></section-->
<form method="post" action="#"> <form method="post" action="#">
<input type="hidden" name="method" value="delete_status" ></input> <input type="hidden" name="method" value="delete_status" ></input>
<ul data-role="listview" class="document-list" data-inset="true"></ul> <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"> <div class="ui-input-btn ui-btn ui-icon-delete ui-btn-inline ui-btn-icon-left">
Delete Delete
<input type="submit" data-enhanced="true" value="Delete"> <input type="submit" data-enhanced="true" value="Delete">
......
/*global $, rJS, RSVP, promiseEventListener, promiseReadAsText, /*global $, rJS, RSVP, promiseEventListener, promiseReadAsText,
initGadgetMixin, Handlebars, console */ initGadgetMixin, Handlebars, console */
(function (window, rJS, RSVP, promiseEventListener, (function (window, rJS, RSVP, promiseEventListener,
promiseReadAsText, initGadgetMixin) { /* Handlebars*/ promiseReadAsText, initGadgetMixin, Handlebars) { /* Handlebars*/
"use strict"; "use strict";
// delete last session document // delete last session document
function removeLastSession(gadget, name) { function removeLastSession(gadget, name) {
...@@ -171,12 +171,11 @@ ...@@ -171,12 +171,11 @@
}); });
} }
var gadget_klass = rJS(window); var gadget_klass = rJS(window),
//var gadget_klass = rJS(window), source = gadget_klass.__template_element
// source = gadget_klass.__template_element .getElementById("table-template")
// .getElementById("li-template") .innerHTML,
// .innerHTML, table_template = Handlebars.compile(source);
// li_template = Handlebars.compile(source);
initGadgetMixin(gadget_klass); initGadgetMixin(gadget_klass);
gadget_klass.declareAcquiredMethod("aq_post", "jio_post") gadget_klass.declareAcquiredMethod("aq_post", "jio_post")
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
...@@ -205,69 +204,66 @@ ...@@ -205,69 +204,66 @@
}) })
.declareMethod("render", function () { .declareMethod("render", function () {
console.log("VIEWADDINSTANCE RENDER 1"); console.log("VIEWADDINSTANCE RENDER 1");
var gadget, doc_list; var gadget, doc_list, innerHTML;
gadget = this; gadget = this;
doc_list = gadget.props.element.querySelector("ul.document-list"); doc_list = gadget.props.element.querySelector(".document_list");
console.log("list created? 1");
console.log(doc_list);
// helper: add options to selects // helper: add options to selects
function makeListItems(row_list) { function makeListItems(row_list) {
console.log("MAKEDOCUMENTLIST 1"); console.log("MAKEDOCUMENTLIST 1");
var i, len, fragment, record, item, button, box, label; //test; var i, len, record, item, //button, box, label, fragment
fragment = document.createDocumentFragment(); param_list; //test;
for (i = 0, len = row_list.length; i < len; i += 1) { 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; record = row_list[i].doc;
param_list[i] = {
title: record.title + " (" + record.date + ")",
item = document.createElement("li"); name: "record_" + record._id,
date: new Date(record.date)
//test = document.createElement("li"); };
/*jslint nomen: true*/
//test.innerHTML = li_template({
// value: record.title + " (" + record.date + ")",
// name: "record_" + record._id
//});
/*jslint nomen: false*/
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);
//test.appendChild(label);
item.appendChild(button);
item.appendChild(label);
fragment.appendChild(item);
} }
param_list.sort(function (a, b) {
return b.date - a.date;
});
}
innerHTML = table_template({
documentlist: param_list
});
console.log("MAKEDOCUMENTLIST 2"); console.log("MAKEDOCUMENTLIST 2");
return fragment; //return fragment;
} }
// helper: select a configuration dictionary from a doc // helper: select a configuration dictionary from a doc
function handleDictSelect(e) { function handleDictSelect(e) {
//console.log('SELECTING CONFIGURATION DICTIONARY??????');
var form, element, id, json_data; var form, element, id, json_data;
//prevent default //prevent default
e.preventDefault(); e.preventDefault();
form = e.target; form = e.target;
console.log('HANDLEDICTSELECT');
console.log(form);
element = form.querySelector("div.ui-focus"); element = form.querySelector("div.ui-focus");
if (element === undefined || null) { if (element === null || element === "undefined") {
console.log(0);
element = form.querySelector("input.ui-state-focus"); element = form.querySelector("input.ui-state-focus");
} console.log(element);
id = element.name.replace("record_", "");
} else {
id = element.childNodes[1].name.replace("record_", ""); id = element.childNodes[1].name.replace("record_", "");
}
return gadget.aq_getAttachment({ return gadget.aq_getAttachment({
"_id": id, "_id": id,
"_attachment": "body.json" "_attachment": "body.json"
...@@ -278,7 +274,7 @@ ...@@ -278,7 +274,7 @@
gadget.setConfigurationDict(json_data); gadget.setConfigurationDict(json_data);
}) })
.push(function () { .push(function () {
console.log("happiness"); console.log("to remove last session");
return removeLastSession(gadget); return removeLastSession(gadget);
}) })
.push(function (jio_document_list) { .push(function (jio_document_list) {
...@@ -325,6 +321,8 @@ ...@@ -325,6 +321,8 @@
$doc.listview("refresh"); $doc.listview("refresh");
} }
} }
console.log("list created? 1");
console.log(doc_list);
return RSVP.all(promise_list); return RSVP.all(promise_list);
} }
return gadget.aq_allDocs({ return gadget.aq_allDocs({
...@@ -333,21 +331,21 @@ ...@@ -333,21 +331,21 @@
"select_list": ["title", "modified"] "select_list": ["title", "modified"]
}) })
.push(function (document_list) { .push(function (document_list) {
console.log("VIEWADDINSTANCE RENDER 2"); var len, data, $doc;
var len, data, $doc, fragment;
data = document_list.data; data = document_list.data;
len = data.total_rows; len = data.total_rows;
if (len > 0) { if (len > 0) {
fragment = makeListItems(data.rows); makeListItems(data.rows);
} else { } else {
fragment = document.createElement("li"); makeListItems([{doc: "none"}]);
fragment.innerHTML = "no records";
} }
// append // append
while (doc_list.firstChild) { while (doc_list.firstChild) {
doc_list.removeChild(doc_list.firstChild); doc_list.removeChild(doc_list.firstChild);
} }
doc_list.appendChild(fragment); console.log("list created? last");
console.log(doc_list);
doc_list.innerHTML = innerHTML;
// enhance/refresh // enhance/refresh
$doc = $(doc_list); $doc = $(doc_list);
if ($doc.listview("instance")) { if ($doc.listview("instance")) {
...@@ -394,4 +392,4 @@ ...@@ -394,4 +392,4 @@
}); });
}(window, rJS, RSVP, promiseEventListener, promiseReadAsText, }(window, rJS, RSVP, promiseEventListener, promiseReadAsText,
initGadgetMixin)); /* Handlebars*/ initGadgetMixin, Handlebars)); /* Handlebars*/
\ No newline at end of file \ No newline at end of file
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