| .. | .. |
|---|
| 28 | 28 | 'CA': $L.get('Cancelled') |
|---|
| 29 | 29 | }; |
|---|
| 30 | 30 | /** |
|---|
| 31 | | - * These transitions could be get from server, class Pack.Status, but we copy them for simplicity, this info won't change easily |
|---|
| 31 | + * These transitions could be get from server, class Pack.Status, but we |
|---|
| 32 | + * copy them for simplicity, this info won't change easily |
|---|
| 32 | 33 | */ |
|---|
| 33 | 34 | var PACK_ACTIONS_BY_STATUS = { |
|---|
| 34 | 35 | activate: [PACK_STATUS.CREATED, PACK_STATUS.EXPIRED, PACK_STATUS.ONHOLD], |
|---|
| .. | .. |
|---|
| 57 | 58 | } |
|---|
| 58 | 59 | } |
|---|
| 59 | 60 | ); |
|---|
| 61 | + this.getStatusColor = function(status) { |
|---|
| 62 | + var COLORS_BY_STATUS = { |
|---|
| 63 | + 'CR': '#808080', |
|---|
| 64 | + 'AC': '#329e5a', |
|---|
| 65 | + 'OH': '#9047c7', |
|---|
| 66 | + 'EX': '#ea7824', |
|---|
| 67 | + 'CA': '#a21717' |
|---|
| 68 | + }; |
|---|
| 69 | + |
|---|
| 70 | + return COLORS_BY_STATUS[status]; |
|---|
| 71 | + }, |
|---|
| 72 | + this.getStatusName = function(status) { |
|---|
| 73 | + return PACK_STATUSES[status]; |
|---|
| 74 | + } |
|---|
| 75 | + |
|---|
| 60 | 76 | this.savePackData = function(pack, isNew, _onsuccess) { |
|---|
| 61 | 77 | var _success = function() { |
|---|
| 62 | 78 | _onsuccess(); |
|---|
| .. | .. |
|---|
| 64 | 80 | } |
|---|
| 65 | 81 | var _error = function(error) { |
|---|
| 66 | 82 | console.log(error); |
|---|
| 67 | | - toaster.pop('error', 'Packs', $L.get("Error {0} pack '{1}'. Reason: {2}", isNew ? $L.get("creating") : $L.get("updating"), pack.code, $L.get(error.headers('X-SECURIS-ERROR')))); |
|---|
| 83 | + toaster.pop('error', 'Packs', $L.get("Error {0} pack '{1}'. Reason: {2}", isNew ? $L.get("creating") : $L.get("updating"), pack.code, $L.get(error.headers('X-SECURIS-ERROR-MSG')))); |
|---|
| 68 | 84 | } |
|---|
| 69 | 85 | packResource.save(pack, _success, _error); |
|---|
| 70 | 86 | } |
|---|
| .. | .. |
|---|
| 73 | 89 | var validStatuses = PACK_ACTIONS_BY_STATUS[action]; |
|---|
| 74 | 90 | return pack && validStatuses && validStatuses.indexOf(pack.status) !== -1; |
|---|
| 75 | 91 | } |
|---|
| 76 | | - this.getStatusName = function(status) { |
|---|
| 77 | | - return PACK_STATUSES[status]; |
|---|
| 78 | | - } |
|---|
| 79 | | - |
|---|
| 80 | 92 | var _createSuccessCallback = function(actionName, message, _innerCallback) { |
|---|
| 81 | 93 | return function() { |
|---|
| 82 | 94 | _innerCallback && _innerCallback(); |
|---|
| .. | .. |
|---|
| 87 | 99 | return function(error) { |
|---|
| 88 | 100 | console.log(error); |
|---|
| 89 | 101 | _innerCallback && _innerCallback(); |
|---|
| 90 | | - toaster.pop('error', actionName, $L.get("Error on action '{0}', pack '{1}'. Reason: {2}", actionName, pack.code, $L.get(error.headers('X-SECURIS-ERROR')))); |
|---|
| 102 | + toaster.pop('error', actionName, $L.get("Error on action '{0}', pack '{1}'. Reason: {2}", actionName, pack.code, $L.get(error.headers('X-SECURIS-ERROR-MSG')))); |
|---|
| 91 | 103 | } |
|---|
| 92 | 104 | } |
|---|
| 93 | | - this.getPacksList = function(pack, _onsuccess, _onerror) { |
|---|
| 105 | + this.getPacksList = function(_onsuccess, _onerror) { |
|---|
| 94 | 106 | return packResource.query(_onsuccess, _onerror); |
|---|
| 95 | 107 | } |
|---|
| 96 | 108 | this.activate = function(pack, _onsuccess, _onerror) { |
|---|
| .. | .. |
|---|
| 141 | 153 | }; |
|---|
| 142 | 154 | |
|---|
| 143 | 155 | /** |
|---|
| 144 | | - * These transitions could be get from server, class License.Status, but we copy them for simplicity, this info won't change easily |
|---|
| 156 | + * These transitions could be get from server, class License.Status, but |
|---|
| 157 | + * we copy them for simplicity, this info won't change easily |
|---|
| 145 | 158 | */ |
|---|
| 146 | 159 | var LIC_ACTIONS_BY_STATUS = { |
|---|
| 147 | 160 | activate: [LIC_STATUS.CREATED, LIC_STATUS.REQUESTED, LIC_STATUS.PREACTIVE], |
|---|
| 148 | 161 | send: [LIC_STATUS.ACTIVE, LIC_STATUS.PREACTIVE], |
|---|
| 149 | 162 | download: [LIC_STATUS.ACTIVE, LIC_STATUS.PREACTIVE], |
|---|
| 163 | + block: [LIC_STATUS.CANCELLED], |
|---|
| 164 | + unblock: [LIC_STATUS.CANCELLED], |
|---|
| 150 | 165 | cancel: [LIC_STATUS.REQUESTED, LIC_STATUS.EXPIRED, LIC_STATUS.PREACTIVE, LIC_STATUS.ACTIVE], |
|---|
| 151 | 166 | 'delete': [LIC_STATUS.CREATED, LIC_STATUS.CANCELLED] |
|---|
| 152 | 167 | } |
|---|
| 168 | + |
|---|
| 169 | + var licenseResource = $resource('/license/:licenseId/:action', { |
|---|
| 170 | + licenseId : '@id', |
|---|
| 171 | + action : '@action' |
|---|
| 172 | + }, |
|---|
| 173 | + { |
|---|
| 174 | + activate: { |
|---|
| 175 | + method: "POST", |
|---|
| 176 | + params: {action: "activate"} |
|---|
| 177 | + }, |
|---|
| 178 | + cancel: { |
|---|
| 179 | + method: "POST", |
|---|
| 180 | + params: {action: "cancel"} |
|---|
| 181 | + }, |
|---|
| 182 | + download: { |
|---|
| 183 | + method: "GET", |
|---|
| 184 | + params: {action: "download"} |
|---|
| 185 | + }, |
|---|
| 186 | + block: { |
|---|
| 187 | + method: "POST", |
|---|
| 188 | + params: {action: "block"} |
|---|
| 189 | + }, |
|---|
| 190 | + send: { |
|---|
| 191 | + method: "POST", |
|---|
| 192 | + params: {action: "send"} |
|---|
| 193 | + }, |
|---|
| 194 | + unblock: { |
|---|
| 195 | + method: "POST", |
|---|
| 196 | + params: {action: "unblock"} |
|---|
| 197 | + } |
|---|
| 198 | + }); |
|---|
| 199 | + |
|---|
| 153 | 200 | |
|---|
| 154 | 201 | this.isActionAvailable = function(action, lic) { |
|---|
| 155 | 202 | var validStatuses = LIC_ACTIONS_BY_STATUS[action]; |
|---|
| 156 | 203 | return lic && validStatuses && validStatuses.indexOf(lic.status) !== -1; |
|---|
| 157 | 204 | } |
|---|
| 158 | | - |
|---|
| 205 | + this.getStatusColor = function(status) { |
|---|
| 206 | + var COLORS_BY_STATUS = { |
|---|
| 207 | + 'CR': '#808080', |
|---|
| 208 | + 'AC': '#329e5a', |
|---|
| 209 | + 'RE': '#2981d4', |
|---|
| 210 | + 'EX': '#ea7824', |
|---|
| 211 | + 'CA': '#a21717' |
|---|
| 212 | + }; |
|---|
| 213 | + |
|---|
| 214 | + return COLORS_BY_STATUS[status]; |
|---|
| 215 | + }, |
|---|
| 159 | 216 | this.getStatusName = function(status) { |
|---|
| 160 | 217 | return LIC_STATUSES[status]; |
|---|
| 161 | 218 | } |
|---|
| 219 | + |
|---|
| 220 | + this.saveLicenseData = function(license, isNew, _onsuccess) { |
|---|
| 221 | + var _success = function() { |
|---|
| 222 | + _onsuccess(); |
|---|
| 223 | + toaster.pop('success', 'Licenses', $L.get("License '{0}' {1} successfully", license.code, isNew ? $L.get("created") : $L.get("updated"))); |
|---|
| 224 | + } |
|---|
| 225 | + var _error = function(error) { |
|---|
| 226 | + console.log(error); |
|---|
| 227 | + toaster.pop('error', 'Licenses', $L.get("Error {0} license '{1}'. Reason: {2}", isNew ? $L.get("creating") : $L.get("updating"), license.code, $L.get(error.headers('X-SECURIS-ERROR-MSG')))); |
|---|
| 228 | + } |
|---|
| 229 | + licenseResource.save(license, _success, _error); |
|---|
| 230 | + } |
|---|
| 162 | 231 | |
|---|
| 163 | 232 | var _createSuccessCallback = function(actionName, message, _innerCallback) { |
|---|
| 164 | 233 | return function() { |
|---|
| .. | .. |
|---|
| 166 | 235 | toaster.pop('success', actionName, message); |
|---|
| 167 | 236 | } |
|---|
| 168 | 237 | } |
|---|
| 169 | | - var _createErrorCallback = function(pack, actionName, _innerCallback) { |
|---|
| 238 | + var _createErrorCallback = function(license, actionName, _innerCallback) { |
|---|
| 170 | 239 | return function(error) { |
|---|
| 171 | 240 | console.log(error); |
|---|
| 172 | 241 | _innerCallback && _innerCallback(); |
|---|
| 173 | | - toaster.pop('error', actionName, $L.get("Error on action '{0}', pack '{1}'. Reason: {2}", actionName, pack.code, $L.get(error.headers('X-SECURIS-ERROR')))); |
|---|
| 242 | + toaster.pop('error', actionName, $L.get("Error on action '{0}', license '{1}'. Reason: {2}", actionName, license.code, $L.get(error.headers('X-SECURIS-ERROR-MSG')))); |
|---|
| 174 | 243 | } |
|---|
| 175 | 244 | } |
|---|
| 176 | | - this.getPacksList = function(pack, _onsuccess, _onerror) { |
|---|
| 177 | | - return packResource.query(_onsuccess, _onerror); |
|---|
| 245 | + |
|---|
| 246 | + this.getLicensesList = function(pack, _onsuccess, _onerror) { |
|---|
| 247 | + return licenseResource.query({packId: pack.id}, _onsuccess, _onerror); |
|---|
| 178 | 248 | } |
|---|
| 179 | 249 | this.activate = function(license, _onsuccess, _onerror) { |
|---|
| 180 | 250 | console.log('Activation on license: ' + license.id); |
|---|
| .. | .. |
|---|
| 218 | 288 | console.log('scope.license: ' + scope.$parent.license); |
|---|
| 219 | 289 | var setter = $parse(attrs.fileLoader).assign; |
|---|
| 220 | 290 | element.bind('change', function(evt) { |
|---|
| 221 | | - if (!window.FileReader) { // Browser is not compatible |
|---|
| 291 | + if (!window.FileReader) { // Browser is not |
|---|
| 292 | + // compatible |
|---|
| 222 | 293 | BootstrapDialog.alert($L.get("Open your .req file with a text editor and copy&paste the content in the form text field?")); |
|---|
| 223 | 294 | return; |
|---|
| 224 | 295 | } |
|---|
| 225 | 296 | console.log('File selected'); |
|---|
| 226 | | - //console.log('scope.license: ' + scope.$parent.license); |
|---|
| 297 | + // console.log('scope.license: ' + |
|---|
| 298 | + // scope.$parent.license); |
|---|
| 227 | 299 | var field = $parse(attrs.fileLoader); |
|---|
| 228 | | - //console.log('field: ' + field); |
|---|
| 300 | + // console.log('field: ' + field); |
|---|
| 229 | 301 | var fileList = evt.target.files; |
|---|
| 230 | 302 | if (fileList != null && fileList[0]) { |
|---|
| 231 | 303 | var reader = new FileReader(); |
|---|
| .. | .. |
|---|
| 314 | 386 | $scope.isNew = undefined; |
|---|
| 315 | 387 | |
|---|
| 316 | 388 | // Selected pack from listing |
|---|
| 317 | | - // pack is the edited pack, in creation contains the data for the new pack |
|---|
| 389 | + // pack is the edited pack, in creation contains the data for |
|---|
| 390 | + // the new pack |
|---|
| 318 | 391 | $scope.pack = null; |
|---|
| 319 | 392 | |
|---|
| 320 | 393 | $scope.packs = Packs.getPacksList(); |
|---|
| .. | .. |
|---|
| 331 | 404 | } |
|---|
| 332 | 405 | |
|---|
| 333 | 406 | /** |
|---|
| 334 | | - * Execute an action over the pack, activation, onhold, cancellation |
|---|
| 407 | + * Execute an action over the pack, activation, onhold, |
|---|
| 408 | + * cancellation |
|---|
| 335 | 409 | */ |
|---|
| 336 | 410 | $scope.execute = function(action, pack) { |
|---|
| 337 | 411 | var _execute = function(extra_data) { |
|---|
| .. | .. |
|---|
| 348 | 422 | } |
|---|
| 349 | 423 | } |
|---|
| 350 | 424 | if (action === 'delete') { |
|---|
| 351 | | - BootstrapDialog.confirm($L.get("The pack '{0}' will be deleted, are you sure ?", $scope.pack.code), function(answer) { |
|---|
| 425 | + BootstrapDialog.confirm($L.get("The pack '{0}' will be deleted, are you sure ?", pack.code), function(answer) { |
|---|
| 352 | 426 | if (answer) { |
|---|
| 353 | 427 | _execute(); |
|---|
| 354 | 428 | } |
|---|
| .. | .. |
|---|
| 361 | 435 | message: function(dialog) { |
|---|
| 362 | 436 | var $content = $('<div></div>'); |
|---|
| 363 | 437 | var $message = $('<div></div>'); |
|---|
| 364 | | - var pageToLoad = dialog.getData('pageToLoad'); |
|---|
| 365 | | - $message.append($('<label/>').text($L.get("The pack '{0}' and all its licenses will be cancelled, this action cannot be undone", $scope.pack.code))); |
|---|
| 438 | + $message.append($('<label/>').text($L.get("The pack '{0}' and all its licenses will be cancelled, this action cannot be undone", pack.code))); |
|---|
| 366 | 439 | $content.append($message); |
|---|
| 367 | 440 | |
|---|
| 368 | 441 | var $message = $('<div style="margin-top:10pt;"/>'); |
|---|
| 369 | 442 | var pageToLoad = dialog.getData('pageToLoad'); |
|---|
| 370 | 443 | $message.append($('<label style="margin-right:5pt;"/>').text($L.get("Cancellation reason:") + " ")); |
|---|
| 371 | | - $message.append($('<input type="text" style="width:100%;" maxlength="512" id="_cancellation_reason"/>')); |
|---|
| 444 | + $message.append($('<input type="text" style="width:100%;" maxlength="512" id="_pack_cancellation_reason"/>')); |
|---|
| 372 | 445 | $content.append($message); |
|---|
| 373 | 446 | return $content; |
|---|
| 374 | 447 | }, |
|---|
| .. | .. |
|---|
| 385 | 458 | label: $L.get('Cancel pack'), |
|---|
| 386 | 459 | cssClass: 'btn-primary', |
|---|
| 387 | 460 | action: function(dialogRef){ |
|---|
| 388 | | - var reason = $('#_cancellation_reason').val(); |
|---|
| 461 | + var reason = $('#_pack_cancellation_reason').val(); |
|---|
| 389 | 462 | console.log('Ready to cancel pack, by reason: ' + reason); |
|---|
| 390 | 463 | if (!reason) { |
|---|
| 391 | | - $('#_cancellation_reason').focus(); |
|---|
| 464 | + $('#_pack_cancellation_reason').focus(); |
|---|
| 392 | 465 | } else { |
|---|
| 393 | 466 | _execute({reason: reason}); |
|---|
| 394 | 467 | dialogRef.close(); |
|---|
| .. | .. |
|---|
| 413 | 486 | init_valid_date: new Date(), |
|---|
| 414 | 487 | default_valid_period: 30, |
|---|
| 415 | 488 | license_type_id: null, |
|---|
| 416 | | - organization_id: null //!$scope.refs.organization_id || !$scope.refs.organization_id.length ? null : $scope.refs.organization_id[0].id |
|---|
| 489 | + organization_id: null // !$scope.refs.organization_id |
|---|
| 490 | + // || |
|---|
| 491 | + // !$scope.refs.organization_id.length |
|---|
| 492 | + // ? null : |
|---|
| 493 | + // $scope.refs.organization_id[0].id |
|---|
| 417 | 494 | } |
|---|
| 418 | 495 | setTimeout(function() { |
|---|
| 419 | 496 | $('#code').focus(); |
|---|
| .. | .. |
|---|
| 432 | 509 | |
|---|
| 433 | 510 | $scope.pack = selectedPack; |
|---|
| 434 | 511 | |
|---|
| 435 | | - //$scope.pack.organization_name = $scope.getLabelFromId('organization_id', $scope.pack.organization_id); |
|---|
| 512 | + // $scope.pack.organization_name = |
|---|
| 513 | + // $scope.getLabelFromId('organization_id', |
|---|
| 514 | + // $scope.pack.organization_id); |
|---|
| 436 | 515 | $scope.pack.license_type_name = $scope.getLabelFromId('license_type_id', $scope.pack.license_type_id); |
|---|
| 437 | 516 | $scope.pack.status_name = Packs.getStatusName($scope.pack.status); |
|---|
| 438 | 517 | |
|---|
| .. | .. |
|---|
| 452 | 531 | toaster.pop('success', Catalogs.getName(), $L.get("Pack '{0}' deleted successfully", selectedPack.code)); |
|---|
| 453 | 532 | },function(error) { |
|---|
| 454 | 533 | console.log(error); |
|---|
| 455 | | - toaster.pop('error', Catalogs.getName(), $L.get("Error deleting pack, reason: {0}. Details: {1}", $L.get(HTTP_ERRORS[error.status]), error.headers('X-SECURIS-ERROR')), 10000); |
|---|
| 534 | + toaster.pop('error', Catalogs.getName(), $L.get("Error deleting pack, reason: {0}. Details: {1}", $L.get(HTTP_ERRORS[error.status]), error.headers('X-SECURIS-ERROR-MSG')), 10000); |
|---|
| 456 | 535 | }); |
|---|
| 457 | 536 | } |
|---|
| 458 | 537 | }); |
|---|
| .. | .. |
|---|
| 493 | 572 | // Called when Application ID change in current field |
|---|
| 494 | 573 | var newLTId = $scope.pack['license_type_id']; |
|---|
| 495 | 574 | if (newLTId) { |
|---|
| 496 | | - // Only if there is a "valid" value selected we should update the metadata |
|---|
| 575 | + // Only if there is a "valid" value selected we should |
|---|
| 576 | + // update the metadata |
|---|
| 497 | 577 | Catalogs.getResource('licensetype').get({licenseTypeId: newLTId}).$promise.then(function(lt) { |
|---|
| 498 | 578 | $scope.pack.metadata = []; |
|---|
| 499 | 579 | lt.metadata.forEach(function(md) { |
|---|
| .. | .. |
|---|
| 520 | 600 | function($scope, $http, $resource, toaster, Licenses, $store, $L) { |
|---|
| 521 | 601 | $scope.Licenses = Licenses; |
|---|
| 522 | 602 | $scope.$on('pack_changed', function(evt, message) { |
|---|
| 523 | | - $scope.licenses = licenseResource.query({packId: $scope.currentPack.id}); |
|---|
| 603 | + $scope.licenses = Licenses.getLicensesList($scope.currentPack); |
|---|
| 524 | 604 | $scope.creationAvailable = $scope.currentPack.status == 'AC'; |
|---|
| 525 | 605 | if ($scope.showForm) { |
|---|
| 526 | 606 | if ($scope.isNew) { |
|---|
| .. | .. |
|---|
| 531 | 611 | } |
|---|
| 532 | 612 | }) |
|---|
| 533 | 613 | |
|---|
| 534 | | - var licenseResource = $resource('/license/:licenseId', { |
|---|
| 535 | | - licenseId : '@id' |
|---|
| 536 | | - }, { |
|---|
| 537 | | - save_w_upload: { |
|---|
| 538 | | - method: "POST", |
|---|
| 539 | | - transformRequest: function(data, headersGetter) { |
|---|
| 540 | | - // To use an object without FormData, follow: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest?redirectlocale=en-US&redirectslug=DOM%2FXMLHttpRequest%2FUsing_XMLHttpRequest#Submitting_forms_and_uploading_files |
|---|
| 541 | | - var formData = new FormData(); |
|---|
| 542 | | - angular.forEach(data, function(value, key) { |
|---|
| 543 | | - if (key !== 'request_data') |
|---|
| 544 | | - formData.append(key, value) |
|---|
| 545 | | - else |
|---|
| 546 | | - formData.append(key, $('input#request_data_file').get(0).files[0]); |
|---|
| 547 | | - }) |
|---|
| 548 | | - |
|---|
| 549 | | - return formData; |
|---|
| 550 | | - }, |
|---|
| 551 | | - headers: { |
|---|
| 552 | | - 'Content-Type': undefined |
|---|
| 553 | | - } |
|---|
| 554 | | - } |
|---|
| 555 | | - }); |
|---|
| 556 | 614 | $scope.mandatory = { |
|---|
| 557 | 615 | code: true, |
|---|
| 558 | 616 | email: true |
|---|
| .. | .. |
|---|
| 564 | 622 | } |
|---|
| 565 | 623 | $scope.refs = {}; |
|---|
| 566 | 624 | |
|---|
| 567 | | - // Used to create the form with the appropriate data |
|---|
| 625 | + // Used to create the form with the |
|---|
| 626 | + // appropriate data |
|---|
| 568 | 627 | $scope.isNew = undefined; |
|---|
| 569 | 628 | |
|---|
| 570 | 629 | // Selected license from listing |
|---|
| 571 | | - // license is the edited license, in creation contains the data for the new license |
|---|
| 630 | + // license is the edited license, in |
|---|
| 631 | + // creation contains the data for |
|---|
| 632 | + // the new license |
|---|
| 572 | 633 | $scope.license = null; |
|---|
| 573 | | - if ($scope.currentPack) |
|---|
| 574 | | - $scope.licenses = licenseResource.query({packId: $scope.currentPack.id}); |
|---|
| 575 | | - |
|---|
| 576 | | -// $(document).on('change', '#request_data_file', function(newValue, oldValue) { |
|---|
| 577 | | -// console.log('File changed!!!!'); |
|---|
| 578 | | -// var reader = new FileReader(); |
|---|
| 579 | | -// reader.onload = function(data) { |
|---|
| 580 | | -// console.log('LOAD complete: ' + data); |
|---|
| 581 | | -// console.log('LOAD reader.result: ' + reader.result); |
|---|
| 582 | | -// $('input#request_data').val(reader.result) |
|---|
| 583 | | -// } |
|---|
| 584 | | -// console.log('file: ' + $('input#request_data_file').get(0).files[0]); |
|---|
| 585 | | -// console.log('file2: ' + $scope.request_data_file); |
|---|
| 586 | | -// reader.readAsText($('input#request_data_file').get(0).files[0]); |
|---|
| 587 | | -// }); |
|---|
| 588 | | - |
|---|
| 589 | | - $scope.save = function() { |
|---|
| 590 | | - //$( "form#licenseForm" ).attr( "enctype", "multipart/form-data" ).attr( "encoding", "multipart/form-data" ); |
|---|
| 591 | | - var _success = function() { |
|---|
| 592 | | - if (!$scope.isNew) $scope.showForm = false; |
|---|
| 593 | | - $scope.licenses = licenseResource.query({packId: $scope.currentPack.id}); |
|---|
| 594 | | - toaster.pop('success', Catalogs.getName(), $L.get("License '{0}' {1} successfully", $scope.license.code, $scope.isNew ? $L.get("created") : $L.get("updated"))); |
|---|
| 595 | | - } |
|---|
| 596 | | - var _error = function(error) { |
|---|
| 597 | | - console.log(error); |
|---|
| 598 | | - toaster.pop('error', Catalogs.getName(), $L.get("Error {0} license '{1}'. Reason: {2}", $scope.isNew ? $L.get("creating") : $L.get("updating"), $scope.pack.code, $L.get(error.headers('X-SECURIS-ERROR')))); |
|---|
| 599 | | - } |
|---|
| 600 | | - licenseResource.save($scope.license, _success, _error) |
|---|
| 634 | + if ($scope.currentPack) { |
|---|
| 635 | + $scope.licenses = Licenses.getLicensesList($scope.currentPack); |
|---|
| 601 | 636 | } |
|---|
| 637 | + |
|---|
| 638 | + $scope.save = function() { |
|---|
| 639 | + Licenses.saveLicenseData($scope.license, $scope.isNew, function() { |
|---|
| 640 | + if (!$scope.isNew) { |
|---|
| 641 | + $scope.showForm = false; |
|---|
| 642 | + } else { |
|---|
| 643 | + $scope.newLicense(); |
|---|
| 644 | + } |
|---|
| 645 | + $scope.licenses = Licenses.getLicensesList($scope.currentPack); |
|---|
| 646 | + }); |
|---|
| 647 | + } |
|---|
| 602 | 648 | |
|---|
| 603 | 649 | $scope.newLicense = function() { |
|---|
| 604 | 650 | if (!$scope.currentPack) { |
|---|
| .. | .. |
|---|
| 658 | 704 | var promise = licenseResource.remove({}, {id: selectedlicense.id}).$promise; |
|---|
| 659 | 705 | promise.then(function(data) { |
|---|
| 660 | 706 | $scope.selectlicense(null); |
|---|
| 661 | | - $scope.licenses = licenseResource.query({packId: $scope.currentPack.id}); |
|---|
| 707 | + $scope.licenses = Licenses.getLicensesList($scope.currentPack); |
|---|
| 662 | 708 | toaster.pop('success', Catalogs.getName(), $L.get("License '{0}' deleted successfully", selectedlicense.code)); |
|---|
| 663 | 709 | },function(error) { |
|---|
| 664 | 710 | console.log(error); |
|---|
| 665 | | - 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); |
|---|
| 711 | + 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-MSG')), 10000); |
|---|
| 666 | 712 | }); |
|---|
| 667 | 713 | } |
|---|
| 668 | 714 | }); |
|---|
| 669 | 715 | $scope.isNew = false; |
|---|
| 670 | 716 | } |
|---|
| 671 | 717 | |
|---|
| 718 | + $scope.execute = function(action, license) { |
|---|
| 719 | + if (!license) { |
|---|
| 720 | + license = $scope.license; |
|---|
| 721 | + } |
|---|
| 722 | + var _execute = function(extra_data) { |
|---|
| 723 | + if (extra_data) { |
|---|
| 724 | + Licenses[action](license, extra_data, function() { |
|---|
| 725 | + if (!$scope.isNew) $scope.showForm = false; |
|---|
| 726 | + $scope.licenses = Licenses.getLicensesList($scope.currentPack); |
|---|
| 727 | + }); |
|---|
| 728 | + } else { |
|---|
| 729 | + Licenses[action](license, function() { |
|---|
| 730 | + if (!$scope.isNew) $scope.showForm = false; |
|---|
| 731 | + $scope.licenses = Licenses.getLicensesList($scope.currentPack); |
|---|
| 732 | + }); |
|---|
| 733 | + } |
|---|
| 734 | + } |
|---|
| 735 | + if (action === 'delete') { |
|---|
| 736 | + BootstrapDialog.confirm($L.get("The license '{0}' will be deleted, are you sure?", license.code), function(result){ |
|---|
| 737 | + if(result) { |
|---|
| 738 | + _execute(); |
|---|
| 739 | + } |
|---|
| 740 | + }); |
|---|
| 741 | + } else { |
|---|
| 742 | + if (action === 'cancel') { |
|---|
| 743 | + BootstrapDialog.show({ |
|---|
| 744 | + title: $L.get("License cancellation"), |
|---|
| 745 | + type: BootstrapDialog.TYPE_DANGER, |
|---|
| 746 | + message: function(dialog) { |
|---|
| 747 | + var $content = $('<div></div>'); |
|---|
| 748 | + var $message = $('<div></div>'); |
|---|
| 749 | + var pageToLoad = dialog.getData('pageToLoad'); |
|---|
| 750 | + $message.append($('<label/>').text($L.get("This action cannot be undone.", $scope.pack.code))); |
|---|
| 751 | + $content.append($message); |
|---|
| 752 | + |
|---|
| 753 | + var $message = $('<div style="margin-top:10pt;"/>'); |
|---|
| 754 | + $message.append($('<label style="margin-right:5pt;"/>').text($L.get("Cancellation reason:") + " ")); |
|---|
| 755 | + $message.append($('<input type="text" style="width:100%;" maxlength="512" id="_lic_cancellation_reason"/>')); |
|---|
| 756 | + $content.append($message); |
|---|
| 757 | + return $content; |
|---|
| 758 | + }, |
|---|
| 759 | + closable: true, |
|---|
| 760 | + buttons: [{ |
|---|
| 761 | + id: 'btn-cancel', |
|---|
| 762 | + label: $L.get('Close'), |
|---|
| 763 | + cssClass: 'btn-default', |
|---|
| 764 | + action: function(dialogRef) { |
|---|
| 765 | + dialogRef.close(); |
|---|
| 766 | + } |
|---|
| 767 | + }, { |
|---|
| 768 | + id: 'btn-ok', |
|---|
| 769 | + label: $L.get('Cancel license'), |
|---|
| 770 | + cssClass: 'btn-primary', |
|---|
| 771 | + action: function(dialogRef){ |
|---|
| 772 | + var reason = $('#_lic_cancellation_reason').val(); |
|---|
| 773 | + console.log('Ready to cancel license, by reason: ' + reason); |
|---|
| 774 | + if (!reason) { |
|---|
| 775 | + $('#_lic_cancellation_reason').focus(); |
|---|
| 776 | + } else { |
|---|
| 777 | + _execute({reason: reason}); |
|---|
| 778 | + dialogRef.close(); |
|---|
| 779 | + } |
|---|
| 780 | + } |
|---|
| 781 | + }] |
|---|
| 782 | + }); |
|---|
| 783 | + } else { |
|---|
| 784 | + _execute(); |
|---|
| 785 | + } |
|---|
| 786 | + } |
|---|
| 787 | + } |
|---|
| 788 | + |
|---|
| 672 | 789 | |
|---|
| 673 | 790 | $scope.cancel = function() { |
|---|
| 674 | 791 | $scope.showForm = false; |
|---|