Created
March 6, 2015 02:53
-
-
Save gotoweb/d6d5adb8df836a459041 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // service(factory) | |
| logpresso.factory('serviceMovie', function(socket) { | |
| var isready = false; | |
| var list = []; | |
| function get() { | |
| return new Async(function() { | |
| var self = this; | |
| if(!isready) { | |
| socket.send('...MoviePlugin.getMovies', {}, pid) | |
| .success(function(m) { | |
| list = m.body.movies; | |
| isready = true; | |
| self.done('success', list); | |
| }); | |
| } | |
| else { | |
| setTimeout(function() { | |
| self.done('success', list); | |
| }, 1); | |
| } | |
| }); | |
| } | |
| function add(movie) { | |
| return new Async(function() { | |
| var self = this; | |
| socket.send('...MoviePlugin.addMovie', movie, pid) | |
| .success(function(m) { | |
| movie.id = m.body.id; | |
| list.push(movie); | |
| self.done('success', m.body.id); | |
| }); | |
| }); | |
| } | |
| function findMovieById(id) { | |
| // TODO | |
| } | |
| function remove(id) { | |
| return new Async(function() { | |
| var self = this; | |
| socket.send('...MoviePlugin.removeMovie', id, pid) | |
| .success(function(m) { | |
| var movie = findMovieById(id); | |
| list.splice(list.indexOf(movie), 1); // remove | |
| self.done('success'); | |
| }); | |
| }); | |
| } | |
| return { | |
| get: get, | |
| add: add, | |
| remove: remove | |
| } | |
| }); | |
| // controller | |
| logpresso.controller('MovieListController', function($scope, serviceMovie) { | |
| $scope.listMovie = []; | |
| serviceMovie.get() | |
| .success(function(list) { | |
| $scope.listMovie = list; | |
| $scope.$apply(); | |
| }); | |
| $scope.addMovie = function(obj) { | |
| serviceMovie.add(obj) | |
| .success(function(newId) { | |
| // 목록 refresh | |
| $scope.listMovie = list; | |
| $scope.$apply(); | |
| }); | |
| } | |
| $scope.removeMovie = function(id) { | |
| serviceMovie.remove(id) | |
| .success(function() { | |
| // 목록 refresh | |
| $scope.listMovie = list; | |
| $scope.$apply(); | |
| }); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment