diff options
author | Joonghun Park <jh718.park@samsung.com> | 2013-05-31 10:20:20 +0900 |
---|---|---|
committer | Joonghun Park <jh718.park@samsung.com> | 2013-05-31 10:20:20 +0900 |
commit | dbb8db1229a22406ce8afee942838fd9e869cdec (patch) | |
tree | 813cbbbdff04a2698d048a32eda960bfc478b905 | |
parent | f04138f0f0565129d13131f90073b2c243615657 (diff) | |
download | TemporaryStorage-dbb8db1229a22406ce8afee942838fd9e869cdec.tar.gz TemporaryStorage-dbb8db1229a22406ce8afee942838fd9e869cdec.tar.bz2 TemporaryStorage-dbb8db1229a22406ce8afee942838fd9e869cdec.zip |
[TemporaryStorage] deletion of complete item functionality is added
Change-Id: I1388e17ba585f04f29623ea592fc7f926287d53c
-rwxr-xr-x | index.html | 38 | ||||
-rwxr-xr-x | js/main.js | 270 |
2 files changed, 180 insertions, 128 deletions
@@ -13,7 +13,7 @@ </head> <body> <form> - <h1>MY TASK MANAGER</h1> + <h1>My Task Manager</h1> <fieldset> <p>Task <input type="date" id="datePiker" /> @@ -23,21 +23,27 @@ <div class="submit_area"> <input type="button" id="register" value="Task Save" /> </div> - <fieldset> - <div id="divToday"> - <p id="pDate"></p> - <ul class="task_list" id="todayList"></ul> - </div> - <div id="divPrevious"> - <p>Previous Task</p> - <ul class="task_list" id="beforeList"></ul> - </div> - <div id="divAfter"> - <p>After Task</p> - <ul class="task_list" id="afterList"></ul> + <div id="divList"> + <fieldset> + <div id="divToday"> + <p id="pDate"></p> + <ul class="task_list" id="todayList"></ul> + </div> + <div id="divPrevious"> + <p>Previous Task</p> + <ul class="task_list" id="beforeList"></ul> + </div> + <div id="divAfter"> + <p>After Task</p> + <ul class="task_list" id="afterList"></ul> + </div> + </fieldset> + <div class="submit_area"> + <input type="button" id="delete" value="Delete Complete Task"/> </div> - </fieldset> - <div class="comment"> * After Task Complete, if browser (App) is re-executed, the completed Task is no longer indicated.</div> + <div class="comment"> * After Task Complete, if browser (App) is re-executed, the completed Task is no longer indicated.</div> + </div> + </form> </body> -</html> +</html>
\ No newline at end of file @@ -1,112 +1,158 @@ -$(document).ready(function () { - - var $todayHtml = $("#todayList"); - var $beforeHtml = $("#beforeList"); - var $afterHtml = $("#afterList"); - var $datePiker = $("#datePiker"); - var $pDate = $("#pDate"); - var taskDate; - var today = new Date(); - var year = today.getFullYear(); - var month = (today.getMonth() + 1) > 9 ? "" + (today.getMonth() + 1) : "0" + (today.getMonth() + 1); - var date = today.getDate() > 9 ? "" + today.getDate() : "0" + today.getDate(); - var currentDate = year + month + date; - var local = localStorage; - var session = sessionStorage; - - $datePiker.val(year + "-" + month + "-" + date); - $pDate.append("Today (" + year + "." + month + "." + date + ")"); - $todayHtml.html = ""; - $beforeHtml.html = ""; - $afterHtml.html = ""; - - //After task Complete, call the data temporarily stored in sessionStorage to maintain the data until the browser (App) is re-executed - for (var i = 0; i < session.length; i++) { - - //Import sessionStorage key to compare with the current date - taskDate = session.key(i).substring(0, 8); - - //Today Task - if (currentDate == taskDate) { - $todayHtml.append(getHtmlToStorage(i, session)); - //Previous Task - } else if (currentDate > taskDate) { - $beforeHtml.append(getHtmlToStorage(i, session)); - //After Task - } else { - $afterHtml.append(getHtmlToStorage(i, session)); - } - - //Shows Task Completed data until the browser (App) is re-executed - $("#" + "list_" + session.key(i)).addClass("del"); - $("#" + session.key(i)).attr('disabled', 'disabled'); - } - - //Call Task data stored in localStorage - for (var i = 0; i < local.length; i++) { - - //현재날짜와 비교를 위한 localStorage key 추출 - taskDate = local.key(i).substring(0, 8); - - //Today Task - if (currentDate == taskDate) { - $todayHtml.append(getHtmlToStorage(i, local)); - //Previous Task - } else if (currentDate > taskDate) { - $beforeHtml.append(getHtmlToStorage(i, local)); - //After Task - } else { - $afterHtml.append(getHtmlToStorage(i, local)); - } - } - - $todayHtml[0].innerHTML == "" ? $("#divToday").hide() : ""; - $beforeHtml[0].innerHTML == "" ? $("#divPrevious").hide() : ""; - $afterHtml[0].innerHTML == "" ? $("#divAfter").hide() : ""; - - //Task Save - $("#register").on("click", function () { - - if ($("#txtTask").val() == "") { - alert("Please enter the task."); - } else { - if (confirm("Are you sure you want to task stored?")) { - var key = getKeyToDate($("#datePiker").val()); - - //Store localStorage data - local.setItem(key, $("#txtTask").val()); - location.reload(); - } - } - }); -}); - -//Create key by using the storage date -function getHtmlToStorage(index, storage) { - return "<li id='" + "list_" + storage.key(index) + "'>" + storage.getItem(storage.key(index)) + - "<input type='checkbox' id='" + storage.key(index) + "' value='" + storage.key(index) + - "' onclick='taskComplete(this.value)' /></li>"; -} - -//storage delete -function taskComplete(key) { - if ($("#" + key).is(":checked")) { - - //For completed Task, Strikeout is indicated - $("#" + "list_" + key).addClass("del"); - $("#" + key).attr('disabled', 'disabled'); - - //taskComplete deleted from localStorage is temporarily stored in sessionStorage - sessionStorage.setItem(key, localStorage.getItem(key)); - - //The completed Task is deleted from localStorage. - localStorage.removeItem(key); - } -} - -//Create key by using the storage date -function getKeyToDate(date) { - if (date) { - return (date.replace(/\-/g, "") + Math.random()).replace(/\./g, ""); - } -} +var local = localStorage;
+var session = sessionStorage;
+
+$(document).ready(function() {
+ // Get information storage
+ getStorage();
+ // Task Save
+ $("#register").on("click", function() {
+
+ if ($("#txtTask").val() == "") {
+ alert("Please enter the task.");
+ } else {
+ if (confirm("Are you sure you want to task stored?")) {
+ var key = getKeyToDate($("#datePiker").val());
+
+ // Store localStorage data
+ local.setItem(key, $("#txtTask").val());
+ location.reload();
+ }
+ }
+ });
+
+ // Task Delete
+ $("#delete").on("click", function() {
+ $(":checkbox[name='storageCheck']:checked").each(function(i, v) {
+ // The completed Task is deleted from localStorage.
+ local.removeItem(v.value);
+ session.removeItem(v.value);
+ getStorage();
+ });
+ });
+});
+
+/**
+ * Call Task data stored in Storage
+ */
+function getHtmlToStorage(index, storage) {
+ return "<li id='"
+ + "list_"
+ + storage.key(index)
+ + "'>"
+ + storage.getItem(storage.key(index))
+ + "<input type='checkbox' id='"
+ + storage.key(index)
+ + "' value='"
+ + storage.key(index)
+ + "' name='storageCheck' onclick='taskComplete(this.value)' /></li>";
+}
+
+/**
+ * Get information storage
+ */
+function getStorage() {
+
+ var $todayHtml = $("#todayList");
+ var $beforeHtml = $("#beforeList");
+ var $afterHtml = $("#afterList");
+ var $datePiker = $("#datePiker");
+ var $pDate = $("#pDate");
+ var taskDate;
+ var today = new Date();
+ var year = today.getFullYear();
+ var month = (today.getMonth() + 1) > 9 ? "" + (today.getMonth() + 1) : "0"
+ + (today.getMonth() + 1);
+ var date = today.getDate() > 9 ? "" + today.getDate() : "0"
+ + today.getDate();
+ var currentDate = year + month + date;
+
+ $datePiker.val(year + "-" + month + "-" + date);
+ $pDate[0].innerHTML = "";
+ $todayHtml[0].innerHTML = "";
+ $beforeHtml[0].innerHTML = "";
+ $afterHtml[0].innerHTML = "";
+ $pDate.append("Today (" + year + "." + month + "." + date + ")");
+
+ // After task Complete, call the data temporarily stored in sessionStorage
+ // to maintain the data until the browser (App) is re-executed
+ for ( var i = 0; i < session.length; i++) {
+
+ // Import sessionStorage key to compare with the current date
+ taskDate = session.key(i).substring(0, 8);
+
+ // Today Task
+ if (currentDate == taskDate) {
+ $todayHtml.append(getHtmlToStorage(i, session));
+ // Previous Task
+ } else if (currentDate > taskDate) {
+ $beforeHtml.append(getHtmlToStorage(i, session));
+ // After Task
+ } else {
+ $afterHtml.append(getHtmlToStorage(i, session));
+ }
+
+ // Shows Task Completed data until the browser (App) is re-executed
+ $("#list_" + session.key(i)).addClass("del");
+ $("#" + session.key(i)).attr("checked", true);
+ }
+
+ // Call Task data stored in localStorage
+ for ( var i = 0; i < local.length; i++) {
+ var isAppend = true;
+ // Import localStorage key to compared with the current date
+ taskDate = local.key(i).substring(0, 8);
+
+ for ( var j = 0; j < session.length; j++) {
+ if (local.key(i) == session.key(j)) {
+ isAppend = false;
+ break;
+ }
+ }
+
+ if (isAppend) {
+ // Today Task
+ if (currentDate == taskDate) {
+ $todayHtml.append(getHtmlToStorage(i, local));
+ // Previous Task
+ } else if (currentDate > taskDate) {
+ $beforeHtml.append(getHtmlToStorage(i, local));
+ // After Task
+ } else {
+ $afterHtml.append(getHtmlToStorage(i, local));
+ }
+ }
+ }
+
+ $todayHtml[0].innerHTML == "" ? $("#divToday").hide() : "";
+ $beforeHtml[0].innerHTML == "" ? $("#divPrevious").hide() : "";
+ $afterHtml[0].innerHTML == "" ? $("#divAfter").hide() : "";
+
+ if (local.length == 0 && session.length == 0)
+ $("#divList").hide();
+}
+
+/**
+ * task complete stored in sessionStorage
+ */
+function taskComplete(key) {
+
+ if ($("#" + key).is(":checked")) {
+
+ // For completed Task, Strikeout is indicated
+ $("#list_" + key).addClass("del");
+
+ // task Complete stored in sessionStorage
+ session.setItem(key, local.getItem(key));
+ } else {
+ $("#list_" + key).removeClass("del");
+ }
+}
+
+/**
+ * Create key by using the storage date
+ */
+function getKeyToDate(date) {
+ if (date) {
+ return (date.replace(/\-/g, "") + Math.random()).replace(/\./g, "");
+ }
+}
\ No newline at end of file |