diff --git a/entry.js b/entry.js
index c41855a..6ff45b2 100644
--- a/entry.js
+++ b/entry.js
@@ -1,15 +1,65 @@
import $ from 'jquery';
import getForm from "./lib/form.data.js";
import insertData from "./lib/insertData.js";
+import deleteData from "./lib/deleteData.js";
+import updateData from "./lib/updateData.js";
+import getTodo from "./lib/todo.data.js";
+import submitUpdate from "./lib/submitUpdate.js";
+import cancel from "./lib/cancel.js";
let form = $("form");
+let todo = $("ul.todo"); //Todo List
-form.on('submit', function (e) {
+
+form.on('submit', function (e) {
+ //console.log('form.on: ', $(this));
e.preventDefault();
var value = getForm(e);
- insertData(value);
- alert(`Add item: ${value}`);
+ if(value === undefined){
+ alert("請輸入內容");
+ } else{
+ insertData(value);
+ alert(`Add item: ${value}`);
+ console.log("submit");
+ }
+});
+
+//監聽Delete button
+todo.on('click', ".btnDel",function(e) { //e: EventObject
+ //$(this).parent().remove();
+ deleteData($(this));
+ console.log($(this));
});
+//監聽Update button
+todo.on('click', '.btnUpd', function(e) {
+ updateData($(this));
+ console.log("onClick:", $(this));
+});
+
+//監聽按下Updata後出現的button Decide
+todo.on('click', '.btnDeci', function(e) {
+ e.preventDefault();
+ console.log("onClick: ", $(this));
+
+ var value = getTodo(e);
+ console.log('getTodo: ', value);
+ if(value === undefined){
+ alert("請輸入");
+ } else{
+ submitUpdate(e, value);
+ }
+ //console.log($(this));
+
+
+});
+
+//監聽按下Updata後出現的Cancel button
+todo.on('click', '.btnCancel', function(e){
+ console.log("onClick: ", $(this));
+ cancel($(this));
+});
+
+
diff --git a/index.html b/index.html
index 126d527..df4857d 100644
--- a/index.html
+++ b/index.html
@@ -6,7 +6,7 @@
This is my todo
My todo list
diff --git a/lib/cancel.js b/lib/cancel.js
new file mode 100644
index 0000000..c17dff1
--- /dev/null
+++ b/lib/cancel.js
@@ -0,0 +1,7 @@
+var $ = require('jquery');
+
+module.exports = function(target, value){
+ console.log('cancel() receive target:', target, value);
+ // ($(target).parent())[0].innerHTML = `${data}
+ // `;
+};
\ No newline at end of file
diff --git a/lib/deleteData.js b/lib/deleteData.js
new file mode 100644
index 0000000..8b7bdde
--- /dev/null
+++ b/lib/deleteData.js
@@ -0,0 +1,8 @@
+var $ = require('jquery');
+
+module.exports = function(target){
+ //$(this).parent().remove();
+ target.parent().remove();
+ console.log("deleteData");
+ return true;
+};
\ No newline at end of file
diff --git a/lib/form.data.js b/lib/form.data.js
index 5bcb395..76eead0 100644
--- a/lib/form.data.js
+++ b/lib/form.data.js
@@ -2,8 +2,9 @@ import $ from 'jquery';
module.exports = function (e) {
var target = e.currentTarget;
+ console.log(`currentTarget:${target}`);
var inputNode = $(target).find('input[name=item]');
var inputValue = inputNode.val();
- inputNode.val('').focus();
+ inputNode.val('').focus(); //?
return inputValue;
};
\ No newline at end of file
diff --git a/lib/insertData.js b/lib/insertData.js
index 4fb74ec..b7f1875 100644
--- a/lib/insertData.js
+++ b/lib/insertData.js
@@ -1,6 +1,7 @@
var $ = require('jquery');
module.exports = function (data) {
- $("ul.todo").append(`${data}`);
+ $("ul.todo").append(`${data}
+ `);
return true;
}
\ No newline at end of file
diff --git a/lib/submitUpdate.js b/lib/submitUpdate.js
new file mode 100644
index 0000000..e5b39e9
--- /dev/null
+++ b/lib/submitUpdate.js
@@ -0,0 +1,9 @@
+var $ = require('jquery');
+
+module.exports = function(e, value) {
+ var target = e.currentTarget;
+
+ //console.log("submitUpdate() receive target.parent, value:", $(target).parent()[0].innerHTML, value);
+ $(target).parent()[0].innerHTML = `${value}
+ `;
+};
\ No newline at end of file
diff --git a/lib/todo.data.js b/lib/todo.data.js
new file mode 100644
index 0000000..4103a43
--- /dev/null
+++ b/lib/todo.data.js
@@ -0,0 +1,14 @@
+import $ from 'jquery';
+
+module.exports = function (e) {
+ var target = e.currentTarget;
+ console.log(`currentTarget:${target}`); //currentTarget === this
+ var inputValue = $(target).parent().find('input').val();
+ //inputNode.val('').focus();
+ //console.log("inputValue:", inputValue);
+ return inputValue;
+ // var inputNode = $(target).find('input[name=item]');
+ // var inputValue = inputNode.val();
+ // inputNode.val('').focus(); //?
+ // return inputValue;
+};
\ No newline at end of file
diff --git a/lib/updateData.js b/lib/updateData.js
new file mode 100644
index 0000000..174617a
--- /dev/null
+++ b/lib/updateData.js
@@ -0,0 +1,16 @@
+var $ = require('jquery');
+
+module.exports = function(target){
+ // var text = target.parent().text();
+ // console.log(text);
+
+ // $(this).parent().html() = `Changed
+ // `;
+
+ (target.parent())[0].innerHTML = `
+
+ `;
+ // ($(this).parent())[0].innerHTML = `
+ // `;
+
+};
\ No newline at end of file