diff --git a/app/appinfo.json b/app/appinfo.json index d17b05a..a48653d 100644 --- a/app/appinfo.json +++ b/app/appinfo.json @@ -1,6 +1,6 @@ { "id": "com.monkeystew.todotxtenyo.beta", - "version": "0.3.0", + "version": "0.3.1", "vendor": "Monkeystew", "type": "web", "main": "index.html", diff --git a/app/mock/todoTxt_readDoneFile.json b/app/mock/todoTxt_readDoneFile.json new file mode 100644 index 0000000..adfc827 --- /dev/null +++ b/app/mock/todoTxt_readDoneFile.json @@ -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" +} diff --git a/app/source/TodoList.js b/app/source/TodoList.js index adf6fa1..dce2703 100644 --- a/app/source/TodoList.js +++ b/app/source/TodoList.js @@ -280,6 +280,9 @@ enyo.kind({ this.cacheChanges = "COMMIT"; this.owner.addTodo(); this.completeItem = false; + if (this.owner.preferences["archive"] == true) { + this.owner.autoarchive = true; + } this.$.todoPopup.close(); }, diff --git a/app/source/TodoPrefs.js b/app/source/TodoPrefs.js index b6ab7fa..6041e8a 100644 --- a/app/source/TodoPrefs.js +++ b/app/source/TodoPrefs.js @@ -20,6 +20,7 @@ enyo.kind({ events: { "onClose": "", "onAbout": "", + "onArchive": "", "onPrefReset": "" }, components: [ @@ -58,8 +59,19 @@ enyo.kind({ {kind: "CheckBox", name: "offline", preferenceProperty: "offline", 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: "Item", layoutKind: "HFlexLayout", components: [ diff --git a/app/source/TodoTxt.js b/app/source/TodoTxt.js index 31cdfe2..bc44330 100644 --- a/app/source/TodoTxt.js +++ b/app/source/TodoTxt.js @@ -54,7 +54,7 @@ enyo.kind({ }, {name: "preferenceView", kind: "TodoPrefs", onClose: "closeView", onAbout: "showAbout", - onPrefReset: "resetPreferences" + onPrefReset: "resetPreferences", onArchive: "archiveTodo" } ]}, {name: "toaster", kind: "HtmlContent"}, @@ -71,6 +71,11 @@ enyo.kind({ method: "readfile", 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", service: "palm://com.monkeystew.todotxtenyo.beta.service/", method: "writefile", onSuccess: "saveSuccess" @@ -151,7 +156,10 @@ enyo.kind({ this.$.makeDir.call({ path: "/media/internal/todo" }); } + this.recount = 0; + this.autoarchive = false; this.todoList = []; + this.doneList = []; this.refreshTodo(); }, @@ -187,6 +195,7 @@ enyo.kind({ refreshTodo: function() { if (this.preferences["storage"] == "file") { this.getLocalFile(); + this.getArchiveFile(); } else if (this.preferences["storage"] == "dropbox") { if (this.preferences["offline"] == false) { 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() { this.$.listView.addTodo(); }, @@ -245,6 +277,7 @@ enyo.kind({ }, parseFile: function(path, file) { + //console.log("path: " + path); if (file.content != undefined) { todofile = file.content.split("\n"); } else { @@ -311,6 +344,10 @@ enyo.kind({ this.showToast("file saved"); console.log(inEvent.path + " saved..."); 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) { var file = new Object(); file.content = inResponse; diff --git a/pkg/packageinfo.json b/pkg/packageinfo.json index c315a2e..81701c9 100644 --- a/pkg/packageinfo.json +++ b/pkg/packageinfo.json @@ -3,7 +3,7 @@ "package_format_version": 2, "loc_name": "Todo.txt Enyo", "icon": "icon.png", - "version": "0.3.0", + "version": "0.3.1", "vendor": "Monkeystew", "app": "com.monkeystew.todotxtenyo.beta", "services": ["com.monkeystew.todotxtenyo.beta.service"]