From 1bf728c96934bf40fb056eeaf1b3c29e0128bdea Mon Sep 17 00:00:00 2001 From: junv Date: Tue, 25 Mar 2014 08:34:54 +0800 Subject: [PATCH] starting add douban books, not finished yet --- platforms/ios/cordova/console.log | 44 +++++++++++++++++++ platforms/ios/www/index.html | 1 + platforms/ios/www/js/app.js | 1 + .../app/controllers/books-controller.coffee | 20 ++++++++- .../js/app/controllers/books-controller.js | 30 ++++++++++++- .../www/js/app/services/douban-service.coffee | 25 +++++++++++ .../ios/www/js/app/services/douban-service.js | 36 +++++++++++++++ .../ios/www/templates/modal/import_books.html | 32 +++++++++++--- www/index.html | 1 + www/js/app.js | 1 + .../app/controllers/books-controller.coffee | 17 ++++++- www/js/app/controllers/books-controller.js | 24 +++++++++- www/js/app/services/douban-service.coffee | 25 +++++++++++ www/js/app/services/douban-service.js | 36 +++++++++++++++ www/templates/modal/import_books.html | 32 +++++++++++--- 15 files changed, 303 insertions(+), 22 deletions(-) create mode 100644 platforms/ios/www/js/app/services/douban-service.coffee create mode 100644 platforms/ios/www/js/app/services/douban-service.js create mode 100644 www/js/app/services/douban-service.coffee create mode 100644 www/js/app/services/douban-service.js diff --git a/platforms/ios/cordova/console.log b/platforms/ios/cordova/console.log index fa24f18..2fdbdb6 100644 --- a/platforms/ios/cordova/console.log +++ b/platforms/ios/cordova/console.log @@ -2,3 +2,47 @@ 2014-03-11 21:30:44.394 Libr[50734:70b] Unlimited access to network resources 2014-03-11 21:30:44.510 Libr[50734:70b] Resetting plugins due to page load. 2014-03-11 21:30:44.730 Libr[50734:70b] Finished load of: file:///Users/twer/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/27050D46-5713-492B-814C-7D0455F35FDC/Libr.app/www/index.html#/login +2014-03-24 16:23:21.454 Libr[2904:70b] Multi-tasking -> Device: YES, App: YES +2014-03-24 16:23:21.487 Libr[2904:70b] Unlimited access to network resources +2014-03-24 16:23:21.927 Libr[2904:70b] Resetting plugins due to page load. +2014-03-24 16:23:22.448 Libr[2904:70b] Finished load of: file:///Users/twer/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/27050D46-5713-492B-814C-7D0455F35FDC/Libr.app/www/index.html#/login +2014-03-24 16:25:49.572 Libr[3102:70b] Multi-tasking -> Device: YES, App: YES +2014-03-24 16:25:49.578 Libr[3102:70b] Unlimited access to network resources +2014-03-24 16:25:49.658 Libr[3102:70b] Resetting plugins due to page load. +2014-03-24 16:25:49.873 Libr[3102:70b] Finished load of: file:///Users/twer/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/27050D46-5713-492B-814C-7D0455F35FDC/Libr.app/www/index.html#/tab/home +2014-03-24 16:26:02.989 Libr[3283:70b] Multi-tasking -> Device: YES, App: YES +2014-03-24 16:26:02.995 Libr[3283:70b] Unlimited access to network resources +2014-03-24 16:26:03.079 Libr[3283:70b] Resetting plugins due to page load. +2014-03-24 16:26:03.307 Libr[3283:70b] Finished load of: file:///Users/twer/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/27050D46-5713-492B-814C-7D0455F35FDC/Libr.app/www/index.html#/tab/home +2014-03-24 16:27:09.085 Libr[3470:70b] Multi-tasking -> Device: YES, App: YES +2014-03-24 16:27:09.091 Libr[3470:70b] Unlimited access to network resources +2014-03-24 16:27:09.135 Libr[3470:70b] Resetting plugins due to page load. +2014-03-24 16:27:09.341 Libr[3470:70b] Finished load of: file:///Users/twer/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/27050D46-5713-492B-814C-7D0455F35FDC/Libr.app/www/index.html#/tab/home +2014-03-24 16:27:21.437 Libr[3651:70b] Multi-tasking -> Device: YES, App: YES +2014-03-24 16:27:21.443 Libr[3651:70b] Unlimited access to network resources +2014-03-24 16:27:21.521 Libr[3651:70b] Resetting plugins due to page load. +2014-03-24 16:27:21.758 Libr[3651:70b] Finished load of: file:///Users/twer/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/27050D46-5713-492B-814C-7D0455F35FDC/Libr.app/www/index.html#/tab/home +2014-03-24 16:28:33.698 Libr[3835:70b] Multi-tasking -> Device: YES, App: YES +2014-03-24 16:28:33.704 Libr[3835:70b] Unlimited access to network resources +2014-03-24 16:28:33.748 Libr[3835:70b] Resetting plugins due to page load. +2014-03-24 16:28:33.954 Libr[3835:70b] Finished load of: file:///Users/twer/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/27050D46-5713-492B-814C-7D0455F35FDC/Libr.app/www/index.html#/tab/home +2014-03-24 16:28:39.632 Libr[4015:70b] Multi-tasking -> Device: YES, App: YES +2014-03-24 16:28:39.638 Libr[4015:70b] Unlimited access to network resources +2014-03-24 16:28:39.722 Libr[4015:70b] Resetting plugins due to page load. +2014-03-24 16:28:39.940 Libr[4015:70b] Finished load of: file:///Users/twer/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/27050D46-5713-492B-814C-7D0455F35FDC/Libr.app/www/index.html#/tab/home +2014-03-24 16:29:18.678 Libr[4197:70b] Multi-tasking -> Device: YES, App: YES +2014-03-24 16:29:18.684 Libr[4197:70b] Unlimited access to network resources +2014-03-24 16:29:18.728 Libr[4197:70b] Resetting plugins due to page load. +2014-03-24 16:29:18.935 Libr[4197:70b] Finished load of: file:///Users/twer/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/27050D46-5713-492B-814C-7D0455F35FDC/Libr.app/www/index.html#/tab/home +2014-03-24 16:29:25.660 Libr[4376:70b] Multi-tasking -> Device: YES, App: YES +2014-03-24 16:29:25.665 Libr[4376:70b] Unlimited access to network resources +2014-03-24 16:29:25.773 Libr[4376:70b] Resetting plugins due to page load. +2014-03-24 16:29:26.059 Libr[4376:70b] Finished load of: file:///Users/twer/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/27050D46-5713-492B-814C-7D0455F35FDC/Libr.app/www/index.html#/tab/home +2014-03-24 16:30:35.034 Libr[4561:70b] Multi-tasking -> Device: YES, App: YES +2014-03-24 16:30:35.039 Libr[4561:70b] Unlimited access to network resources +2014-03-24 16:30:35.085 Libr[4561:70b] Resetting plugins due to page load. +2014-03-24 16:30:35.291 Libr[4561:70b] Finished load of: file:///Users/twer/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/27050D46-5713-492B-814C-7D0455F35FDC/Libr.app/www/index.html#/tab/home +2014-03-24 16:30:39.187 Libr[4741:70b] Multi-tasking -> Device: YES, App: YES +2014-03-24 16:30:39.193 Libr[4741:70b] Unlimited access to network resources +2014-03-24 16:30:39.282 Libr[4741:70b] Resetting plugins due to page load. +2014-03-24 16:30:39.558 Libr[4741:70b] Finished load of: file:///Users/twer/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/27050D46-5713-492B-814C-7D0455F35FDC/Libr.app/www/index.html#/tab/home diff --git a/platforms/ios/www/index.html b/platforms/ios/www/index.html index 5905806..ffadc56 100644 --- a/platforms/ios/www/index.html +++ b/platforms/ios/www/index.html @@ -28,6 +28,7 @@ + diff --git a/platforms/ios/www/js/app.js b/platforms/ios/www/js/app.js index f6c4241..b998311 100644 --- a/platforms/ios/www/js/app.js +++ b/platforms/ios/www/js/app.js @@ -5,6 +5,7 @@ // 'libr.controllers' is found in controllers.js angular.module('libr', ['ionic', 'libr.services', 'libr.controllers', 'libr.services.scan', 'libr.handlers.errorHandler', + 'libr.services.douban', 'libr.services.geolocation', 'libr.services.auth', 'libr.services.books', diff --git a/platforms/ios/www/js/app/controllers/books-controller.coffee b/platforms/ios/www/js/app/controllers/books-controller.coffee index f48a6df..49b1149 100644 --- a/platforms/ios/www/js/app/controllers/books-controller.coffee +++ b/platforms/ios/www/js/app/controllers/books-controller.coffee @@ -2,8 +2,8 @@ libr = angular.module 'libr.controllers.books', ['ionic'] class BooksController - @$inject: ['$scope', 'Books', 'ScanService', '$ionicModal'] - constructor: (@$scope, @Books, ScanService, @$ionicModal) -> + @$inject: ['$scope', 'Books', 'ScanService', '$ionicModal', 'DoubanService'] + constructor: (@$scope, @Books, ScanService, @$ionicModal, @DoubanService) -> currentPage = localStorage.setItem 'user_books_current_page', 0 @$scope.books = [] @$scope.moreItemsAvailable = true @@ -34,6 +34,8 @@ class BooksController ] @$scope.onRefresh = @refresh @$scope.loadMore = @loadMore + @$scope.closeDialog = @closeDialog + @$scope.searchDoubanUser = @searchDoubanUser refresh: ()=> afterBookId = localStorage.getItem 'user_max_book_id' @@ -66,5 +68,19 @@ class BooksController @$scope.$broadcast('scroll.infiniteScrollComplete') @$scope.moreItemsAvailable = false + closeDialog: => + @$scope.modal.hide() + + searchDoubanUser: (user)=> + if user is undefined or user.trim() is '' + alert '请输入有效昵称' + else + @DoubanService.userInfo user, + (data)=> + @$scope.resultEnabled = true + @$scope.doubanUser = data + , (error)=> + console.log error + libr.controller 'BooksController', BooksController \ No newline at end of file diff --git a/platforms/ios/www/js/app/controllers/books-controller.js b/platforms/ios/www/js/app/controllers/books-controller.js index 1765f78..2c6f68d 100644 --- a/platforms/ios/www/js/app/controllers/books-controller.js +++ b/platforms/ios/www/js/app/controllers/books-controller.js @@ -6,13 +6,16 @@ libr = angular.module('libr.controllers.books', ['ionic']); BooksController = (function() { - BooksController.$inject = ['$scope', 'Books', 'ScanService', '$ionicModal']; + BooksController.$inject = ['$scope', 'Books', 'ScanService', '$ionicModal', 'DoubanService']; - function BooksController($scope, Books, ScanService, $ionicModal) { + function BooksController($scope, Books, ScanService, $ionicModal, DoubanService) { var currentPage; this.$scope = $scope; this.Books = Books; this.$ionicModal = $ionicModal; + this.DoubanService = DoubanService; + this.searchDoubanUser = __bind(this.searchDoubanUser, this); + this.closeDialog = __bind(this.closeDialog, this); this.loadMore = __bind(this.loadMore, this); this.refresh = __bind(this.refresh, this); currentPage = localStorage.setItem('user_books_current_page', 0); @@ -51,6 +54,8 @@ ]; this.$scope.onRefresh = this.refresh; this.$scope.loadMore = this.loadMore; + this.$scope.closeDialog = this.closeDialog; + this.$scope.searchDoubanUser = this.searchDoubanUser; } BooksController.prototype.refresh = function() { @@ -101,6 +106,27 @@ } }; + BooksController.prototype.closeDialog = function() { + return this.$scope.modal.hide(); + }; + + BooksController.prototype.searchDoubanUser = function(user) { + if (user === void 0 || user.trim() === '') { + return alert('请输入有效昵称'); + } else { + return this.DoubanService.userInfo(user, (function(_this) { + return function(data) { + _this.$scope.resultEnabled = true; + return _this.$scope.doubanUser = data; + }; + })(this), (function(_this) { + return function(error) { + return console.log(error); + }; + })(this)); + } + }; + return BooksController; })(); diff --git a/platforms/ios/www/js/app/services/douban-service.coffee b/platforms/ios/www/js/app/services/douban-service.coffee new file mode 100644 index 0000000..40c2510 --- /dev/null +++ b/platforms/ios/www/js/app/services/douban-service.coffee @@ -0,0 +1,25 @@ +libr = angular.module 'libr.services.douban', [] + + +class DoubanService + + @$inject: ['$http'] + constructor: (@$http)-> + + + userInfo: (user, callback, error)-> + @$http( + url: "http://api.douban.com/v2/user/#{user}" + method: 'GET' + timeout: 10000 + ) + .success (data, status, headers, config)-> + if status is 200 + callback data + else + error data + .error (data)-> + error data + +libr.service 'DoubanService', DoubanService + diff --git a/platforms/ios/www/js/app/services/douban-service.js b/platforms/ios/www/js/app/services/douban-service.js new file mode 100644 index 0000000..c9d4e37 --- /dev/null +++ b/platforms/ios/www/js/app/services/douban-service.js @@ -0,0 +1,36 @@ +// Generated by CoffeeScript 1.7.1 +(function() { + var DoubanService, libr; + + libr = angular.module('libr.services.douban', []); + + DoubanService = (function() { + DoubanService.$inject = ['$http']; + + function DoubanService($http) { + this.$http = $http; + } + + DoubanService.prototype.userInfo = function(user, callback, error) { + return this.$http({ + url: "http://api.douban.com/v2/user/" + user, + method: 'GET', + timeout: 10000 + }).success(function(data, status, headers, config) { + if (status === 200) { + return callback(data); + } else { + return error(data); + } + }).error(function(data) { + return error(data); + }); + }; + + return DoubanService; + + })(); + + libr.service('DoubanService', DoubanService); + +}).call(this); diff --git a/platforms/ios/www/templates/modal/import_books.html b/platforms/ios/www/templates/modal/import_books.html index f04ca73..cfc7dcc 100644 --- a/platforms/ios/www/templates/modal/import_books.html +++ b/platforms/ios/www/templates/modal/import_books.html @@ -3,14 +3,32 @@

从豆瓣读书导入书籍

+ - - +
+ + + +

注意:绑定后不能更改用户名,请填入正确的用户名

+
+
+

我们找到以下用户:

+ +

昵称:{{doubanUser.name}}

+ +

描述:{{doubanUser.desc}}

+ + + +

注意:如果正确请点击提交按钮

+
\ No newline at end of file diff --git a/www/index.html b/www/index.html index 5905806..ffadc56 100644 --- a/www/index.html +++ b/www/index.html @@ -28,6 +28,7 @@ + diff --git a/www/js/app.js b/www/js/app.js index f6c4241..b998311 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -5,6 +5,7 @@ // 'libr.controllers' is found in controllers.js angular.module('libr', ['ionic', 'libr.services', 'libr.controllers', 'libr.services.scan', 'libr.handlers.errorHandler', + 'libr.services.douban', 'libr.services.geolocation', 'libr.services.auth', 'libr.services.books', diff --git a/www/js/app/controllers/books-controller.coffee b/www/js/app/controllers/books-controller.coffee index 235c6f0..49b1149 100644 --- a/www/js/app/controllers/books-controller.coffee +++ b/www/js/app/controllers/books-controller.coffee @@ -2,8 +2,8 @@ libr = angular.module 'libr.controllers.books', ['ionic'] class BooksController - @$inject: ['$scope', 'Books', 'ScanService', '$ionicModal'] - constructor: (@$scope, @Books, ScanService, @$ionicModal) -> + @$inject: ['$scope', 'Books', 'ScanService', '$ionicModal', 'DoubanService'] + constructor: (@$scope, @Books, ScanService, @$ionicModal, @DoubanService) -> currentPage = localStorage.setItem 'user_books_current_page', 0 @$scope.books = [] @$scope.moreItemsAvailable = true @@ -35,6 +35,7 @@ class BooksController @$scope.onRefresh = @refresh @$scope.loadMore = @loadMore @$scope.closeDialog = @closeDialog + @$scope.searchDoubanUser = @searchDoubanUser refresh: ()=> afterBookId = localStorage.getItem 'user_max_book_id' @@ -70,4 +71,16 @@ class BooksController closeDialog: => @$scope.modal.hide() + searchDoubanUser: (user)=> + if user is undefined or user.trim() is '' + alert '请输入有效昵称' + else + @DoubanService.userInfo user, + (data)=> + @$scope.resultEnabled = true + @$scope.doubanUser = data + , (error)=> + console.log error + + libr.controller 'BooksController', BooksController \ No newline at end of file diff --git a/www/js/app/controllers/books-controller.js b/www/js/app/controllers/books-controller.js index ea834f6..2c6f68d 100644 --- a/www/js/app/controllers/books-controller.js +++ b/www/js/app/controllers/books-controller.js @@ -6,13 +6,15 @@ libr = angular.module('libr.controllers.books', ['ionic']); BooksController = (function() { - BooksController.$inject = ['$scope', 'Books', 'ScanService', '$ionicModal']; + BooksController.$inject = ['$scope', 'Books', 'ScanService', '$ionicModal', 'DoubanService']; - function BooksController($scope, Books, ScanService, $ionicModal) { + function BooksController($scope, Books, ScanService, $ionicModal, DoubanService) { var currentPage; this.$scope = $scope; this.Books = Books; this.$ionicModal = $ionicModal; + this.DoubanService = DoubanService; + this.searchDoubanUser = __bind(this.searchDoubanUser, this); this.closeDialog = __bind(this.closeDialog, this); this.loadMore = __bind(this.loadMore, this); this.refresh = __bind(this.refresh, this); @@ -53,6 +55,7 @@ this.$scope.onRefresh = this.refresh; this.$scope.loadMore = this.loadMore; this.$scope.closeDialog = this.closeDialog; + this.$scope.searchDoubanUser = this.searchDoubanUser; } BooksController.prototype.refresh = function() { @@ -107,6 +110,23 @@ return this.$scope.modal.hide(); }; + BooksController.prototype.searchDoubanUser = function(user) { + if (user === void 0 || user.trim() === '') { + return alert('请输入有效昵称'); + } else { + return this.DoubanService.userInfo(user, (function(_this) { + return function(data) { + _this.$scope.resultEnabled = true; + return _this.$scope.doubanUser = data; + }; + })(this), (function(_this) { + return function(error) { + return console.log(error); + }; + })(this)); + } + }; + return BooksController; })(); diff --git a/www/js/app/services/douban-service.coffee b/www/js/app/services/douban-service.coffee new file mode 100644 index 0000000..40c2510 --- /dev/null +++ b/www/js/app/services/douban-service.coffee @@ -0,0 +1,25 @@ +libr = angular.module 'libr.services.douban', [] + + +class DoubanService + + @$inject: ['$http'] + constructor: (@$http)-> + + + userInfo: (user, callback, error)-> + @$http( + url: "http://api.douban.com/v2/user/#{user}" + method: 'GET' + timeout: 10000 + ) + .success (data, status, headers, config)-> + if status is 200 + callback data + else + error data + .error (data)-> + error data + +libr.service 'DoubanService', DoubanService + diff --git a/www/js/app/services/douban-service.js b/www/js/app/services/douban-service.js new file mode 100644 index 0000000..c9d4e37 --- /dev/null +++ b/www/js/app/services/douban-service.js @@ -0,0 +1,36 @@ +// Generated by CoffeeScript 1.7.1 +(function() { + var DoubanService, libr; + + libr = angular.module('libr.services.douban', []); + + DoubanService = (function() { + DoubanService.$inject = ['$http']; + + function DoubanService($http) { + this.$http = $http; + } + + DoubanService.prototype.userInfo = function(user, callback, error) { + return this.$http({ + url: "http://api.douban.com/v2/user/" + user, + method: 'GET', + timeout: 10000 + }).success(function(data, status, headers, config) { + if (status === 200) { + return callback(data); + } else { + return error(data); + } + }).error(function(data) { + return error(data); + }); + }; + + return DoubanService; + + })(); + + libr.service('DoubanService', DoubanService); + +}).call(this); diff --git a/www/templates/modal/import_books.html b/www/templates/modal/import_books.html index f04ca73..cfc7dcc 100644 --- a/www/templates/modal/import_books.html +++ b/www/templates/modal/import_books.html @@ -3,14 +3,32 @@

从豆瓣读书导入书籍

+ - - +
+ + + +

注意:绑定后不能更改用户名,请填入正确的用户名

+
+
+

我们找到以下用户:

+ +

昵称:{{doubanUser.name}}

+ +

描述:{{doubanUser.desc}}

+ + + +

注意:如果正确请点击提交按钮

+
\ No newline at end of file