-
-
Save pilucdes/d005e72fa9d2c50fcfb8ebf0c3d04af8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| angular.module('wdfApp.controllers') | |
| .controller('RequestListCtrl', ['$scope', '$http', '$q', function ($scope, $http, $q) { | |
| $scope.btnAcceptVisibleClass = "hidden"; | |
| $scope.btnRefuseVisibleClass = "hidden"; | |
| $scope.btnAcceptText = "Accept"; | |
| var UpdateDatagrid = function () { | |
| $scope.btnRefuseVisibleClass = "hidden"; | |
| $scope.btnAcceptVisibleClass = "hidden"; | |
| var grid = $("#requestsGrid").dxDataGrid("instance"); | |
| grid.refresh(); | |
| grid.clearSelection(); | |
| }; | |
| //DataSource | |
| var requestStore = new DevExpress.data.CustomStore({ | |
| load: function (loadOptions) { | |
| var await = $q.defer(); | |
| $http({ | |
| method: 'GET', url: '/api/requests', | |
| headers: { Authorization: 'Bearer ' + wdf.core.session.user.getToken() } | |
| }).success(function (data) { | |
| await.resolve(data); | |
| }); | |
| return await.promise; | |
| } | |
| }); | |
| var serverStore = new DevExpress.data.CustomStore({ | |
| load: function (loadOptions) { | |
| var await = $q.defer(); | |
| $http({ | |
| method: 'GET', url: '/api/servers', | |
| headers: { Authorization: 'Bearer ' + wdf.core.session.user.getToken() } | |
| }).success(function (data) { | |
| await.resolve(data); | |
| }); | |
| return await.promise; | |
| } | |
| }); | |
| $scope.newCompanyRegister = JSON.parse(JSON.stringify(EasySolution.Classes.ESUsersCompanyRegister)); | |
| $scope.visibleFormAccepted = false; | |
| $scope.popupOptions = { | |
| width: 650, | |
| height: 500, | |
| contentTemplate: "info", | |
| showTitle: true, | |
| title: "Register the company", | |
| dragEnabled: false, | |
| closeOnOutsideClick: true, | |
| bindingOptions: { | |
| visible: "visibleFormAccepted", | |
| } | |
| }; | |
| $scope.formAcceptedlabelLocation = "left"; | |
| $scope.formAcceptedOptions = { | |
| bindingOptions: { | |
| formData: "newCompanyRegister", | |
| readOnly: false, | |
| showColonAfterLabel: false, | |
| labelLocation: "formAcceptedlabelLocation", | |
| minColWidth: 300, | |
| colCount: "2", | |
| width: "undefined" | |
| }, | |
| items: [{ | |
| dataField: "Company.Name", | |
| label: { text: "Company Name" }, | |
| validationRules: [{ | |
| type: "required", | |
| message: "Company name is required" | |
| }] | |
| }, { | |
| dataField: "Company.LegalName", | |
| label: { text: "Legal Name" }, | |
| }, "Address", "City", | |
| { | |
| dataField: "Company.PostalCode", | |
| label: { text: "Postal Code" }, | |
| editorOptions: { | |
| mask: "LNL NLN", | |
| maskRules: { | |
| "L": /[a-zA-Z]/, | |
| "N": /[0-9]/ | |
| } | |
| } | |
| }, | |
| { | |
| dataField: "Company.PhoneNumber", | |
| label: { text: "Phone Number" }, | |
| validationRules: [{ | |
| type: "required", | |
| message: "Phone number is required" | |
| }], | |
| editorOptions: { | |
| mask: "000-000-0000" | |
| } | |
| }, | |
| { | |
| dataField: "Company.PhoneTollFree", | |
| label: { text: "Toll Free" }, | |
| editorOptions: { | |
| mask: "000-000-0000" | |
| } | |
| }, | |
| { | |
| dataField: "Company.PhoneFax", | |
| label: { text: "Fax" }, | |
| editorOptions: { | |
| mask: "000-000-0000" | |
| } | |
| }, | |
| { | |
| dataField: "Company.ServerId", | |
| label: { text: "Server" }, | |
| editorType: "dxLookup", | |
| editorOptions: { | |
| dataSource: serverStore, | |
| displayExpr: "Name", | |
| valueExpr: "id", | |
| closeOnOutsideClick: true, | |
| popupHeight: 450, | |
| popupWidth: 320, | |
| animation: { | |
| show: { | |
| type: "fade", | |
| duration: 400, | |
| from: 0.1, | |
| to: 1 | |
| }, | |
| hide: { | |
| type: "fade", | |
| duration: 400, | |
| from: 1, | |
| to: 0.1 | |
| } | |
| }, | |
| title: "Select server", | |
| placeholder: "Select a server", | |
| itemTemplate: function (data) { | |
| return EasySolution.Templates.Servers(data); | |
| } | |
| }, | |
| validationRules: [{ | |
| type: "required", | |
| message: "Server is required" | |
| }] | |
| }] | |
| }; | |
| $scope.dataGridOptions = { | |
| dataSource: requestStore, | |
| hoverStateEnabled: true, | |
| bindingOptions: { | |
| searchPanel: "searchPanel", | |
| showColumnLines: "false", | |
| showRowLines: "false", | |
| showBorders: "false", | |
| rowAlternationEnabled: "true" | |
| }, | |
| columns: [ | |
| { | |
| dataField: "CompanyName", | |
| caption: "Company Name" | |
| }, | |
| { | |
| dataField: "Status", | |
| caption: "Status", | |
| lookup: { | |
| dataSource: EasySolution.Enums.RequestStatus.Dictionary, | |
| displayExpr: "Name", | |
| valueExpr: "ID" | |
| } | |
| }, { | |
| dataField: "ContactPhone", | |
| caption: "Contact Phone" | |
| }, { | |
| dataField: "ContactEmail", | |
| caption: "Contact Email" | |
| }, | |
| { | |
| dataField: "RequestDate", | |
| caption: "Request Date", | |
| sortOrder: "desc", | |
| dataType: "date" | |
| }], | |
| selection: { | |
| mode: "single" | |
| }, | |
| remoteOperations: false | |
| , | |
| loadPanel: { | |
| text: "Loading..." | |
| }, | |
| scrolling: { | |
| mode: "virtual" | |
| }, | |
| sorting: { | |
| mode: "single" | |
| }, | |
| onSelectionChanged: function (selectedItems) { | |
| if (selectedItems.selectedRowsData.length == 0) | |
| { return; } | |
| $scope.selectedRequest = selectedItems.selectedRowsData[0]; | |
| $scope.btnRefuseVisibleClass = "visible"; | |
| $scope.btnAcceptVisibleClass = "visible"; | |
| $scope.btnAcceptText = "Accept"; | |
| //Cancel , Comfirmed | |
| if ($scope.selectedRequest.Status == EasySolution.Enums.RequestStatus.Enum.Confirmed || | |
| $scope.selectedRequest.Status == EasySolution.Enums.RequestStatus.Enum.Cancelled) { | |
| $scope.btnRefuseVisibleClass = "hidden"; | |
| $scope.btnAcceptVisibleClass = "hidden"; | |
| } | |
| //Waiting | |
| else if ($scope.selectedRequest.Status == EasySolution.Enums.RequestStatus.Enum.WaitingManager) { | |
| $scope.btnAcceptText = "Resend email"; | |
| } | |
| } | |
| }; | |
| $scope.btnRefuse = { | |
| text: "Cancel", | |
| type: "danger", | |
| onClick: function (params) { | |
| $http({ | |
| method: 'POST', url: '/api/Requests/Cancel', | |
| headers: { Authorization: 'Bearer ' + wdf.core.session.user.getToken() }, | |
| data: $scope.selectedRequest | |
| }).success(function (data) { | |
| UpdateDatagrid(); | |
| }).error(function (data) { | |
| DevExpress.ui.notify("Error while creating company", "error", EasySolution.Const.Notify.closeDelay); | |
| }); | |
| } | |
| }; | |
| $scope.btnAccept = { | |
| type: "success", | |
| bindingOptions: { | |
| text: 'btnAcceptText' | |
| }, | |
| onClick: function (params) { | |
| if ($scope.selectedRequest != null) { | |
| $scope.newCompanyRegister.Company.Name = $scope.selectedRequest.CompanyName; | |
| $scope.newCompanyRegister.Company.LegalName = $scope.selectedRequest.CompanyName; | |
| $scope.newCompanyRegister.Company.PhoneNumber = $scope.selectedRequest.ContactPhone; | |
| $scope.newCompanyRegister.RequestId = $scope.selectedRequest.id; | |
| if ($scope.selectedRequest.Status == EasySolution.Enums.RequestStatus.Enum.WaitingManager) { | |
| SendRequest($scope.newCompanyRegister); | |
| } | |
| else { | |
| $scope.ShowFormAccepted(); | |
| } | |
| } | |
| } | |
| }; | |
| $scope.postRegisterCompany = { | |
| text: "Register", | |
| type: "default", | |
| onClick: function (params) { | |
| var form = $("#formAccepted").dxForm("instance"); | |
| var result = form.validate(); | |
| if (result.isValid) { | |
| $scope.newCompanyRegister.Company.PhoneNumber = form.getEditor('Company.PhoneNumber').option("text"); | |
| $scope.newCompanyRegister.Company.PhoneFax = form.getEditor('Company.PhoneFax').option("text"); | |
| $scope.newCompanyRegister.Company.PhoneTollFree = form.getEditor('Company.PhoneTollFree').option("text"); | |
| SendRequest($scope.newCompanyRegister); | |
| } | |
| } | |
| }; | |
| $scope.ShowFormAccepted = function () { | |
| $scope.visibleFormAccepted = true; | |
| } | |
| var SendRequest = function (data) { | |
| $http({ | |
| method: 'POST', url: '/api/Requests/Accept', | |
| headers: { Authorization: 'Bearer ' + wdf.core.session.user.getToken() }, | |
| data: data | |
| }).success(function (data) { | |
| DevExpress.ui.notify("Company created, an email has been sent to the manager for the registration", "success", EasySolution.Const.Notify.closeDelay); | |
| UpdateDatagrid(); | |
| $scope.visibleFormAccepted = false; | |
| }).error(function (data) { | |
| DevExpress.ui.notify("Error while creating company", "error", EasySolution.Const.Notify.closeDelay); | |
| }); | |
| } | |
| }]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment