1/** 2 * @fileoverview Likes Javascript 3 * @author [email protected] (Shohei Nakajima) 4 */ 5 6 7/** 8 * Likes Service Javascript 9 * 10 * @param {string} Controller name 11 * @param {function('$http', '$q')} Controller 12 */ 13NetCommonsApp.factory('LikesSave', ['$http', '$q', 'NC3_URL', function($http, $q, NC3_URL) { 14 return function(post) { 15 16 var deferred = $q.defer(); 17 var promise = deferred.promise; 18 19 $http.get(NC3_URL + '/net_commons/net_commons/csrfToken.json') 20 .then(function(response) { 21 var token = response.data; 22 post._Token.key = token.data._Token.key; 23 24 //POSTãªã¯ã¨ã¹ã 25 $http.post( 26 NC3_URL + '/likes/likes/like.json', 27 $.param({_method: 'POST', data: post}), 28 {cache: false, 29 headers: 30 {'Content-Type': 'application/x-www-form-urlencoded'} 31 } 32 ).then( 33 function(response) { 34 //success condition 35 var data = response.data; 36 deferred.resolve(data); 37 }, 38 function(response) { 39 //error condition 40 var data = response.data; 41 var status = response.status; 42 deferred.reject(data, status); 43 }); 44 }, 45 function(response) { 46 //Token error condition 47 var data = response.data; 48 var status = response.status; 49 deferred.reject(data, status); 50 }); 51 52 promise.success = function(fn) { 53 promise.then(fn); 54 return promise; 55 }; 56 57 promise.error = function(fn) { 58 promise.then(null, fn); 59 return promise; 60 }; 61 62 return promise; 63 }; 64}]); 65 66 67/** 68 * Likes Controller Javascript 69 * 70 * @param {string} Controller name 71 * @param {function($scope, LikesSave)} Controller 72 */ 73NetCommonsApp.controller('Likes', ['$scope', 'LikesSave', function($scope, LikesSave) { 74 75 /** 76 * Request parameters 77 * 78 * @type {object} 79 */ 80 $scope.data = null; 81 82 /** 83 * Options parameters 84 * - disabled 85 * - likeCounts 86 * - unlikeCounts 87 * 88 * @type {object} 89 */ 90 $scope.options = null; 91 92 /** 93 * initialize 94 * - disabled 95 * - likeCounts 96 * - unlikeCounts 97 * 98 * @return {void} 99 */ 100 $scope.initialize = function(data, options) { 101 $scope.data = data; 102 $scope.options = options; 103 $scope.options.disabled = false; 104 }; 105 106 /** 107 * save 108 * 109 * @return {void} 110 */ 111 $scope.save = function(isLiked) { 112 $scope.data['LikesUser']['is_liked'] = isLiked; 113 if ($scope.options.disabled) { 114 return; 115 } 116 $scope.options.disabled = true; 117 $scope.sending = true; 118 119 LikesSave($scope.data) 120 .success(function(data) { 121 $scope.sending = false; 122 //success condition 123 if (isLiked) { 124 $scope.options['likeCount'] = $scope.options['likeCount'] + 1; 125 } else { 126 $scope.options['unlikeCount'] = $scope.options['unlikeCount'] + 1; 127 } 128 }) 129 .error(function(data, status) { 130 //error condition 131 $scope.sending = false; 132 }); 133 }; 134}]); 135 136 137/** 138 * LikeSettings Controller Javascript 139 * 140 * @param {string} Controller name 141 * @param {function($scope)} Controller 142 */ 143NetCommonsApp.controller('LikeSettings', ['$scope', function($scope) { 144 145 /** 146 * initialize 147 * - useLikeDomId 148 * - useUnlikeDomId 149 * 150 * @return {void} 151 */ 152 $scope.initialize = function(useLikeDomId, useUnlikeDomId) { 153 $scope.useLikeDomId = useLikeDomId; 154 $scope.useUnlikeDomId = useUnlikeDomId; 155 }; 156 157 /** 158 * Use like button 159 * 160 * @return {void} 161 */ 162 $scope.useLike = function() { 163 var likeElement = $('#' + $scope.useLikeDomId); 164 var unlikeElement = $('#' + $scope.useUnlikeDomId); 165 166 if (likeElement[0].checked) { 167 unlikeElement[0].disabled = false; 168 } else { 169 unlikeElement[0].disabled = true; 170 unlikeElement[0].checked = false; 171 } 172 }; 173}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.