angularjs mobile v0.1
This commit is contained in:
111
public/mobile2/js/memory-services.js
Normal file
111
public/mobile2/js/memory-services.js
Normal file
@ -0,0 +1,111 @@
|
||||
|
||||
angular.module('myApp.memoryServices', [])
|
||||
.factory('Employee', [
|
||||
function () {
|
||||
return {
|
||||
query: function () {
|
||||
return employees;
|
||||
},
|
||||
get: function (employee) {
|
||||
return findById(parseInt(employee.employeeId));
|
||||
}
|
||||
}
|
||||
|
||||
}])
|
||||
.factory('Report', [
|
||||
function () {
|
||||
return {
|
||||
query: function (employee) {
|
||||
return findByManager(parseInt(employee.employeeId));
|
||||
}
|
||||
}
|
||||
|
||||
}])
|
||||
|
||||
// Note
|
||||
.factory('Note', ["$http", function($http) {
|
||||
var self = this;
|
||||
|
||||
self.notesMap = {}; // noteId => note
|
||||
|
||||
var e = {};
|
||||
|
||||
// 得到Note
|
||||
e.getNote = function(noteId, callback) {
|
||||
if(self.notesMap[noteId]) {
|
||||
if(!self.notesMap[noteId].Content) {
|
||||
$http.get("/note/getNoteContent", {params:{noteId: noteId}}).success(function(ret) {
|
||||
$.extend(self.notesMap[noteId], ret);
|
||||
callback(self.notesMap[noteId]);
|
||||
});
|
||||
}
|
||||
callback(self.notesMap[noteId]);
|
||||
} else {
|
||||
$http.get("/note/getNoteAndContent", {params:{noteId: noteId}}).success(function(ret) {
|
||||
self.notesMap[noteId] = ret;
|
||||
callback(self.notesMap[noteId]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Notebook调用
|
||||
e.setCache = function(notes) {
|
||||
for(var i in notes) {
|
||||
var note = notes[i];
|
||||
self.notesMap[note.NoteId] = note;
|
||||
}
|
||||
}
|
||||
|
||||
return e;
|
||||
}])
|
||||
|
||||
// Notebook
|
||||
.factory('Notebook', ["$http", "Note",function ($http, Note) {
|
||||
var self = this;
|
||||
self.notebooks = [];
|
||||
self.notebooksMap = {};
|
||||
|
||||
self.notes = {}; // notebookId=>[note]
|
||||
self.notesMap = {}; // noteId => note
|
||||
|
||||
var e = {};
|
||||
e.getNotebooks = function(callback) {
|
||||
if(!callback) {
|
||||
callback = function() {};
|
||||
}
|
||||
if(self.notebooks.length > 0) callback(self.notebooks);
|
||||
else {
|
||||
$http.get("/notebook/getNotebooks").success(function(ret) {
|
||||
self.notebooks = ret;
|
||||
for(var i in ret) {
|
||||
var notebook = ret[i];
|
||||
self.notebooksMap[notebook.NotebookId] = notebook;
|
||||
}
|
||||
callback(ret);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
e.getNotebook = function(notebookId, callback) {
|
||||
if(self.notebooksMap[notebookId]) callback(self.notebooksMap[notebookId]);
|
||||
else {
|
||||
e.getNotebooks(function() {
|
||||
callback(self.notebooksMap[notebookId]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
e.getNotes = function(notebookId, callback) {
|
||||
if(self.notes[notebookId]) callback(self.notes[notebookId]);
|
||||
else {
|
||||
$http.get("/note/listNotes", {params:{notebookId: notebookId}}).success(function(ret) {
|
||||
self.notes[notebookId] = ret;
|
||||
callback(ret);
|
||||
// 存到Note中
|
||||
Note.setCache(ret);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return e;
|
||||
}]);
|
Reference in New Issue
Block a user