-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Js mvc #93
Open
pushpalata06
wants to merge
13
commits into
master
Choose a base branch
from
js-mvc
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Js mvc #93
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
33e99e0
rename folder CSS to css and create new folder js
pushpalata06 7612b43
js code converted into mvc of js
pushpalata06 36660ef
add noteTagController and its view
pushpalata06 1adf20f
create a note without tags
pushpalata06 c93b529
Remove create.js File
pushpalata06 18ee1b4
add View for NoteModel and change variable name of saveBtn to saveButton
pushpalata06 02bd5fb
add parameter title and description to NoteModel Constructor
pushpalata06 7abfdae
reset input data from Login View
pushpalata06 c508655
mvc code for Login functionality and solved errors
pushpalata06 d8a35c7
Remove Controller.js File
pushpalata06 3a5963e
modified structure of login controller and view to separate responsib…
dermario 9298f58
changes are modified
pushpalata06 a254a15
create separate get() request method for Login in Web
pushpalata06 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,4 +71,4 @@ | |
background-color: #2175bc; | ||
color: #fff; | ||
text-decoration: none; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
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) | ||
}); | ||
|
||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use meaningful names.