local offline archive support

This commit is contained in:
Morgan McMillian 2012-12-01 17:03:35 -05:00
parent 5bf37a803e
commit b36fd3cc1a
6 changed files with 81 additions and 3 deletions

View file

@ -1,6 +1,6 @@
{ {
"id": "com.monkeystew.todotxtenyo.beta", "id": "com.monkeystew.todotxtenyo.beta",
"version": "0.3.0", "version": "0.3.1",
"vendor": "Monkeystew", "vendor": "Monkeystew",
"type": "web", "type": "web",
"main": "index.html", "main": "index.html",

View file

@ -0,0 +1,4 @@
{ "returnValue": true,
"path": "/dummy",
"content": "x TEST ENTRY 1\nx TEST ENTRY 2\nx TEST ENTRY 3\nx TEST ENTRY 4\nx TEST ENTRY 5\n"
}

View file

@ -280,6 +280,9 @@ enyo.kind({
this.cacheChanges = "COMMIT"; this.cacheChanges = "COMMIT";
this.owner.addTodo(); this.owner.addTodo();
this.completeItem = false; this.completeItem = false;
if (this.owner.preferences["archive"] == true) {
this.owner.autoarchive = true;
}
this.$.todoPopup.close(); this.$.todoPopup.close();
}, },

View file

@ -20,6 +20,7 @@ enyo.kind({
events: { events: {
"onClose": "", "onClose": "",
"onAbout": "", "onAbout": "",
"onArchive": "",
"onPrefReset": "" "onPrefReset": ""
}, },
components: [ components: [
@ -58,8 +59,19 @@ enyo.kind({
{kind: "CheckBox", name: "offline", {kind: "CheckBox", name: "offline",
preferenceProperty: "offline", preferenceProperty: "offline",
onChange: "setPreference"} onChange: "setPreference"}
]},
{kind: "Item", layoutKind: "HFlexLayout",
components: [
{content: "Auto archive"},
{kind: "Spacer"},
{kind: "CheckBox", name: "archive",
preferenceProperty: "archive",
onChange: "setPreference"}
]} ]}
]}, ]},
{kind: "Button", caption: "Archive now", onclick: "doArchive",
className: "enyo-button-dark"
},
{kind: "RowGroup", caption: "storage", components: [ {kind: "RowGroup", caption: "storage", components: [
{kind: "Item", layoutKind: "HFlexLayout", {kind: "Item", layoutKind: "HFlexLayout",
components: [ components: [

View file

@ -54,7 +54,7 @@ enyo.kind({
}, },
{name: "preferenceView", kind: "TodoPrefs", {name: "preferenceView", kind: "TodoPrefs",
onClose: "closeView", onAbout: "showAbout", onClose: "closeView", onAbout: "showAbout",
onPrefReset: "resetPreferences" onPrefReset: "resetPreferences", onArchive: "archiveTodo"
} }
]}, ]},
{name: "toaster", kind: "HtmlContent"}, {name: "toaster", kind: "HtmlContent"},
@ -71,6 +71,11 @@ enyo.kind({
method: "readfile", method: "readfile",
onSuccess: "parseFile", onFailure: "doNothing" onSuccess: "parseFile", onFailure: "doNothing"
}, },
{name: "readDoneFile", kind: "PalmService",
service: "palm://com.monkeystew.todotxtenyo.beta.service/",
method: "readfile",
onSuccess: "loadArchive", onFailure: "doNothing"
},
{name: "writeFile", kind: "PalmService", {name: "writeFile", kind: "PalmService",
service: "palm://com.monkeystew.todotxtenyo.beta.service/", service: "palm://com.monkeystew.todotxtenyo.beta.service/",
method: "writefile", onSuccess: "saveSuccess" method: "writefile", onSuccess: "saveSuccess"
@ -151,7 +156,10 @@ enyo.kind({
this.$.makeDir.call({ path: "/media/internal/todo" }); this.$.makeDir.call({ path: "/media/internal/todo" });
} }
this.recount = 0;
this.autoarchive = false;
this.todoList = []; this.todoList = [];
this.doneList = [];
this.refreshTodo(); this.refreshTodo();
}, },
@ -187,6 +195,7 @@ enyo.kind({
refreshTodo: function() { refreshTodo: function() {
if (this.preferences["storage"] == "file") { if (this.preferences["storage"] == "file") {
this.getLocalFile(); this.getLocalFile();
this.getArchiveFile();
} else if (this.preferences["storage"] == "dropbox") { } else if (this.preferences["storage"] == "dropbox") {
if (this.preferences["offline"] == false) { if (this.preferences["offline"] == false) {
var dboxpath = this.preferences["dboxpath"]; var dboxpath = this.preferences["dboxpath"];
@ -198,6 +207,29 @@ enyo.kind({
} }
}, },
archiveTodo: function() {
// TODO stub
for (item in this.todoList) {
if (this.todoList[item].detail.match(/^x\s/)) {
this.recount++;
this.doneList.push(this.todoList[item]);
this.todoList.splice(item, 1);
this.archiveTodo();
this.recount--;
}
}
if (this.recount == 0) {
console.log("done: "+this.doneList);
this.$.listView.listRefresh();
this.saveFile(
this.preferences["filepath"].replace(/todo\.txt/, "done.txt"),
this.doneList
);
this.saveFile(this.preferences["filepath"], this.todoList);
this.closeView();
}
},
addTodo: function() { addTodo: function() {
this.$.listView.addTodo(); this.$.listView.addTodo();
}, },
@ -245,6 +277,7 @@ enyo.kind({
}, },
parseFile: function(path, file) { parseFile: function(path, file) {
//console.log("path: " + path);
if (file.content != undefined) { if (file.content != undefined) {
todofile = file.content.split("\n"); todofile = file.content.split("\n");
} else { } else {
@ -311,6 +344,10 @@ enyo.kind({
this.showToast("file saved"); this.showToast("file saved");
console.log(inEvent.path + " saved..."); console.log(inEvent.path + " saved...");
console.log(inEvent.bytes + " bytes..."); console.log(inEvent.bytes + " bytes...");
if (inEvent.path == this.preferences["filepath"] && this.autoarchive == true) {
this.autoarchive = false;
this.archiveTodo();
}
} }
}, },
@ -348,6 +385,28 @@ enyo.kind({
} }
}, },
getArchiveFile: function() {
// TODO stub
var path = this.preferences["filepath"].replace(/todo\.txt/, "done.txt");
if (this.os == "BlackBerry") {
// TODO do something here
} else {
this.$.readDoneFile.call({ path: path });
}
},
loadArchive: function(path, file) {
// TODO stub
var list = file.content.split("\n");
for (item in list) {
if (list[item].length > 0) {
var task = new Object();
task.detail = list[item];
this.doneList.push(task);
}
}
},
loadDropbox: function(inSender, inResponse, inRequest) { loadDropbox: function(inSender, inResponse, inRequest) {
var file = new Object(); var file = new Object();
file.content = inResponse; file.content = inResponse;

View file

@ -3,7 +3,7 @@
"package_format_version": 2, "package_format_version": 2,
"loc_name": "Todo.txt Enyo", "loc_name": "Todo.txt Enyo",
"icon": "icon.png", "icon": "icon.png",
"version": "0.3.0", "version": "0.3.1",
"vendor": "Monkeystew", "vendor": "Monkeystew",
"app": "com.monkeystew.todotxtenyo.beta", "app": "com.monkeystew.todotxtenyo.beta",
"services": ["com.monkeystew.todotxtenyo.beta.service"] "services": ["com.monkeystew.todotxtenyo.beta.service"]