Skip to content

Commit

Permalink
pagination in HomeView; added refresh button; bySearchKeywords map; h…
Browse files Browse the repository at this point in the history
…tml cleanup;
  • Loading branch information
chrisekelley committed Nov 19, 2011
1 parent 668aa40 commit 497bbcc
Show file tree
Hide file tree
Showing 13 changed files with 161 additions and 153 deletions.
95 changes: 59 additions & 36 deletions _attachments/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,21 @@ var wrapError = function(onError, model, options) {
var AppRouter = Backbone.Router.extend({

routes: {
"/": "home", // #home
"home": "home", // #home
"search/:query": "search", // #search
"incident": "incident", // #incident
"arrestDocket/:query": "arrestDocket", // #arrestDocket
"problem/:query": "problem", // #arrestDocket
"incidentRecords/:incidentId": "incidentRecords", // #incidentRecords
"edit/:recordId": "edit", // #edit
"record/:recordId": "record", // #record
"renderForm/:formId/:parentId": "renderForm", // #renderForm
"destroy/:recordId": "destroy", // #destroy
"design": "design", // #design
"populate": "populate", // #populate
"config": "config", // #config
"*actions": "home", // matches http://example.com/#anything-here - used to point to defaultRoute
"/": "home", // #home
"home/:startkey": "home", // #home
"search/:query": "search", // #search
"incident": "incident", // #incident
"arrestDocket/:query": "arrestDocket", // #arrestDocket
"problem/:query": "problem", // #arrestDocket
"incidentRecords/:incidentId": "incidentRecords", // #incidentRecords
"edit/:recordId": "edit", // #edit
"record/:recordId": "record", // #record
"renderForm/:formId/:parentId": "renderForm", // #renderForm
"destroy/:recordId": "destroy", // #destroy
"design": "design", // #design
"populate": "populate", // #populate
"config": "config", // #config
"*actions": "home", // matches http://example.com/#anything-here - used to point to defaultRoute
},
// The following route is unused.
defaultRoute: function( actions ){
Expand All @@ -77,8 +77,8 @@ var AppRouter = Backbone.Router.extend({
//page = new Page({});
(new HomeView({model: page})).render();
},
home: function () {
//console.log("home route.");
home: function (startkey, startkey_docid) {
console.log("home route." + startkey);
// if ($("#charts").length <= 0){
// window.location.href = '/coconut/_design/coconut/index.html';
// }
Expand All @@ -91,26 +91,48 @@ var AppRouter = Backbone.Router.extend({
viewDiv.setAttribute("id", "homePageView");
$("#views").append(viewDiv);
}
// $("#charts").remove();
// if (! $("#charts").length){
// var viewDiv = document.createElement("div");
// viewDiv.setAttribute("id", "charts");
// $("#mailcol").append(viewDiv);
// }

var limit = 16;
var searchResults = new IncidentsList();
searchResults.db["keys"] = null;
searchResults.db["view"] = ["byIncidentSorted?descending=true&limit=15"];
//var viewQuery = "byIncidentSorted?descending=true&limit=" + limit + "&startkey=" + startkey + "&startkey_docid=" + startkey_docid;
var viewQuery = "byIncidentSorted?descending=true&limit=" + limit + "&startkey=" + "[" + startkey + "]";
if (startkey == null || startkey == "" || startkey == "home") {
viewQuery = "byIncidentSorted?descending=true&limit=" + limit;
}
console.log("viewQuery: " + viewQuery)
searchResults.db["view"] = [viewQuery];
searchResults.fetch({
success : function(){
FORMY.Incidents = searchResults;
//console.log("render; Incidents count: " + FORMY.Incidents.length);
var page = new Page({content: "Default List of Incidents:"});
console.log("item count: " + searchResults.length);
var listLength = searchResults.length;
//var querySize = 15
if (listLength < limit) {
limit = listLength;
startkey = null;
} else {
var next_start_record = searchResults.at(limit-1);
if (next_start_record) {
startkey_docid = next_start_record.id;
console.log("next_start_record: " + JSON.stringify(next_start_record));
console.log("startkey_docid: " + startkey_docid);
startkey = next_start_record.get("lastModified");
FORMY.Incidents = searchResults.remove(next_start_record);
}
}
if (startkey == "") { //home (/)
FORMY.Incidents = searchResults;
startkey = 16
//console.log("searchResults: " + JSON.stringify(searchResults));
}
console.log("startkey: " + startkey);
var page = new Page({content: "Default List of Incidents:", startkey_docid:startkey_docid, startkey:startkey});
(new HomeView(
{model: page, el: $("#homePageView")})).render();
{model: page, el: $("#homePageView"), startkey_docid:startkey_docid, startkey:startkey})).render();
//console.log("starting stripeme.");
$(".stripeMe tr").mouseover(function(){$(this).addClass("over");}).mouseout(function(){$(this).removeClass("over");});
$(".stripeMe tr:even").addClass("alt");
$("#noStripeMe").removeClass("alt");
$("#noStripeMe").addClass("noStripeMeHeader");
},
error : function(){
console.log("Error loading PatientRecordList: " + arguments);
Expand Down Expand Up @@ -152,18 +174,17 @@ var AppRouter = Backbone.Router.extend({
//searchResults.db["keys"] = {"keys": [8]};
//searchResults.db["view"] = ["bySurnameOrId?startkey=\"" + searchTerm + "\"&endkey=\"" + searchTerm + "\u9999\""];
//searchResults.db["view"] = ["byId?startkey=\"" + searchTerm + "\"&endkey=\"" + searchTerm + "Z\""];
searchResults.db["view"] = ["byId"];
searchResults.db["view"] = ["bySearchKeywords"];
//searchResults.db["view"] = ["byId?descending=true&limit=15"];
} else {
//console.log("This should reset the collection.");
searchResults.db["keys"] = null;
searchResults.db["view"] = ["byIncidentSorted?descending=true&limit=15"];
searchResults.db["view"] = ["byIncidentSorted?descending=true&limit=16"];
}
searchResults.fetch({
success : function(){
//console.log("Records:" + JSON.stringify(patient.Records));
//console.log("Fetching Records for:" + searchTerm);
//console.log("searchResults: " + JSON.stringify(searchResults));
var next_start_record = searchResults.get(15);
console.log("next_start_record: " + JSON.stringify(next_start_record));
FORMY.Incidents = searchResults;
//console.log("render; Incidents count: " + FORMY.Incidents.length);
var page = new Page({content: "Default List of Incidents:"});
Expand Down Expand Up @@ -438,8 +459,9 @@ var AppRouter = Backbone.Router.extend({
function randomFromTo(from, to){
return Math.floor(Math.random() * (to - from + 1) + from);
};
var countTestDocs = 20;

while (ct < 6) {
while (ct < (countTestDocs+1)) {
ct++;
var subcounty=randomFromTo(1,8).toString();
var village=randomFromTo(1,8).toString();
Expand Down Expand Up @@ -475,7 +497,8 @@ var AppRouter = Backbone.Router.extend({
var created = new Date().valueOf();
var lastModified = created;

var id = "test" + ct;
//var id = "test" + ct;
var id = "test" + ct + "_" + created;
testdoc = { _id : id, "flowId": "300","formId": "incident","phone": "0772555"+ ct,"description": "This is a test",
"subcounty": subcounty,"village": village,"priority": priority,"department": department,"assignedId": ct.toString(),
"resolved":resolved, "created": created,"lastModified": lastModified,"collection": "incident"};
Expand Down
2 changes: 1 addition & 1 deletion _attachments/app/templates/config.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ <h2>Configuration</h2>

<tr>
<td><a href="#populate"><img src="images/system-users.png" alt="Populate" /></a></td>
<td>Populate Application with Test Data. Won't work if already populated with test data.</td>
<td>Populate Application with Test Data. Do not use this on a live system!.</td>
</tr>
</table>
73 changes: 34 additions & 39 deletions _attachments/app/templates/home.vert.template.html
Original file line number Diff line number Diff line change
@@ -1,39 +1,34 @@

<div id="pagewidth-vert">
<div id="search-results">
<form name="searchForm" id="search-results-form" onsubmit="return false;">
<!-- <input type="hidden" id="first_surname" name="first_surname"/>
<input type="hidden" id="start_row" name="start_row"/> -->
<!-- <table>
<tbody><tr>
<td> -->
<table class="banner-home-vert" width="100%">
<tbody><tr>
<td style="vertical-align: top;"><input type="text" id="search_string" name="search_string" placeholder="Search:Phone/ID" size="15"/>
<button id='form-search' value="Search" class="shiny-red" style="width: 65px;">Search</button>
<!-- <td style="vertical-align: top;"> -->
<button id='form-client'class="menu-blue" style="width: 55px;">Incident</button>
<button id='form-config' class="menu-blue" style="width: 40px;">Conf</button>
</td>
<!-- <a href="#newPatient">New Client</a></td>
<td><a href="/mobilefuton/_design/mobilefuton/index.html">Configuration</a></td> -->
</tr>
</tbody></table>
<!-- </td>
</tr>
</tbody></table> -->
</form>
<div id="search-results-body-vert">
<div id="search-results-list">
<table id="incidents" width="100%" class="stripeMe">
<thead>
<tr>
<th>Phone</th><th>Alert</th><th>Dept.</th><th style="border-right:none;">Date</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
</div>
</div>
<div id="pagewidth-vert">
<div id="search-results">
<form name="searchForm" id="search-results-form" onsubmit="return false;">
<table class="banner-home-vert" width="100%">
<tbody>
<tr>
<td style="vertical-align: top;">
<input type="text" id="search_string" name="search_string" placeholder="Search:Phone/ID" size="15"/>
<button id='form-search' value="Search" class="shiny-red" style="width: 65px;">Search</button>
<button id='form-client'class="menu-blue" style="width: 55px;">Incident</button>
<button id='form-config' class="menu-blue" style="width: 40px;">Conf</button>
<img src="images/1321455058_reload.png" alt="Refresh" class="tabbar-image" onClick="window.location.href = '/coconut/_design/coconut/index.html'"/>
</td>
</tr>
</tbody>
</table>
</form>
<div id="search-results-body-vert">
<div id="search-results-list">
<table id="incidents" width="100%" class="stripeMe">
<thead>
<tr>
<th>Phone</th><th>Alert</th><th>Dept.</th><th style="border-right:none;">Date</th>
</tr>
</thead>
<tbody></tbody>
{{#if startkey_docid}}
<tr style="background-color: #6EA8E4;" id="noStripeMe"><td></td><td></td><td></td><td><div id="nextLink" onmouseover="style.color='red';" onmouseout="style.color='#034AF3';">&gt;&gt;</div></td></tr>
{{/if}}
</table>
</div>
</div>
</div>
</div>
20 changes: 15 additions & 5 deletions _attachments/app/views/HomeView.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
var HomeView = Backbone.View.extend({
//el: $("#homePageView"),
template: loadTemplate("home.template.html"),

initialize: function() {
_.bindAll(this, 'addOne', 'reseted', 'render', 'search', 'orientation');
_.bindAll(this, 'addOne', 'reseted', 'render', 'search', 'orientation', 'nextLink');
FORMY.Incidents.bind('add', this.addOne, this);
//FORMY.Incidents.bind('search', this.search, this);
FORMY.Incidents.bind('reset', this.reseted, this);
FORMY.Incidents.bind('all', this.render, this);
FORMY.Incidents.bind('change', this.search, this);
FORMY.Incidents.bind('render', this.render, this);

//FORMY.Incidents.fetch();
return this;
},
},
startkey: null,
startkey_docid: null,
endkey_docid: null,
addOne : function(patient){
this.view = new SearchListItemView({model: patient});
this.rendered = this.view.render().el;
Expand All @@ -25,6 +25,7 @@ var HomeView = Backbone.View.extend({
"click #form-client " : "incidentLink",
"click #form-config " : "configLink",
"click #form-design " : "designLink",
"click #nextLink" : "nextLink",
"orientationEvent " : "orientation",
},
reseted: function() {
Expand All @@ -36,6 +37,15 @@ var HomeView = Backbone.View.extend({
console.log("remove the view in homeView");
$(this.el).remove();
},
nextLink: function() {
console.log("this.model.toJSON(): " + this.model.get("startkey"));
if (this.model.get("startkey") != null) {
//FORMY.router.navigate('home/' + this.model.get("startkey") + '/' + this.model.get("startkey_docid"), true);
FORMY.router.navigate('home/' + this.model.get("startkey"), true);
} else {
console.log("nextLink");
}
},
incidentLink: function() {
FORMY.router.navigate('incident', true);
},
Expand Down
4 changes: 2 additions & 2 deletions _attachments/css/1140.css
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ img {
float: none;
margin-left: 0px;
margin-right: 0px;
padding-left: 20px;
padding-right: 20px;
/* padding-left: 20px; */
/* padding-right: 20px; */
}

}
16 changes: 15 additions & 1 deletion _attachments/css/Site.css
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ font-weight: bold;
fill: white;
}

// http://mbostock.github.com/d3/ex/population.css
/* http://mbostock.github.com/d3/ex/population.css */
.bullet { font: 10px sans-serif; }
.bullet .marker { stroke: #000; stroke-width: 2px; }
.bullet .tick line { stroke: #666; stroke-width: .5px; }
Expand All @@ -1209,3 +1209,17 @@ font-weight: bold;
.bullet .title { font-size: 14px; font-weight: bold; }
.bullet .subtitle { fill: #999; }

.tabbar-image {
vertical-align:bottom;
padding-left: 10px;

}

#nextLink {
color: #034AF3;
}

.noStripeMeHeader
{
background: #6EA8E4;
}
Binary file added _attachments/images/1321454797_reload.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _attachments/images/1321454835_reload.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _attachments/images/1321455058_reload.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 0 additions & 44 deletions _attachments/index-old.html

This file was deleted.

Loading

0 comments on commit 497bbcc

Please sign in to comment.