From 33e99e01d40e9041b35076bb88d1223335b41b07 Mon Sep 17 00:00:00 2001 From: pushpalata06 Date: Wed, 27 May 2015 06:17:24 +0000 Subject: [PATCH 01/13] rename folder CSS to css and create new folder js --- app/View/Create.php | 2 +- public/{CSS => css}/style.css | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename public/{CSS => css}/style.css (99%) diff --git a/app/View/Create.php b/app/View/Create.php index 8a0c1aad..76384cbf 100644 --- a/app/View/Create.php +++ b/app/View/Create.php @@ -9,7 +9,7 @@ - + + - +

Create Note :
@@ -193,7 +29,7 @@ function getUserId() {
    - +
diff --git a/public/js/create.js b/public/js/create.js new file mode 100644 index 00000000..07e60de8 --- /dev/null +++ b/public/js/create.js @@ -0,0 +1,192 @@ +var UserTagModel = function() {}; + +var UserTagView = function() {}; + +var NoteTagView = function() {}; + +var DeleteLinkView = function() {}; + +var UserTagController = function() {}; + +function passUserTagsAndCreateNoteTags(userTagsArray) { + var userId = getUserId(); + console.log(userId); + + var noteTags = []; + for (var i = 0; i < userTagsArray.length; i++) { + var userTag = userTagsArray[i]; + userTag.userId = userId; + noteTags[i] = { + "id": noteTagId, + "noteId": noteId, + "userTagId": userTagId, + "isDeleted": isDeleted, + "userTag": userTag + }; + } + console.log(noteTags); + + passNoteTagsAndCreateNoteModel(noteTags); +} + +function passNoteTagsAndCreateNoteModel(noteTags) { + var title = document.getElementById("title").value; + var body = document.getElementById("body").value; + + var noteTagId = document.getElementById("noteTagId").value; + var noteId = document.getElementById("noteId").value; + var userTagId = document.getElementById("userTagId").value; + var isDeleted = document.getElementById("isDeleted").value; + + var json = { + "title": title, + "body": body, + "noteTags": noteTags + }; + document.getElementById("noteModel").value = JSON.stringify(json); +} + +function getUserId() { + var allcookies = document.cookie; + console.log(allcookies); + + // Get all the cookies pairs in an array + cookiearray = allcookies.split(';'); + console.log(cookiearray); + + // Now take key value pair out of this array + for (var i = 0; i < cookiearray.length; i++) { + name = cookiearray[i].split('=')[0].trim(); + value = cookiearray[i].split('=')[1].trim(); + if (name == "userId") + return value; + } +} +NoteTagView.addTag = function(txtIdValue) { + if ((txtIdValue).length == 0) { + alert("The textbox should not be empty"); + return; + }; + + var userTag = { + "id": null, + "userId": "null", + "tag": txtIdValue, + "isDeleted": "0" + }; + + NoteTagView.prototype.createNoteTags(userTag); + + document.getElementById("txtTags").value = ""; +} + +DeleteLinkView.prototype.createDeleteLink = function(userTag) { + var x = document.createElement("A"); + var t = document.createTextNode("Delete"); + + x.setAttribute("href", "#"); + x.setAttribute("id", "del"); + x.setAttribute("value", JSON.stringify(userTag)); + x.appendChild(t); + return x; +}; +var userTagsArray = []; +NoteTagView.prototype.createNoteTags = function(userTag) { + var noteTags = document.getElementById('note-tags'); + var liClickTag = document.createElement("LI"); + + var div = document.createElement("span"); + div.appendChild(document.createTextNode(userTag.tag)); + + liClickTag.appendChild(div); + + liClickTag.userTag = userTag; + + var appendDelete = DeleteLinkView.prototype.createDeleteLink(userTag); + + liClickTag.appendChild(appendDelete); + noteTags.appendChild(liClickTag); + + userTagsArray.push(liClickTag.userTag); + + $("a[id^='del']").live("click", null, function(e) { + var li = $(this).parent(); + var tag = li[0].childNodes[0].innerText; + + console.log(tag); + console.log(userTagsArray); + for (var i = 0; i < userTagsArray.length; i++) { + if (tag == userTagsArray[i].tag) + userTagsArray.splice(i, 1); + passUserTagsAndCreateNoteTags(userTagsArray); + } + li.remove(); + }); + passUserTagsAndCreateNoteTags(userTagsArray); +}; + +UserTagView.prototype.setTags = function(userTagsFromServer) { + var userTags = document.getElementById('user-tags'); + for (var i = 0; i < userTagsFromServer.length; i++) { + //create and append tag to tag list + + var li = document.createElement("LI"); + + li.setAttribute("class", "inputTags"); + li.appendChild(document.createTextNode(userTagsFromServer[i].tag)); + li.userTagsFromServer = userTagsFromServer[i]; + + li.addEventListener("click", function() { + console.log(this.userTagsFromServer); + var userTag = this.userTagsFromServer; + + NoteTagView.prototype.createNoteTags(userTag); + + }, false); + userTags.appendChild(li); + } +}; + +UserTagModel.search = function() { + $.ajax({ + type: 'GET', + url: '/notes/api/userTag', + data: 'id=testdata', + datatype: "JSON", + cache: false, + + success: function(result) { + console.log(result); + var userTagsFromServer = JSON.parse(result); + + UserTagView.prototype.setTags(userTagsFromServer); + + }, + error: function(result) { + var errorMsg = JSON.parse(result); + alert("Message: " + errorMsg); + } + }); +}; +UserTagController.prototype.loadView = function(txtIdValue) { + var noteTagView = NoteTagView.addTag(txtIdValue); + console.log(noteTagView); + +}; +UserTagController.prototype.loadModel = function() { + var userTagModel = UserTagModel.search(); + console.log(userTagModel); + +}; +$(document).ready(function() { + + var userTagController = new UserTagController; + userTagController.loadModel(); + + var addBtnClk = document.getElementById("addBtnClk"); + addBtnClk.addEventListener('click', function() { + var txtIdValue = document.getElementById("txtTags").value; + userTagController.loadView(txtIdValue) + }); + +}); \ No newline at end of file From 36660ef68a9abcf0ade1240ea1d91fcc99b7fbb3 Mon Sep 17 00:00:00 2001 From: pushpalata06 Date: Thu, 28 May 2015 07:20:09 +0000 Subject: [PATCH 03/13] add noteTagController and its view --- public/js/create.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/public/js/create.js b/public/js/create.js index 07e60de8..94d1dae0 100644 --- a/public/js/create.js +++ b/public/js/create.js @@ -8,6 +8,8 @@ var DeleteLinkView = function() {}; var UserTagController = function() {}; +var NoteTagController = function() {}; + function passUserTagsAndCreateNoteTags(userTagsArray) { var userId = getUserId(); console.log(userId); @@ -168,7 +170,7 @@ UserTagModel.search = function() { } }); }; -UserTagController.prototype.loadView = function(txtIdValue) { +NoteTagController.prototype.loadView = function(txtIdValue) { var noteTagView = NoteTagView.addTag(txtIdValue); console.log(noteTagView); @@ -183,10 +185,12 @@ $(document).ready(function() { var userTagController = new UserTagController; userTagController.loadModel(); + var noteTagController = new NoteTagController; + var addBtnClk = document.getElementById("addBtnClk"); addBtnClk.addEventListener('click', function() { var txtIdValue = document.getElementById("txtTags").value; - userTagController.loadView(txtIdValue) + noteTagController.loadView(txtIdValue) }); }); \ No newline at end of file From 1adf20ff57fb3c681390680e99250c4be976f89d Mon Sep 17 00:00:00 2001 From: pushpalata06 Date: Thu, 4 Jun 2015 13:41:54 +0000 Subject: [PATCH 04/13] create a note without tags --- app/View/Create.php | 24 ++-- app/View/Notes.php | 5 +- public/css/style.css | 15 +-- public/js/Controller/Controller.js | 7 ++ public/js/Model/NoteModel.js | 42 +++++++ public/js/View/create.js | 195 +++++++++++++++++++++++++++++ 6 files changed, 260 insertions(+), 28 deletions(-) create mode 100644 public/js/Controller/Controller.js create mode 100644 public/js/Model/NoteModel.js create mode 100644 public/js/View/create.js diff --git a/app/View/Create.php b/app/View/Create.php index b7caea2d..4b0f40dd 100644 --- a/app/View/Create.php +++ b/app/View/Create.php @@ -6,11 +6,15 @@ - - + + + + + + @@ -18,28 +22,16 @@
Create Note :
-
- -
- -
-
    - - -
+
- - - -
- + diff --git a/app/View/Notes.php b/app/View/Notes.php index bfa6f972..f4c4ea12 100644 --- a/app/View/Notes.php +++ b/app/View/Notes.php @@ -6,12 +6,13 @@ - Create - Logout + + diff --git a/public/css/style.css b/public/css/style.css index 8127e338..55131cb4 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -61,14 +61,9 @@ } .inputTags { - list-style:none; - display: block; - width: 100px; - margin-bottom: 3px; - margin-left: 10px; - border-left: 10px solid #1958b7; - border-right: 10px solid #508fc4; - background-color: #2175bc; - color: #fff; - text-decoration: none; + width: 120px; + height: 20px; + overflow: hidden; + background: no-repeat right #ddd; + border: 1px solid #ccc; } \ No newline at end of file diff --git a/public/js/Controller/Controller.js b/public/js/Controller/Controller.js new file mode 100644 index 00000000..56a80fc3 --- /dev/null +++ b/public/js/Controller/Controller.js @@ -0,0 +1,7 @@ +function Controller () { + NoteModel.prototype.saveBtnOnclick(); +} + +$(function () { + var controller = new Controller(); +}); \ No newline at end of file diff --git a/public/js/Model/NoteModel.js b/public/js/Model/NoteModel.js new file mode 100644 index 00000000..9c32b206 --- /dev/null +++ b/public/js/Model/NoteModel.js @@ -0,0 +1,42 @@ +function NoteModel () { + this.title = title; + this.description = description; + + this.getTitle = function() { + return this.title; + }; + + this.getDescription = function() { + return this.description; + }; +} + +NoteModel.prototype.saveBtnOnclick = function() { + var saveBtnId = document.getElementById('save'); + + saveBtnId.addEventListener("click", function() { + var title = document.getElementById('title').value; + console.log(title); + + var description = document.getElementById('description').value; + console.log(description); + + var noteTags = []; + + var noteModel = new NoteModel(title, description); + console.log(noteModel.getTitle()); + console.log(noteModel.getDescription()); + + NoteModel.prototype.createNoteModel(title, description, noteTags); + + }); +}; +NoteModel.prototype.createNoteModel = function(title, description, noteTags) { + var noteModel = { + "title": title, + "body": description, + "noteTags": noteTags + }; + console.log(noteModel); + new NoteModelView(noteModel); +}; diff --git a/public/js/View/create.js b/public/js/View/create.js new file mode 100644 index 00000000..17d1cbed --- /dev/null +++ b/public/js/View/create.js @@ -0,0 +1,195 @@ +var UserTagModel = function() {}; + +var UserTagView = function() {}; + +var NoteTagView = function() {}; + +var DeleteLinkView = function() {}; + +var UserTagController = function() {}; + +var NoteTagController = function() {}; + +function passUserTagsAndCreateNoteTags(userTagsArray) { + var userId = getUserId(); + console.log(userId); + + var noteTags = []; + for (var i = 0; i < userTagsArray.length; i++) { + var userTag = userTagsArray[i]; + userTag.userId = userId; + noteTags[i] = { + "id": noteTagId, + "noteId": noteId, + "userTagId": userTagId, + "isDeleted": isDeleted, + "userTag": userTag + }; + } + console.log(noteTags); + + passNoteTagsAndCreateNoteModel(noteTags); +} + +function passNoteTagsAndCreateNoteModel(noteTags) { + var title = document.getElementById("title").value; + var body = document.getElementById("body").value; + + var noteTagId = document.getElementById("noteTagId").value; + var noteId = document.getElementById("noteId").value; + var userTagId = document.getElementById("userTagId").value; + var isDeleted = document.getElementById("isDeleted").value; + + var json = { + "title": title, + "body": body, + "noteTags": noteTags + }; + document.getElementById("noteModel").value = JSON.stringify(json); +} + +function getUserId() { + var allcookies = document.cookie; + console.log(allcookies); + + // Get all the cookies pairs in an array + cookiearray = allcookies.split(';'); + console.log(cookiearray); + + // Now take key value pair out of this array + for (var i = 0; i < cookiearray.length; i++) { + name = cookiearray[i].split('=')[0].trim(); + value = cookiearray[i].split('=')[1].trim(); + if (name == "userId") + return value; + } +} +NoteTagView.addTag = function(txtIdValue) { + if ((txtIdValue).length == 0) { + alert("The textbox should not be empty"); + return; + }; + + var userTag = { + "id": null, + "userId": "null", + "tag": txtIdValue, + "isDeleted": "0" + }; + + NoteTagView.prototype.createNoteTags(userTag); + + document.getElementById("txtTags").value = ""; +} + +DeleteLinkView.prototype.createDeleteLink = function(userTag) { + var anchorTag = document.createElement("A"); + var deleteText = document.createTextNode("Delete"); + + anchorTag.setAttribute("href", "#"); + anchorTag.setAttribute("id", "del"); + anchorTag.setAttribute("value", JSON.stringify(userTag)); + anchorTag.appendChild(deleteText); + return anchorTag; +}; + +var userTagsArray = []; +NoteTagView.prototype.createNoteTags = function(userTag) { + var noteTags = document.getElementById('note-tags'); + var liClickTag = document.createElement("LI"); + + var div = document.createElement("span"); + div.appendChild(document.createTextNode(userTag.tag)); + + liClickTag.appendChild(div); + + liClickTag.userTag = userTag; + + var appendDelete = DeleteLinkView.prototype.createDeleteLink(userTag); + + liClickTag.appendChild(appendDelete); + noteTags.appendChild(liClickTag); + + userTagsArray.push(liClickTag.userTag); + + $("a[id^='del']").live("click", null, function(e) { + var li = $(this).parent(); + var tag = li[0].childNodes[0].innerText; + + console.log(tag); + console.log(userTagsArray); + for (var i = 0; i < userTagsArray.length; i++) { + if (tag == userTagsArray[i].tag) + userTagsArray.splice(i, 1); + passUserTagsAndCreateNoteTags(userTagsArray); + } + li.remove(); + }); + passUserTagsAndCreateNoteTags(userTagsArray); +}; + +UserTagView.prototype.setTags = function(userTagsFromServer) { + var userTags = document.getElementById('user-tags'); + for (var i = 0; i < userTagsFromServer.length; i++) { + //create and append tag to tag list + + var li = document.createElement("LI"); + + li.setAttribute("class", "inputTags"); + li.appendChild(document.createTextNode(userTagsFromServer[i].tag)); + li.userTagsFromServer = userTagsFromServer[i]; + + li.addEventListener("click", function() { + console.log(this.userTagsFromServer); + var userTag = this.userTagsFromServer; + + NoteTagView.prototype.createNoteTags(userTag); + + }, false); + userTags.appendChild(li); + } +}; + +UserTagModel.search = function() { + $.ajax({ + type: 'GET', + url: '/notes/api/userTag', + data: 'id=testdata', + datatype: "JSON", + cache: false, + + success: function(result) { + console.log(result); + var userTagsFromServer = JSON.parse(result); + + UserTagView.prototype.setTags(userTagsFromServer); + }, + error: function(result) { + var errorMsg = JSON.parse(result); + alert("Message: " + errorMsg); + } + }); +}; +NoteTagController.prototype.loadView = function(txtIdValue) { + var noteTagView = NoteTagView.addTag(txtIdValue); + console.log(noteTagView); + +}; +UserTagController.prototype.loadModel = function() { + var userTagModel = UserTagModel.search(); + console.log(userTagModel); + +}; +$(document).ready(function() { + console.log("Hello"); + var userTagController = new UserTagController; + userTagController.loadModel(); + + var noteTagController = new NoteTagController; + + var addBtnClk = document.getElementById("addBtnClk"); + addBtnClk.addEventListener('click', function() { + var txtIdValue = document.getElementById("txtTags").value; + noteTagController.loadView(txtIdValue); + }); +}); From c93b5299da25b6c774fc100bdc5b8ed046919ded Mon Sep 17 00:00:00 2001 From: pushpalata06 Date: Thu, 4 Jun 2015 13:45:08 +0000 Subject: [PATCH 05/13] Remove create.js File --- public/js/View/create.js | 195 -------------------------------------- public/js/create.js | 196 --------------------------------------- 2 files changed, 391 deletions(-) delete mode 100644 public/js/View/create.js delete mode 100644 public/js/create.js diff --git a/public/js/View/create.js b/public/js/View/create.js deleted file mode 100644 index 17d1cbed..00000000 --- a/public/js/View/create.js +++ /dev/null @@ -1,195 +0,0 @@ -var UserTagModel = function() {}; - -var UserTagView = function() {}; - -var NoteTagView = function() {}; - -var DeleteLinkView = function() {}; - -var UserTagController = function() {}; - -var NoteTagController = function() {}; - -function passUserTagsAndCreateNoteTags(userTagsArray) { - var userId = getUserId(); - console.log(userId); - - var noteTags = []; - for (var i = 0; i < userTagsArray.length; i++) { - var userTag = userTagsArray[i]; - userTag.userId = userId; - noteTags[i] = { - "id": noteTagId, - "noteId": noteId, - "userTagId": userTagId, - "isDeleted": isDeleted, - "userTag": userTag - }; - } - console.log(noteTags); - - passNoteTagsAndCreateNoteModel(noteTags); -} - -function passNoteTagsAndCreateNoteModel(noteTags) { - var title = document.getElementById("title").value; - var body = document.getElementById("body").value; - - var noteTagId = document.getElementById("noteTagId").value; - var noteId = document.getElementById("noteId").value; - var userTagId = document.getElementById("userTagId").value; - var isDeleted = document.getElementById("isDeleted").value; - - var json = { - "title": title, - "body": body, - "noteTags": noteTags - }; - document.getElementById("noteModel").value = JSON.stringify(json); -} - -function getUserId() { - var allcookies = document.cookie; - console.log(allcookies); - - // Get all the cookies pairs in an array - cookiearray = allcookies.split(';'); - console.log(cookiearray); - - // Now take key value pair out of this array - for (var i = 0; i < cookiearray.length; i++) { - name = cookiearray[i].split('=')[0].trim(); - value = cookiearray[i].split('=')[1].trim(); - if (name == "userId") - return value; - } -} -NoteTagView.addTag = function(txtIdValue) { - if ((txtIdValue).length == 0) { - alert("The textbox should not be empty"); - return; - }; - - var userTag = { - "id": null, - "userId": "null", - "tag": txtIdValue, - "isDeleted": "0" - }; - - NoteTagView.prototype.createNoteTags(userTag); - - document.getElementById("txtTags").value = ""; -} - -DeleteLinkView.prototype.createDeleteLink = function(userTag) { - var anchorTag = document.createElement("A"); - var deleteText = document.createTextNode("Delete"); - - anchorTag.setAttribute("href", "#"); - anchorTag.setAttribute("id", "del"); - anchorTag.setAttribute("value", JSON.stringify(userTag)); - anchorTag.appendChild(deleteText); - return anchorTag; -}; - -var userTagsArray = []; -NoteTagView.prototype.createNoteTags = function(userTag) { - var noteTags = document.getElementById('note-tags'); - var liClickTag = document.createElement("LI"); - - var div = document.createElement("span"); - div.appendChild(document.createTextNode(userTag.tag)); - - liClickTag.appendChild(div); - - liClickTag.userTag = userTag; - - var appendDelete = DeleteLinkView.prototype.createDeleteLink(userTag); - - liClickTag.appendChild(appendDelete); - noteTags.appendChild(liClickTag); - - userTagsArray.push(liClickTag.userTag); - - $("a[id^='del']").live("click", null, function(e) { - var li = $(this).parent(); - var tag = li[0].childNodes[0].innerText; - - console.log(tag); - console.log(userTagsArray); - for (var i = 0; i < userTagsArray.length; i++) { - if (tag == userTagsArray[i].tag) - userTagsArray.splice(i, 1); - passUserTagsAndCreateNoteTags(userTagsArray); - } - li.remove(); - }); - passUserTagsAndCreateNoteTags(userTagsArray); -}; - -UserTagView.prototype.setTags = function(userTagsFromServer) { - var userTags = document.getElementById('user-tags'); - for (var i = 0; i < userTagsFromServer.length; i++) { - //create and append tag to tag list - - var li = document.createElement("LI"); - - li.setAttribute("class", "inputTags"); - li.appendChild(document.createTextNode(userTagsFromServer[i].tag)); - li.userTagsFromServer = userTagsFromServer[i]; - - li.addEventListener("click", function() { - console.log(this.userTagsFromServer); - var userTag = this.userTagsFromServer; - - NoteTagView.prototype.createNoteTags(userTag); - - }, false); - userTags.appendChild(li); - } -}; - -UserTagModel.search = function() { - $.ajax({ - type: 'GET', - url: '/notes/api/userTag', - data: 'id=testdata', - datatype: "JSON", - cache: false, - - success: function(result) { - console.log(result); - var userTagsFromServer = JSON.parse(result); - - UserTagView.prototype.setTags(userTagsFromServer); - }, - error: function(result) { - var errorMsg = JSON.parse(result); - alert("Message: " + errorMsg); - } - }); -}; -NoteTagController.prototype.loadView = function(txtIdValue) { - var noteTagView = NoteTagView.addTag(txtIdValue); - console.log(noteTagView); - -}; -UserTagController.prototype.loadModel = function() { - var userTagModel = UserTagModel.search(); - console.log(userTagModel); - -}; -$(document).ready(function() { - console.log("Hello"); - var userTagController = new UserTagController; - userTagController.loadModel(); - - var noteTagController = new NoteTagController; - - var addBtnClk = document.getElementById("addBtnClk"); - addBtnClk.addEventListener('click', function() { - var txtIdValue = document.getElementById("txtTags").value; - noteTagController.loadView(txtIdValue); - }); -}); diff --git a/public/js/create.js b/public/js/create.js deleted file mode 100644 index 94d1dae0..00000000 --- a/public/js/create.js +++ /dev/null @@ -1,196 +0,0 @@ -var UserTagModel = function() {}; - -var UserTagView = function() {}; - -var NoteTagView = function() {}; - -var DeleteLinkView = function() {}; - -var UserTagController = function() {}; - -var NoteTagController = function() {}; - -function passUserTagsAndCreateNoteTags(userTagsArray) { - var userId = getUserId(); - console.log(userId); - - var noteTags = []; - for (var i = 0; i < userTagsArray.length; i++) { - var userTag = userTagsArray[i]; - userTag.userId = userId; - noteTags[i] = { - "id": noteTagId, - "noteId": noteId, - "userTagId": userTagId, - "isDeleted": isDeleted, - "userTag": userTag - }; - } - console.log(noteTags); - - passNoteTagsAndCreateNoteModel(noteTags); -} - -function passNoteTagsAndCreateNoteModel(noteTags) { - var title = document.getElementById("title").value; - var body = document.getElementById("body").value; - - var noteTagId = document.getElementById("noteTagId").value; - var noteId = document.getElementById("noteId").value; - var userTagId = document.getElementById("userTagId").value; - var isDeleted = document.getElementById("isDeleted").value; - - var json = { - "title": title, - "body": body, - "noteTags": noteTags - }; - document.getElementById("noteModel").value = JSON.stringify(json); -} - -function getUserId() { - var allcookies = document.cookie; - console.log(allcookies); - - // Get all the cookies pairs in an array - cookiearray = allcookies.split(';'); - console.log(cookiearray); - - // Now take key value pair out of this array - for (var i = 0; i < cookiearray.length; i++) { - name = cookiearray[i].split('=')[0].trim(); - value = cookiearray[i].split('=')[1].trim(); - if (name == "userId") - return value; - } -} -NoteTagView.addTag = function(txtIdValue) { - if ((txtIdValue).length == 0) { - alert("The textbox should not be empty"); - return; - }; - - var userTag = { - "id": null, - "userId": "null", - "tag": txtIdValue, - "isDeleted": "0" - }; - - NoteTagView.prototype.createNoteTags(userTag); - - document.getElementById("txtTags").value = ""; -} - -DeleteLinkView.prototype.createDeleteLink = function(userTag) { - var x = document.createElement("A"); - var t = document.createTextNode("Delete"); - - x.setAttribute("href", "#"); - x.setAttribute("id", "del"); - x.setAttribute("value", JSON.stringify(userTag)); - x.appendChild(t); - return x; -}; -var userTagsArray = []; -NoteTagView.prototype.createNoteTags = function(userTag) { - var noteTags = document.getElementById('note-tags'); - var liClickTag = document.createElement("LI"); - - var div = document.createElement("span"); - div.appendChild(document.createTextNode(userTag.tag)); - - liClickTag.appendChild(div); - - liClickTag.userTag = userTag; - - var appendDelete = DeleteLinkView.prototype.createDeleteLink(userTag); - - liClickTag.appendChild(appendDelete); - noteTags.appendChild(liClickTag); - - userTagsArray.push(liClickTag.userTag); - - $("a[id^='del']").live("click", null, function(e) { - var li = $(this).parent(); - var tag = li[0].childNodes[0].innerText; - - console.log(tag); - console.log(userTagsArray); - for (var i = 0; i < userTagsArray.length; i++) { - if (tag == userTagsArray[i].tag) - userTagsArray.splice(i, 1); - passUserTagsAndCreateNoteTags(userTagsArray); - } - li.remove(); - }); - passUserTagsAndCreateNoteTags(userTagsArray); -}; - -UserTagView.prototype.setTags = function(userTagsFromServer) { - var userTags = document.getElementById('user-tags'); - for (var i = 0; i < userTagsFromServer.length; i++) { - //create and append tag to tag list - - var li = document.createElement("LI"); - - li.setAttribute("class", "inputTags"); - li.appendChild(document.createTextNode(userTagsFromServer[i].tag)); - li.userTagsFromServer = userTagsFromServer[i]; - - li.addEventListener("click", function() { - console.log(this.userTagsFromServer); - var userTag = this.userTagsFromServer; - - NoteTagView.prototype.createNoteTags(userTag); - - }, false); - userTags.appendChild(li); - } -}; - -UserTagModel.search = function() { - $.ajax({ - type: 'GET', - url: '/notes/api/userTag', - data: 'id=testdata', - datatype: "JSON", - cache: false, - - success: function(result) { - console.log(result); - var userTagsFromServer = JSON.parse(result); - - UserTagView.prototype.setTags(userTagsFromServer); - - }, - error: function(result) { - var errorMsg = JSON.parse(result); - alert("Message: " + errorMsg); - } - }); -}; -NoteTagController.prototype.loadView = function(txtIdValue) { - var noteTagView = NoteTagView.addTag(txtIdValue); - console.log(noteTagView); - -}; -UserTagController.prototype.loadModel = function() { - var userTagModel = UserTagModel.search(); - console.log(userTagModel); - -}; -$(document).ready(function() { - - var userTagController = new UserTagController; - userTagController.loadModel(); - - var noteTagController = new NoteTagController; - - var addBtnClk = document.getElementById("addBtnClk"); - addBtnClk.addEventListener('click', function() { - var txtIdValue = document.getElementById("txtTags").value; - noteTagController.loadView(txtIdValue) - }); - -}); \ No newline at end of file From 18ee1b4eca1fc85ec678e060a5ae1674eca8617d Mon Sep 17 00:00:00 2001 From: pushpalata06 Date: Fri, 5 Jun 2015 04:56:30 +0000 Subject: [PATCH 06/13] add View for NoteModel and change variable name of saveBtn to saveButton --- app/View/Create.php | 2 +- public/js/Model/NoteModel.js | 4 ++-- public/js/View/NoteModel.js | 4 ++++ 3 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 public/js/View/NoteModel.js diff --git a/app/View/Create.php b/app/View/Create.php index 4b0f40dd..1ca7fe42 100644 --- a/app/View/Create.php +++ b/app/View/Create.php @@ -7,7 +7,7 @@ - + diff --git a/public/js/Model/NoteModel.js b/public/js/Model/NoteModel.js index 9c32b206..297dd31a 100644 --- a/public/js/Model/NoteModel.js +++ b/public/js/Model/NoteModel.js @@ -12,9 +12,9 @@ function NoteModel () { } NoteModel.prototype.saveBtnOnclick = function() { - var saveBtnId = document.getElementById('save'); + var saveButton = document.getElementById('save'); - saveBtnId.addEventListener("click", function() { + saveButton.addEventListener("click", function() { var title = document.getElementById('title').value; console.log(title); diff --git a/public/js/View/NoteModel.js b/public/js/View/NoteModel.js new file mode 100644 index 00000000..3872e34d --- /dev/null +++ b/public/js/View/NoteModel.js @@ -0,0 +1,4 @@ +function NoteModelView (noteModel) { + console.log(noteModel); + document.getElementById("noteModel").value = JSON.stringify(noteModel); +} \ No newline at end of file From 02bd5fb2bf9fba25fa60a4e0839b7b7e048743c9 Mon Sep 17 00:00:00 2001 From: pushpalata06 Date: Fri, 5 Jun 2015 07:08:25 +0000 Subject: [PATCH 07/13] add parameter title and description to NoteModel Constructor --- public/js/Model/NoteModel.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/public/js/Model/NoteModel.js b/public/js/Model/NoteModel.js index 297dd31a..c45740d0 100644 --- a/public/js/Model/NoteModel.js +++ b/public/js/Model/NoteModel.js @@ -1,4 +1,4 @@ -function NoteModel () { +function NoteModel (title, description) { this.title = title; this.description = description; @@ -12,9 +12,9 @@ function NoteModel () { } NoteModel.prototype.saveBtnOnclick = function() { - var saveButton = document.getElementById('save'); + var saveBtnId = document.getElementById('save'); - saveButton.addEventListener("click", function() { + saveBtnId.addEventListener("click", function() { var title = document.getElementById('title').value; console.log(title); @@ -27,7 +27,7 @@ NoteModel.prototype.saveBtnOnclick = function() { console.log(noteModel.getTitle()); console.log(noteModel.getDescription()); - NoteModel.prototype.createNoteModel(title, description, noteTags); + NoteModel.prototype.createNoteModel(noteModel.getTitle(), noteModel.getDescription(), noteTags); }); }; From 7abfdaec4baf12fdbe5c5fddbe235020d65400e5 Mon Sep 17 00:00:00 2001 From: pushpalata06 Date: Wed, 10 Jun 2015 12:21:38 +0000 Subject: [PATCH 08/13] reset input data from Login View --- app/View/Login.php | 22 +++++++++++++----- public/js/Controller/LoginController.js | 31 +++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 public/js/Controller/LoginController.js diff --git a/app/View/Login.php b/app/View/Login.php index 3ee3cbfc..1b341be1 100644 --- a/app/View/Login.php +++ b/app/View/Login.php @@ -10,18 +10,29 @@ .error { } + + + + + + - - + - + + + + + + - - + +
Email:
Password:
- diff --git a/public/js/Controller/LoginController.js b/public/js/Controller/LoginController.js new file mode 100644 index 00000000..5483fb15 --- /dev/null +++ b/public/js/Controller/LoginController.js @@ -0,0 +1,31 @@ +function LoginController() { + +} +LoginController.prototype.init = function() { + console.log("In init Function.."); + var loginView = new LoginView( + this.setResetClickedHandler(function(e) { + loginView.resetData(); + }) + ); +}; +LoginController.prototype.setResetClickedHandler = function(handler) { + console.log("In onLogin Reset Clicked Handler.."); + + var resetButton = document.getElementById('reset'); + resetButton.addEventListener("click", function(e) { + handler(e); + }, false); +} + +function LoginView() { + + this.resetData = function() { + document.getElementById('email').value = ""; + document.getElementById('password').value = ""; + } +} +$(function() { + var loginController = new LoginController(); + loginController.init(); +}) \ No newline at end of file From c508655fe241625088c0aaef83fb253f7be96935 Mon Sep 17 00:00:00 2001 From: pushpalata06 Date: Wed, 17 Jun 2015 11:43:34 +0000 Subject: [PATCH 09/13] mvc code for Login functionality and solved errors --- app/Controller/Web/Session.php | 28 +++++++----- app/Controller/Web/User.php | 2 + app/Domain/Session.php | 37 ++++++++-------- app/Domain/User.php | 16 +++---- app/Model/Session.php | 12 ++--- app/Response/Response.php | 2 +- app/Routes/Routes.php | 5 ++- app/Service/Session.php | 4 +- app/Service/User.php | 4 +- app/View/Create.php | 23 ++++++++-- app/View/Login.php | 47 ++++++++++++-------- app/View/Notes.php | 8 +++- public/js/Controller/LoginController.js | 58 ++++++++++++++++++++----- public/js/Controller/NotesController.js | 10 +++++ public/js/Model/LoginModel.js | 37 ++++++++++++++++ public/js/Model/NoteModel.js | 42 ------------------ public/js/View/LoginView.js | 37 ++++++++++++++++ public/js/View/NoteModel.js | 4 -- public/js/View/NotesView.js | 6 +++ tests/Domain/SessionTest.php | 13 ++++-- tests/Domain/UserTest.php | 6 +-- tests/Routes/RoutesTest.php | 41 +++++++++++++---- tests/Service/SessionTest.php | 4 +- tests/View/LoginTest.php | 3 +- 24 files changed, 301 insertions(+), 148 deletions(-) create mode 100644 public/js/Controller/NotesController.js create mode 100644 public/js/Model/LoginModel.js delete mode 100644 public/js/Model/NoteModel.js create mode 100644 public/js/View/LoginView.js delete mode 100644 public/js/View/NoteModel.js create mode 100644 public/js/View/NotesView.js diff --git a/app/Controller/Web/Session.php b/app/Controller/Web/Session.php index 342a99f1..11b281e3 100644 --- a/app/Controller/Web/Session.php +++ b/app/Controller/Web/Session.php @@ -4,6 +4,7 @@ use Notes\View\View as View; use Notes\Service\Session as SessionService; use Notes\Model\Session as SessionModel; +use Notes\Model\User as UserModel; use Notes\Response\Response as Response; use Notes\Request\Request as Request; use Notes\Exception\ModelNotFoundException as ModelNotFoundException; @@ -24,24 +25,31 @@ public function get() public function post() { - $input = $this->request->getUrlParams(); + $input = $this->request->getData(); + + $userModel = new UserModel(); + + $userModel->setId($input['id']); + $userModel->setFirstName($input['firstName']); + $userModel->setLastName($input['lastName']); + $userModel->setEmail($input['email']); + $userModel->setPassword($input['password']); + $userModel->setCreatedOn($input['createdOn']); $sessionService = new SessionService(); try { - $response = $sessionService->login($input); + $response = $sessionService->login($userModel); if ($response instanceof SessionModel) { setcookie('userId', $response->getUserId(), time() + (86400 * 30), "/"); setcookie('authToken', $response->getAuthToken(), time() + (86400 * 30), "/"); - $app = \Slim\Slim::getInstance('developer'); - $app->redirect("/notes"); + + $objResponse = new Response($response->toArray(), 1, "SUCCESS"); + + echo $objResponse->getResponse(); } - } catch (\InvalidArgumentException $error) { - $response = $error->getMessage(); - $objResponse = new Response($response); - $this->view->render("Login.php", $objResponse->getResponse()); } catch (ModelNotFoundException $error) { $response = $error->getMessage(); - $objResponse = new Response($response); - $this->view->render("Login.php", $objResponse->getResponse()); + $objResponse = new Response($response, 0, "FAILURE"); + echo $objResponse->getResponse(); } } } diff --git a/app/Controller/Web/User.php b/app/Controller/Web/User.php index cfe52dcd..de0b54a6 100644 --- a/app/Controller/Web/User.php +++ b/app/Controller/Web/User.php @@ -3,6 +3,7 @@ use Notes\View\View as View; use Notes\Service\User as UserService; +use Notes\Factory\User as UserFactory; use Notes\Model\User as UserModel; use Notes\Response\Response as Response; use Notes\Exception\ModelNotFoundException as ModelNotFoundException; @@ -23,6 +24,7 @@ public function get() public function post() { $input = $this->request->getUrlParams(); + $userService = new UserService(); try { $response = $userService->create($input); diff --git a/app/Domain/Session.php b/app/Domain/Session.php index 32d8a871..4a7208f5 100755 --- a/app/Domain/Session.php +++ b/app/Domain/Session.php @@ -11,6 +11,8 @@ use Notes\Validator\InputValidator as InputValidator; +use Notes\Factory\User as UserFactory; + class Session { public function __construct() @@ -18,61 +20,59 @@ public function __construct() $this->validator = new InputValidator(); } - public function create($userInput) + public function create($userModel) { $sessionModel = new sessionModel(); $userDomain = new UserDomain(); - $userModelRead = $userDomain->readByUserNameAndPassword($userInput); + $userModelRead = $userDomain->readByUserNameAndPassword($userModel); $sessionModel->setUserId($userModelRead->getId()); $randomNumber = rand(); - + $password = $userModelRead->getPassword(); $sessionModel->createAuthToken($password, $randomNumber); $sessionModel->setCreatedOn(date("Y-m-d H:i:s")); - if ($this->validator->notNull($sessionModel->getUserId()) - && $this->validator->validNumber($sessionModel->getUserId()) - && $this->validator->notNull($sessionModel->getAuthToken())) { + $this->validator->notNull($sessionModel->getUserId()); + $this->validator->validNumber($sessionModel->getUserId()); + $this->validator->notNull($sessionModel->getAuthToken()); + $sessionMapper = new SessionMapper(); $sessionModel = $sessionMapper->create($sessionModel); return $sessionModel; - } } public function read($sessionModel) { - if ($this->validator->notNull($sessionModel->getId()) - && $this->validator->validNumber($sessionModel->getId())) { + $this->validator->notNull($sessionModel->getId()); + $this->validator->validNumber($sessionModel->getId()); $sessionMapper = new SessionMapper(); $sessionModel = $sessionMapper->read($sessionModel); return $sessionModel; - } } public function getSessionByAuthTokenAndUserId($sessionModel) { - if ($this->validator->notNull($sessionModel->getUserId()) - && $this->validator->validNumber($sessionModel->getUserId()) - && $this->validator->notNull($sessionModel->getAuthToken())) { + $this->validator->notNull($sessionModel->getUserId()); + $this->validator->validNumber($sessionModel->getUserId()); + $this->validator->notNull($sessionModel->getAuthToken()); $sessionMapper = new SessionMapper(); $sessionModel = $sessionMapper->read($sessionModel); return $sessionModel; - } } public function delete($sessionModel) { - if ($this->validator->notNull($sessionModel->getId()) - && $this->validator->validNumber($sessionModel->getId()) - && $this->validator->notNull($sessionModel->getUserId()) - && $this->validator->validNumber($sessionModel->getUserId())) { + $this->validator->notNull($sessionModel->getId()); + $this->validator->validNumber($sessionModel->getId()); + $this->validator->notNull($sessionModel->getUserId()); + $this->validator->validNumber($sessionModel->getUserId()); $sessionModel->setIsExpired(1); $sessionModel->setExpiredOn(date("Y-m-d H:i:s")); $sessionMapper = new SessionMapper(); @@ -80,6 +80,5 @@ public function delete($sessionModel) $sessionModel = $sessionMapper->update($sessionModel); return $sessionModel; - } } } diff --git a/app/Domain/User.php b/app/Domain/User.php index c803876c..01e62c21 100755 --- a/app/Domain/User.php +++ b/app/Domain/User.php @@ -26,7 +26,10 @@ public function create($input) { $userFactory = new UserFactory(); $userModel = $userFactory->create($input); - $userModel->setCreatedOn(date("Y-m-d H:i:s")); + + $date = date("Y-m-d H:i:s"); + $userModel->setCreatedOn($date); + $userMapper = new UserMapper(); $userModel = $userMapper->create($userModel); return $userModel; @@ -44,15 +47,12 @@ public function read($input) } - public function readByUsernameandPassword($input) + public function readByUsernameandPassword($userModel) { + $userMapper = new UserMapper(); + $userModel = $userMapper->read($userModel); - $userFactory = new UserFactory(); - $userModel = $userFactory->create($input); - - $userMapper = new UserMapper(); - $userModel = $userMapper->read($userModel); - return $userModel; + return $userModel; } public function update($input) diff --git a/app/Model/Session.php b/app/Model/Session.php index ce121a46..84c9d831 100755 --- a/app/Model/Session.php +++ b/app/Model/Session.php @@ -4,12 +4,12 @@ class Session extends Model { - private $id; - private $userId; - private $authToken; - private $createdOn; - private $expiredOn; - private $isExpired; + protected $id; + protected $userId; + protected $authToken; + protected $createdOn; + protected $expiredOn; + protected $isExpired; public function setId($id) { diff --git a/app/Response/Response.php b/app/Response/Response.php index 396b8819..a88179fa 100644 --- a/app/Response/Response.php +++ b/app/Response/Response.php @@ -7,7 +7,7 @@ class Response private $status; private $message; private $version = '1.0.0'; - private $data; + protected $data; private $debugData; public function __construct($data = null, $status = '200', $message = 'OK', $debugData = null) diff --git a/app/Routes/Routes.php b/app/Routes/Routes.php index e70c14c0..bbb29f15 100644 --- a/app/Routes/Routes.php +++ b/app/Routes/Routes.php @@ -21,7 +21,10 @@ $request = $application->request(); $objRequest = new Request(); - $objRequest->setUrlParams($request->post()); + + $objRequest->setData($request->getBody()); + $objRequest->setHeaders($request->headers); + $objRequest->setCookies($request->cookies); $sessionController = new Session($objRequest); $sessionController->post(); diff --git a/app/Service/Session.php b/app/Service/Session.php index e5fcf804..bef98054 100644 --- a/app/Service/Session.php +++ b/app/Service/Session.php @@ -12,11 +12,11 @@ public function __construct() } - public function login($userInput) + public function login($userModel) { $sessionDomain = new SessionDomain(); - $session = $sessionDomain->create($userInput); + $session = $sessionDomain->create($userModel); return $session; } diff --git a/app/Service/User.php b/app/Service/User.php index 359cb28a..2b43b72f 100755 --- a/app/Service/User.php +++ b/app/Service/User.php @@ -11,11 +11,11 @@ public function __construct() { } - public function create($request) + public function create($input) { $userDomain=new UserDomain(); - $response=$userDomain->create($request); + $response=$userDomain->create($input); return $response; diff --git a/app/View/Create.php b/app/View/Create.php index 1ca7fe42..3b76dc1b 100644 --- a/app/View/Create.php +++ b/app/View/Create.php @@ -3,10 +3,14 @@ - + + + + @@ -19,7 +23,7 @@

-
+
Create Note :
@@ -28,7 +32,17 @@
+
+
    + + +
+
+ + + +
@@ -36,6 +50,9 @@
- + + + + diff --git a/app/View/Login.php b/app/View/Login.php index 1b341be1..c4268c20 100644 --- a/app/View/Login.php +++ b/app/View/Login.php @@ -11,41 +11,52 @@ } - - - - - + + + + + + + + + + + + +
+ - + - + + + - - - - - - + ?> - +
Email:
Password:
+ + +
Error :-

+
diff --git a/app/View/Notes.php b/app/View/Notes.php index f4c4ea12..5497b06f 100644 --- a/app/View/Notes.php +++ b/app/View/Notes.php @@ -8,9 +8,15 @@ } + + + + - + + 'Pushpa@123' ); + $userModel = new UserModel(); + + $userModel->setEmail($userInput['email']); + $userModel->setPassword($userInput['password']); $sessionModel = new sessionModel(); $sessionDomain = new Session(); - $sessionModel = $sessionDomain->create($userInput); + $sessionModel = $sessionDomain->create($userModel); $this->assertEquals(4, $sessionModel->getId()); $this->assertEquals(3, $sessionModel->getUserId()); @@ -196,7 +200,10 @@ public function it_should_throw_exception_with_invalid_email_password() 'email' => 'abcd@gmail.com', 'password' => 'Joy%hj5487' ); - + $userModel = new UserModel(); + + $userModel->setEmail($userInput['email']); + $userModel->setPassword($userInput['password']); $input = array( 'authToken' => 'pqr', @@ -210,6 +217,6 @@ public function it_should_throw_exception_with_invalid_email_password() $sessionDomain = new Session(); - $sessionModel = $sessionDomain->create($userInput, $sessionModel); + $sessionModel = $sessionDomain->create($userModel, $sessionModel); } } diff --git a/tests/Domain/UserTest.php b/tests/Domain/UserTest.php index 62fa8e1b..106dbad4 100755 --- a/tests/Domain/UserTest.php +++ b/tests/Domain/UserTest.php @@ -48,8 +48,6 @@ public function testCanInsertRecord() 'email' => 'kirti.6@gmail.com', 'password' => 'abc@$#A123' ); - $userFactory = new UserFactory(); - $userModel = $userFactory->create($input); $userDomain = new User(); $userModel = $userDomain->create($input); @@ -114,7 +112,7 @@ public function testCanReadRecordByUsernameAndPassword() $userFactory = new UserFactory(); $userModel = $userFactory->create($input); $userDomain = new User(); - $userModel = $userDomain->readByUsernameandPassword($input); + $userModel = $userDomain->readByUsernameandPassword($userModel); $expectedDataSet = $this->createXmlDataSet(dirname(__FILE__) . '/_files/user_seed.xml'); $actualDataSet = $this->getConnection()->createDataSet(array( 'Users' @@ -147,7 +145,7 @@ public function testUserCanThrowModelNotFoundExceptionWhenUserNamePasswordDoesNo $userModel = $userFactory->create($input); $userDomain = new User(); - $userModel = $userDomain->readByUsernameandPassword($input); + $userModel = $userDomain->readByUsernameandPassword($userModel); } diff --git a/tests/Routes/RoutesTest.php b/tests/Routes/RoutesTest.php index d5fcad4e..6c624817 100644 --- a/tests/Routes/RoutesTest.php +++ b/tests/Routes/RoutesTest.php @@ -76,7 +76,6 @@ public function user_registration_failed_and_should_stay_on_same_page() 'password' => "AFd@756htrfj"); $client->post('/register' ,$parameters); - $this->assertEquals(200, $client->response->status()); } @@ -100,12 +99,23 @@ public function loginpage_should_be_loaded() public function loginpage_should_be_loaded_after_user_logged_in() { $client=new ClientRequest(); - $parameters = array('email' => "William@Edwards.com", - 'password' => "AFd@756htrfj"); - $client->post('/login', $parameters); + $parameters = array( + 'id' => null, + 'firstName' =>null, + 'lastName' => null, + 'email' => "William@Edwards.com", + 'password' => "AFd@756htrfj", + 'createdOn' => null + ); + $data = json_encode($parameters); + $client->post('/login', $data); + + $response = json_decode($client->response->body(), true); + + $this->assertEquals(1, $response['status']); + $this->assertEquals("SUCCESS", $response['message']); - $this->assertEquals(302, $client->response->status()); - $this->assertEquals('/notes', $client->response->getIterator()["Location"]); + $this->assertEquals(200, $client->response->status()); } /** @@ -115,10 +125,23 @@ public function loginpage_should_be_loaded_after_user_logged_in() public function user_login_failed_and_should_stay_on_same_page() { $client=new ClientRequest(); - $parameters = array('email' => "Joy@Edwards.com", - 'password' => "AFd756htrfj"); + $parameters = array( + 'id' => null, + 'firstName' =>null, + 'lastName' => null, + 'email' => "Joy@Edwards.com", + 'password' => "AFd756htrfj", + 'createdOn' => null + ); + + $data = json_encode($parameters); + $client->post('/login', $data); + + $response = json_decode($client->response->body(), true); + + $this->assertEquals(0, $response['status']); + $this->assertEquals("FAILURE", $response['message']); - $client->post('/login', $parameters); $this->assertEquals(200, $client->response->status()); } } diff --git a/tests/Service/SessionTest.php b/tests/Service/SessionTest.php index ee37308d..f68750c8 100644 --- a/tests/Service/SessionTest.php +++ b/tests/Service/SessionTest.php @@ -56,7 +56,7 @@ public function it_should_login_with_valid_email_password() $sessionModel = new sessionModel(); $sessionService = new Session(); - $sessionModel = $sessionService->login($userInput); + $sessionModel = $sessionService->login($userModel); $this->assertEquals(4, $sessionModel->getId()); $this->assertEquals(3, $sessionModel->getUserId()); @@ -218,6 +218,6 @@ public function it_should_throw_exception_with_invalid_email_password() $userModel->setPassword($userInput['password']); $sessionService = new Session(); - $sessionModel = $sessionService->login($userInput); + $sessionModel = $sessionService->login($userModel); } } diff --git a/tests/View/LoginTest.php b/tests/View/LoginTest.php index 752db79c..be7e3913 100644 --- a/tests/View/LoginTest.php +++ b/tests/View/LoginTest.php @@ -30,7 +30,8 @@ public function response_data_should_access_in_login_View() $dom->loadHTML($output); - $element = $dom->getElementsByTagName('div'); + $element = $dom->getElementsByTagName('p'); + $this->assertEquals("Invalid Email", $element->item(0)->textContent); } public function tearDown() From d8a35c701a3f59e0b16df1d2ab9a715cd4c53795 Mon Sep 17 00:00:00 2001 From: pushpalata06 Date: Wed, 17 Jun 2015 12:13:01 +0000 Subject: [PATCH 10/13] Remove Controller.js File --- public/js/Controller/Controller.js | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 public/js/Controller/Controller.js diff --git a/public/js/Controller/Controller.js b/public/js/Controller/Controller.js deleted file mode 100644 index 56a80fc3..00000000 --- a/public/js/Controller/Controller.js +++ /dev/null @@ -1,7 +0,0 @@ -function Controller () { - NoteModel.prototype.saveBtnOnclick(); -} - -$(function () { - var controller = new Controller(); -}); \ No newline at end of file From 3a5963ea5d6e4bbd3b602ffb290925c677e3d4a0 Mon Sep 17 00:00:00 2001 From: Vagrant User Date: Fri, 19 Jun 2015 06:48:16 +0000 Subject: [PATCH 11/13] modified structure of login controller and view to separate responsibilites --- app/Routes/Routes.php | 2 +- public/js/Controller/LoginController.js | 89 ++++++++++--------------- public/js/View/LoginView.js | 34 ++++++++-- 3 files changed, 64 insertions(+), 61 deletions(-) mode change 100644 => 100755 app/Routes/Routes.php mode change 100644 => 100755 public/js/Controller/LoginController.js mode change 100644 => 100755 public/js/View/LoginView.js diff --git a/app/Routes/Routes.php b/app/Routes/Routes.php old mode 100644 new mode 100755 index bbb29f15..abbfa997 --- a/app/Routes/Routes.php +++ b/app/Routes/Routes.php @@ -17,7 +17,7 @@ $sessionController->get(); }); -$application->post('/login', function () use ($application) { +$application->post('/api/session', function () use ($application) { $request = $application->request(); $objRequest = new Request(); diff --git a/public/js/Controller/LoginController.js b/public/js/Controller/LoginController.js old mode 100644 new mode 100755 index 64bf17c0..7b6692ca --- a/public/js/Controller/LoginController.js +++ b/public/js/Controller/LoginController.js @@ -1,65 +1,44 @@ -function LoginController() { +var utils = { + post: function(url, request, isSync, onSuccess, onFailure) { -} -LoginController.prototype.init = function() { - console.log("In init Function.."); - - var loginView = new LoginView(); - - this.setResetClickedHandler(function(e) { - loginView.resetData(); - }); - - this.setLoginClickedHandler(function(e) { - //read data from View - var userModel = loginView.readUserData(); - console.log(userModel); - - - //call api - var loginModel = new LoginModel(); - - var login = '/login'; - var response = loginModel.callApi(login, userModel, function(postCallbackData) { - console.log(postCallbackData); + }, + get: function(url, request, isSync, onSuccess, onFailure) { - if (postCallbackData.status == 0) { - var OnLoginerror = loginModel.onFailure(userModel, postCallbackData); - console.log(OnLoginerror); - - loginView.showError(OnLoginerror); - } else { - var onLoginSuccess = loginModel.onSuccess(userModel, postCallbackData); - loginView.hide(); - console.log(onLoginSuccess); - - this.notesView = new NotesView(); - this.notesView.show(onLoginSuccess); - } - }); - }); -}; - -LoginController.prototype.setLoginClickedHandler = function(handler) { - console.log("In onLoginClickedHandler..."); - - var loginButton = document.getElementById('login'); - - loginButton.addEventListener("click", function(e) { - handler(e); - }, false); + } } -LoginController.prototype.setResetClickedHandler = function(handler) { - console.log("In onLogin Reset Clicked Handler.."); +var loginController = { + loginView: null, + init: function() { + this.loginView = new LoginView(function(e) { + loginController.loginView.resetData(); + }, function(e) { + //read data from View + var userModel = loginController.loginView.readUserData(); + console.log(userModel); + + //call api + var loginModel = new LoginModel(); + + var login = '/api/session'; + + var Request = new Request(userModel); + + utils.post('/api/session', request, function(response) { + loginController.loginView.hide(response); + console.log("OnSuccess Response:", response); + //transfer control to notes controller + notesController.init(); + }, function(response) { + console.log("OnFailure Response:", response); + loginController.loginView.showError(response); + }); - var resetButton = document.getElementById('reset'); - resetButton.addEventListener("click", function(e) { - handler(e); - }, false); + }); + this.loginView.show(); + } } $(function() { - var loginController = new LoginController(); loginController.init(); }) \ No newline at end of file diff --git a/public/js/View/LoginView.js b/public/js/View/LoginView.js old mode 100644 new mode 100755 index 0d04a96f..8a9f8790 --- a/public/js/View/LoginView.js +++ b/public/js/View/LoginView.js @@ -1,9 +1,10 @@ -function LoginView() { +function LoginView(loginClickedHandler, resetClickedHandler) { + this.resetData = function() { document.getElementById('email').value = ""; document.getElementById('password').value = ""; - } + }; this.readUserData = function() { var id = document.getElementById('id').value; @@ -24,14 +25,37 @@ function LoginView() { email: email, createdOn: createdOn }; - } + }; + + this.setLoginClickedHandler = function(handler) { + console.log("In onLoginClickedHandler..."); + var loginButton = document.getElementById('login'); + + loginButton.addEventListener("click", function(e) { + handler(e); + }, false); + }; + + this.setResetClickedHandler = function(handler) { + console.log("In onLogin Reset Clicked Handler.."); + var resetButton = document.getElementById('reset'); + resetButton.addEventListener("click", function(e) { + handler(e); + }, false); + }; this.hide = function() { document.getElementById('container').style.display = "none"; - } + }; this.showError = function(errorMessage) { console.log(errorMessage); alert(errorMessage.errorMsg); - } + }; + this.show=function(){ + + }; + this.setLoginClickedHandler(loginClickedHandler); + this.setResetClickedHandler(resetClickedHandler); + } \ No newline at end of file From 9298f58b0586548ed103d1d720ec2d2a8577d1d4 Mon Sep 17 00:00:00 2001 From: pushpalata06 Date: Fri, 19 Jun 2015 11:59:05 +0000 Subject: [PATCH 12/13] changes are modified --- app/Controller/{Web => Api}/Session.php | 4 +-- public/js/Controller/LoginController.js | 33 ++++++++++++++-------- public/js/Controller/NotesController.js | 18 ++++++------ public/js/Model/LoginModel.js | 37 ------------------------- public/js/View/LoginView.js | 11 ++++---- public/js/View/NotesView.js | 2 +- tests/Routes/RoutesTest.php | 4 +-- 7 files changed, 41 insertions(+), 68 deletions(-) rename app/Controller/{Web => Api}/Session.php (98%) mode change 100644 => 100755 mode change 100644 => 100755 public/js/Controller/NotesController.js delete mode 100644 public/js/Model/LoginModel.js mode change 100644 => 100755 public/js/View/NotesView.js mode change 100644 => 100755 tests/Routes/RoutesTest.php diff --git a/app/Controller/Web/Session.php b/app/Controller/Api/Session.php old mode 100644 new mode 100755 similarity index 98% rename from app/Controller/Web/Session.php rename to app/Controller/Api/Session.php index 11b281e3..a248a603 --- a/app/Controller/Web/Session.php +++ b/app/Controller/Api/Session.php @@ -1,5 +1,5 @@ request->getData(); $userModel = new UserModel(); - $userModel->setId($input['id']); $userModel->setFirstName($input['firstName']); $userModel->setLastName($input['lastName']); $userModel->setEmail($input['email']); $userModel->setPassword($input['password']); $userModel->setCreatedOn($input['createdOn']); + $sessionService = new SessionService(); try { $response = $sessionService->login($userModel); diff --git a/public/js/Controller/LoginController.js b/public/js/Controller/LoginController.js index 7b6692ca..476e37e6 100755 --- a/public/js/Controller/LoginController.js +++ b/public/js/Controller/LoginController.js @@ -1,6 +1,24 @@ var utils = { - post: function(url, request, isSync, onSuccess, onFailure) { - + post: function(url, request, isAsync, onSuccess, onFailure) { + var data = JSON.stringify(request); + + var xhr = new XMLHttpRequest(); + xhr.open('POST', url, isAsync); + xhr.setRequestHeader('Content-Type', 'application/json'); + xhr.send(data); + + xhr.onreadystatechange = function() { + + if (xhr.readyState == 4 && xhr.status == 200) { + var response = JSON.parse(xhr.responseText); + console.log("OnXhr Success Response: ", response); + if (response.status == 0) { + onFailure(response); + } else { + onSuccess(response); + } + } + } }, get: function(url, request, isSync, onSuccess, onFailure) { @@ -15,16 +33,9 @@ var loginController = { }, function(e) { //read data from View var userModel = loginController.loginView.readUserData(); - console.log(userModel); - + //call api - var loginModel = new LoginModel(); - - var login = '/api/session'; - - var Request = new Request(userModel); - - utils.post('/api/session', request, function(response) { + utils.post('/api/session', userModel, true, function(response) { loginController.loginView.hide(response); console.log("OnSuccess Response:", response); //transfer control to notes controller diff --git a/public/js/Controller/NotesController.js b/public/js/Controller/NotesController.js old mode 100644 new mode 100755 index 501d1b91..b2a5b1c4 --- a/public/js/Controller/NotesController.js +++ b/public/js/Controller/NotesController.js @@ -1,10 +1,8 @@ -function NotesController() { -} -NotesController.prototype.init = function() { - console.log("in init"); -} - -$(function() { - var notesController = new NotesController(); - notesController.init(); -}) \ No newline at end of file +var notesController = { + notesView: null, + init: function() { + + this.notesView = new NotesView(); + this.notesView.show() + } +} \ No newline at end of file diff --git a/public/js/Model/LoginModel.js b/public/js/Model/LoginModel.js deleted file mode 100644 index 562b85f6..00000000 --- a/public/js/Model/LoginModel.js +++ /dev/null @@ -1,37 +0,0 @@ -function LoginModel() { - - this.callApi = function(login, userModel, postCallback) { - console.log("In Api"); - var data = JSON.stringify(userModel); - var xhr = new XMLHttpRequest(); - - xhr.open('POST', login, true); - xhr.setRequestHeader('Content-Type', 'application/json'); - - xhr.send(data); - - xhr.onreadystatechange = function() { - - if (xhr.readyState == 4 && xhr.status == 200) { - console.log(xhr); - console.log(xhr.getAllResponseHeaders()); - var response = JSON.parse(xhr.responseText); - console.log(response); - postCallback(response); - } - } - } - this.onSuccess = function(input, ouput) { - return { - input: input, - ouput: ouput, - }; - } - this.onFailure = function(input, ouput) { - return { - input: input, - ouput: ouput, - errorMsg: ouput.data - }; - } -} \ No newline at end of file diff --git a/public/js/View/LoginView.js b/public/js/View/LoginView.js index 8a9f8790..5c2e984a 100755 --- a/public/js/View/LoginView.js +++ b/public/js/View/LoginView.js @@ -1,5 +1,4 @@ -function LoginView(loginClickedHandler, resetClickedHandler) { - +function LoginView(resetClickedHandler, loginClickedHandler) { this.resetData = function() { document.getElementById('email').value = ""; @@ -48,13 +47,15 @@ function LoginView(loginClickedHandler, resetClickedHandler) { document.getElementById('container').style.display = "none"; }; - this.showError = function(errorMessage) { - console.log(errorMessage); - alert(errorMessage.errorMsg); + this.showError = function(response) { + var errorMessage = response.data; + alert(errorMessage); }; + this.show=function(){ }; + this.setLoginClickedHandler(loginClickedHandler); this.setResetClickedHandler(resetClickedHandler); diff --git a/public/js/View/NotesView.js b/public/js/View/NotesView.js old mode 100644 new mode 100755 index b8a99e27..f5a9dd08 --- a/public/js/View/NotesView.js +++ b/public/js/View/NotesView.js @@ -1,5 +1,5 @@ function NotesView() { - this.show = function(onLoginSuccess) { + this.show = function() { console.log("In notes View"); window.location.href = './notes'; } diff --git a/tests/Routes/RoutesTest.php b/tests/Routes/RoutesTest.php old mode 100644 new mode 100755 index 6c624817..f71892bd --- a/tests/Routes/RoutesTest.php +++ b/tests/Routes/RoutesTest.php @@ -108,7 +108,7 @@ public function loginpage_should_be_loaded_after_user_logged_in() 'createdOn' => null ); $data = json_encode($parameters); - $client->post('/login', $data); + $client->post('/api/session', $data); $response = json_decode($client->response->body(), true); @@ -135,7 +135,7 @@ public function user_login_failed_and_should_stay_on_same_page() ); $data = json_encode($parameters); - $client->post('/login', $data); + $client->post('/api/session', $data); $response = json_decode($client->response->body(), true); From a254a15d2ee39a419f72082c99896bf4c9b4a549 Mon Sep 17 00:00:00 2001 From: pushpalata06 Date: Fri, 19 Jun 2015 12:43:20 +0000 Subject: [PATCH 13/13] create separate get() request method for Login in Web --- app/Controller/Api/Session.php | 4 ---- app/Controller/Web/Login.php | 20 ++++++++++++++++++++ app/Routes/Routes.php | 6 ++++-- 3 files changed, 24 insertions(+), 6 deletions(-) create mode 100755 app/Controller/Web/Login.php diff --git a/app/Controller/Api/Session.php b/app/Controller/Api/Session.php index a248a603..bcad8c07 100755 --- a/app/Controller/Api/Session.php +++ b/app/Controller/Api/Session.php @@ -18,10 +18,6 @@ public function __construct($request) $this->request = $request; $this->view = new View(); } - public function get() - { - $this->view->render("Login.php"); - } public function post() { diff --git a/app/Controller/Web/Login.php b/app/Controller/Web/Login.php new file mode 100755 index 00000000..babfe4ac --- /dev/null +++ b/app/Controller/Web/Login.php @@ -0,0 +1,20 @@ +request = $request; + $this->view = new View(); + } + public function get() + { + $this->view->render("Login.php"); + } +} diff --git a/app/Routes/Routes.php b/app/Routes/Routes.php index abbfa997..58df5d70 100755 --- a/app/Routes/Routes.php +++ b/app/Routes/Routes.php @@ -2,6 +2,8 @@ namespace Notes\Controller\Web; use Notes\Controller\Api\UserTag as UserTag; +use Notes\Controller\Api\Session as Session; + use Notes\Request\Request as Request; $application->get('/:route', function ($route) use ($application) { @@ -13,8 +15,8 @@ $application->get('/login', function () use ($application) { $request = new Request(); - $sessionController = new Session($request); - $sessionController->get(); + $loginController = new Login($request); + $loginController->get(); }); $application->post('/api/session', function () use ($application) {