-
Notifications
You must be signed in to change notification settings - Fork 97
/
app4.js
110 lines (91 loc) · 2.91 KB
/
app4.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
var Notes = Ember.Application.create({
});
/** Router **/
Notes.Router.map(function () {
this.resource('notes', {path: "/"}, function() {
this.route('note', {path: "/note/:note_id"});
});
});
Notes.NotesRoute = Ember.Route.extend({
model: function() {
return this.store.find('note');
}
});
Notes.NotesNoteRoute = Ember.Route.extend({
model: function(note) {
return this.store.find('note', note.note_id);
}
});
/** Ember Data **/
Notes.Note = DS.Model.extend({
name: DS.attr('string'),
value: DS.attr('string'),
introduction: function() {
var intro = "";
if (this.get('value')) {
intro = this.get('value').substring(0, 20);
}
return intro;
}.property('value')
});
Notes.Store = DS.Store.extend({
adapter: DS.LSAdapter
});
Notes.NotesController = Ember.ArrayController.extend({
needs: ['notesNote'],
newNoteName: null,
selectedNoteBinding: 'controllers.notesNote.model',
actions: {
createNewNote: function() {
var content = this.get('content');
var newNoteName = this.get('newNoteName');
var unique = newNoteName != null && newNoteName.length > 1;
content.forEach(function(note) {
if (newNoteName === note.get('name')) {
unique = false; return;
}
});
if (unique) {
var newNote = this.store.createRecord('note');
newNote.set('id', newNoteName);
newNote.set('name', newNoteName);
newNote.save();
this.set('newNoteName', null);
} else {
alert('Note must have a unique name of at least 2 characters!');
}
},
doDeleteNote: function (note) {
this.set('noteForDeletion', note);
$("#confirmDeleteNoteDialog").modal({"show": true});
},
doCancelDelete: function () {
this.set('noteForDeletion', null);
$("#confirmDeleteNoteDialog").modal('hide');
},
doConfirmDelete: function () {
var selectedNote = this.get('noteForDeletion');
this.set('noteForDeletion', null);
if (selectedNote) {
this.store.deleteRecord(selectedNote);
selectedNote.save();
if (this.get('controllers.notesNote.model.id') === selectedNote.get('id')) {
this.transitionToRoute('notes');
}
}
$("#confirmDeleteNoteDialog").modal('hide');
}
}
});
Notes.NotesNoteController = Ember.ObjectController.extend({
myAwesomeProperty: "Yes its Awesome!",
actions: {
updateNote: function() {
var content = this.get('content');
console.log(content);
if (content) {
content.save();
}
}
}
});