Blame view
app/scripts/services/favorite.js
2.34 KB
faf1542f8
|
1 2 |
define(['app'], function (app) { 'use strict'; |
53828b4e7
|
3 |
app.factory('$favorite', function ($http, $rootScope, $window) { |
faf1542f8
|
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 |
var DATA = []; return { loadFromRemote: function (params,successHandle,errorHandle) { /*** load from localstorage for test */ if ($window.localStorage.listFavorite){ DATA = JSON.parse($window.localStorage.listFavorite); }else{ DATA = []; } return; /*** end test */ // return format: { status:0|1 , data:{} } var httpObj = $http({ url: $rootScope.API_URL+'/apiv1/favorite', method: 'GET', params: params || [] }); if (typeof successHandle == 'undefined'){ successHandle = function(response){ if (response.status==1){ DATA = response.data; } } } httpObj.success(successHandle); if (typeof errorHandle != 'undefined'){ httpObj.error(errorHandle); } }, addToFavorite: function(params,successHandle,errorHandle) { /*** load from localstorage for test */ DATA.push(params.data); $window.localStorage.listFavorite = JSON.stringify(DATA); return; /*** end test */ var httpObj = $http({ url: $rootScope.API_URL+'/apiv1/favorite', method: 'POST', params: params || [] }); if (typeof successHandle == 'undefined'){ successHandle = function(response){ if (response.status==1){ DATA = response.data; } } } httpObj.success(successHandle); if (typeof errorHandle != 'undefined'){ httpObj.error(errorHandle); } }, getAll: function(){ return DATA; } }; }); }); |