| .. | .. |
|---|
| 60 | 60 | if (!txt || txt.length <= len) return txt; |
|---|
| 61 | 61 | return txt.substring(0, len) + '...'; |
|---|
| 62 | 62 | } |
|---|
| 63 | | - $scope.currentPackId = $store.get('currentPackId'); |
|---|
| 63 | + $scope.currentPack = $store.get('currentPack'); |
|---|
| 64 | 64 | |
|---|
| 65 | 65 | }]); |
|---|
| 66 | 66 | |
|---|
| .. | .. |
|---|
| 153 | 153 | $scope.showForm = false; |
|---|
| 154 | 154 | } |
|---|
| 155 | 155 | |
|---|
| 156 | | - $scope.selectPack = function(packId) { |
|---|
| 157 | | - $scope.$parent.currentPackId = packId; |
|---|
| 158 | | - $store.put('currentPackId', packId); |
|---|
| 156 | + $scope.selectPack = function(pack) { |
|---|
| 157 | + $scope.$parent.currentPack = pack; |
|---|
| 158 | + $store.put('currentPack', pack); |
|---|
| 159 | + $scope.$parent.$broadcast('pack_changed', pack); |
|---|
| 159 | 160 | } |
|---|
| 160 | 161 | |
|---|
| 161 | 162 | } ]); |
|---|
| 162 | 163 | |
|---|
| 164 | + app.controller('LicensesCtrl', [ |
|---|
| 165 | + '$scope', |
|---|
| 166 | + '$http', |
|---|
| 167 | + '$resource', |
|---|
| 168 | + 'toaster', |
|---|
| 169 | + '$store', |
|---|
| 170 | + '$L', |
|---|
| 171 | + function($scope, $http, $resource, toaster, $store, $L) { |
|---|
| 172 | + $scope.$on('pack_changed', function(evt, message) { |
|---|
| 173 | + $scope.licenses = licenseResource.query({packId: $scope.currentPack.id}); |
|---|
| 174 | + console.log('on pack_changed'); |
|---|
| 175 | + if ($scope.showForm) { |
|---|
| 176 | + if ($scope.isNew) { |
|---|
| 177 | + $scope.license.pack_id = $scope.currentPack.id |
|---|
| 178 | + } else { |
|---|
| 179 | + $scope.showForm = false; |
|---|
| 180 | + } |
|---|
| 181 | + } |
|---|
| 182 | + }) |
|---|
| 183 | + |
|---|
| 184 | + var licenseResource = $resource('/license/:licenseId', { |
|---|
| 185 | + licenseId : '@id' |
|---|
| 186 | + }); |
|---|
| 187 | + $scope.mandatory = { |
|---|
| 188 | + code: true |
|---|
| 189 | + } |
|---|
| 190 | + $scope.maxlength = { |
|---|
| 191 | + code: 50, |
|---|
| 192 | + comments: 1024 |
|---|
| 193 | + } |
|---|
| 194 | + $scope.refs = {}; |
|---|
| 195 | + |
|---|
| 196 | + // Used to create the form with the appropriate data |
|---|
| 197 | + $scope.isNew = undefined; |
|---|
| 198 | + |
|---|
| 199 | + // Selected license from listing |
|---|
| 200 | + // license is the edited license, in creation contains the data for the new license |
|---|
| 201 | + $scope.license = null; |
|---|
| 202 | + if ($scope.currentPack) |
|---|
| 203 | + $scope.licenses = licenseResource.query({packId: $scope.currentPack.id}); |
|---|
| 204 | + |
|---|
| 205 | + $scope.save = function() { |
|---|
| 206 | + var _success = function() { |
|---|
| 207 | + if (!$scope.isNew) $scope.showForm = false; |
|---|
| 208 | + $scope.licenses = licenseResource.query({packId: $scope.currentPack.id}); |
|---|
| 209 | + } |
|---|
| 210 | + licenseResource.save($scope.license, _success) |
|---|
| 211 | + } |
|---|
| 212 | + |
|---|
| 213 | + $scope.newLicense = function() { |
|---|
| 214 | + if (!$scope.currentPack) { |
|---|
| 215 | + BootstrapDialog.show({ |
|---|
| 216 | + title: $L.get('New license'), |
|---|
| 217 | + type: BootstrapDialog.TYPE_WARNING, |
|---|
| 218 | + message: $L.get('Please, select a pack before to create a new license'), |
|---|
| 219 | + buttons: [{ |
|---|
| 220 | + label: 'OK', |
|---|
| 221 | + action: function(dialog) { |
|---|
| 222 | + dialog.close(); |
|---|
| 223 | + } |
|---|
| 224 | + }] |
|---|
| 225 | + }); |
|---|
| 226 | + return; |
|---|
| 227 | + } |
|---|
| 228 | + |
|---|
| 229 | + $scope.isNew = true; |
|---|
| 230 | + $scope.showForm = true; |
|---|
| 231 | + $scope.license = { |
|---|
| 232 | + pack_id: $scope.currentPack.id |
|---|
| 233 | + } |
|---|
| 234 | + setTimeout(function() { |
|---|
| 235 | + $('#licenseForm * #code').focus(); |
|---|
| 236 | + }, 0); |
|---|
| 237 | + } |
|---|
| 238 | + |
|---|
| 239 | + $scope.editLicense = function(selectedlicense) { |
|---|
| 240 | + $scope.isNew = false; |
|---|
| 241 | + $scope.showForm = true; |
|---|
| 242 | + $scope.license = selectedlicense; |
|---|
| 243 | + setTimeout(function() { |
|---|
| 244 | + $('#licenseForm * #code').focus(); |
|---|
| 245 | + }, 0); |
|---|
| 246 | + } |
|---|
| 247 | + |
|---|
| 248 | + $scope.deletelicense = function(selectedlicense) { |
|---|
| 249 | + $scope.showForm = false; |
|---|
| 250 | + BootstrapDialog.confirm($L.get("The license '{0}' will be deleted, are you sure?", selectedlicense.code), function(result){ |
|---|
| 251 | + if(result) { |
|---|
| 252 | + var promise = licenseResource.remove({}, {id: selectedlicense.id}).$promise; |
|---|
| 253 | + promise.then(function(data) { |
|---|
| 254 | + $scope.selectlicense(null); |
|---|
| 255 | + $scope.licenses = licenseResource.query({packId: $scope.currentPack.id}); |
|---|
| 256 | + toaster.pop('success', Catalogs.getName(), $L.get("License '{0}' deleted successfully", selectedlicense.code)); |
|---|
| 257 | + },function(error) { |
|---|
| 258 | + console.log(error); |
|---|
| 259 | + toaster.pop('error', Catalogs.getName(), $L.get("Error deleting license, reason: {0}. Details: {1}", $L.get(HTTP_ERRORS[error.status]), error.headers('X-SECURIS-ERROR')), 10000); |
|---|
| 260 | + }); |
|---|
| 261 | + } |
|---|
| 262 | + }); |
|---|
| 263 | + $scope.isNew = false; |
|---|
| 264 | + } |
|---|
| 265 | + |
|---|
| 266 | + |
|---|
| 267 | + $scope.cancel = function() { |
|---|
| 268 | + $scope.showForm = false; |
|---|
| 269 | + } |
|---|
| 270 | + |
|---|
| 271 | + $scope.showStatus = function(lic) { |
|---|
| 272 | + |
|---|
| 273 | + } |
|---|
| 274 | + $scope.showStatusComplete = function(license) { |
|---|
| 275 | + |
|---|
| 276 | + } |
|---|
| 277 | + $scope.isActionVisible = function(actionMask, lic) { |
|---|
| 278 | + |
|---|
| 279 | + } |
|---|
| 280 | + |
|---|
| 281 | + } ]); |
|---|
| 282 | + |
|---|
| 163 | 283 | })(); |
|---|