app.controller('AdminCtrl', function($scope, $rootScope, $http, $window, $location, $route) { $scope.organizations = { name: 'Organizations', controller: 'organization', //Panel class panelClass: 'panel-dro', showFilters: false, pageLimit: 10, fields: [ 'id', 'name', ], fieldDetails: { 'id': { 'label': '#', 'hideEdit': true, }, 'name': { 'label': 'Name', }, }, buttons: { 'C':{ 'id': 'c', 'name': 'Add organization', 'confirmName': 'Insert', 'confirmClass': 'success', 'icon': 'fa-plus-square', 'header': $scope.user?.rights?.organization?.insert, 'action': 'create', }, 'R':{ 'id': 'r', 'name': 'View organization', 'icon': 'fa-search', 'inline': true, 'action': 'read', }, 'U':{ 'id': 'u', 'name': 'Update organization', 'confirmName': 'Update', 'confirmClass': 'warning', 'inline': $scope.user?.rights?.organization?.update, 'icon':'fa-pencil', 'action': 'update', }, 'D':{ 'id': 'd', 'name': 'Delete organization', 'confirmName': 'Delete', 'confirmClass': 'warning', 'inline': $scope.user?.rights?.organization?.delete, 'icon':'fa-trash', 'action': 'delete', }, } } $scope.users = { name: 'Users', controller: 'user', //Panel class panelClass: 'panel-dro', showFilters: false, pageLimit: 10, fields: [ 'organization_id', 'name', 'username', 'password', 'email', 'phone_mobile', 'user_role_id', ], //pair the organizations table subQueries: { 'organizations': { 'lfield': 'organization_id', 'ffield': 'id', 'controller': 'organization', }, 'role': { 'lfield': 'user_role_id', 'ffield': 'id', 'controller': 'user_role', }, }, //get the name of organization fieldDetails: { 'name': { 'label': 'Name', }, 'username': { 'label': 'Username', }, 'email': { 'label': 'Emailaddress', }, 'phone_mobile': { 'label': 'Phone number', }, 'organization_id': { 'label': 'Organization', 'default': $scope.user?.organization?.id, 'changeTo': ['organizations.name'], 'type': 'combobox', 'required': true, 'sortAsc': true, }, 'user_role_id': { 'label' : 'Role', 'changeTo' : ['role.name'], 'type' : 'combobox', 'required' : true, }, 'password': { 'type': 'password', 'label': 'Password', 'hideList': true, } }, buttons: { 'C':{ 'id': 'c', 'name': 'Add user', 'confirmName': 'Insert', 'confirmClass': 'success', 'icon': 'fa-plus-square', 'header': $scope.user?.rights?.user?.insert, 'action': 'create', }, 'R':{ 'id': 'r', 'name': 'View user', 'icon': 'fa-search', 'inline': true, 'action': 'read', }, 'U':{ 'id': 'u', 'name': 'Update user', 'confirmName': 'Update', 'confirmClass': 'warning', 'inline': $scope.user?.rights?.user?.update, 'icon':'fa-pencil', 'action': 'update', }, 'D':{ 'id': 'd', 'name': 'Delete user', 'confirmName': 'Delete', 'confirmClass': 'warning', 'inline': $scope.user?.rights?.user?.delete, 'icon':'fa-trash', 'action': 'delete', }, } } $scope.groups = { name: 'User groups', controller: 'user_group', showFilters: false, pageLimit: 10, //Panel class panelClass: 'panel-dro', fields: [ 'organization_id', 'user_id', 'group_id' ], subQueries: { 'organizations': { 'lfield': 'organization_id', 'ffield': 'id', 'controller': 'organization', }, 'user': { 'lfield': 'user_id', 'ffield': 'id', 'controller': 'user', }, 'group': { 'lfield': 'group_id', 'ffield': 'id', 'controller': 'group', }, }, fieldDetails: { organization_id: { 'label': 'Organization', 'default': $scope.user?.organization?.id, 'changeTo': ['organizations.name'], 'type': 'combobox', 'required': true, 'sortAsc': true, }, user_id:{ 'label': 'User', 'changeTo': ['user.name'], 'type': 'combobox', 'required': true, }, group_id:{ 'label': 'Group', 'changeTo': ['group.name'], 'type': 'combobox', 'required': true, }, }, autoChangeTo: [ 'user_group_id', 'user_id', 'group_id', ] } $scope.offices = { name: 'Offices', controller: 'office', getCSV: true, pageLimit: 25, //Panel class panelClass: 'panel-dro', //pair the organizations table subQueries: { 'organizations': { 'lfield': 'organization_id', 'ffield': 'id', 'controller': 'organization', }, }, fieldDetails: { id: { label: '#', hideList: true, hideEdit: true, }, organization_id: { 'label': 'Organization', 'default': $scope.user?.organization?.id, 'changeTo': ['organizations.name'], 'type': 'combobox', 'required': true, 'sortAsc': true, }, }, } $scope.suppliers = { name: 'Suppliers', controller: 'Invoice_reader', readOnly: true, pageLimit: 10, //Panel class panelClass: 'panel-dro', fields: [ 'id', 'name', ], fieldDetails: { 'id': { 'label': '#', } } } $scope.direct_debit_suppliers = { name: 'Direct debit suppliers', controller: 'direct_debit_supplier', //Panel class panelClass: 'panel-dro', showFilters: false, pageLimit: 10, fields: [ 'id', 'name', 'column', 'row', 'preg_match', 'remove_first_and_last_row', ], //get the name of organization fieldDetails: { 'id': { 'label': '#', }, 'name': { 'label': 'Name', }, 'column': { 'label': 'Column', }, 'row': { 'label': 'Row', }, 'preg_match': { 'label': 'Preg match', }, 'remove_first_and_last_row': { 'label': 'Remove header and footer', 'type': 'boolean', 'booleanOn': "1", 'booleanOff': "0" }, }, } // set email boxes table $scope.email_boxes = { name: 'E-mail boxes', controller: 'email_box', //Panel class panelClass: 'panel-dro', function: 'getAll', pageLimit: 10, autoChangeTo: ['organization_id'], fields: [ 'organization_id', 'username', 'password', 'server', 'tenant_id', 'client_id', 'client_secret', 'user_id', 'is_connected', 'connection_error', 'is_first_connection', ], subQueries: { 'organizations': { 'lfield': 'organization_id', 'ffield': 'id', 'controller': 'organization', }, }, fieldDetails: { 'organization_id': { 'label': 'Organization', 'default': $scope.user?.organization?.id, 'changeTo': ['organizations.name'], 'type': 'combobox', 'required': true, 'sortAsc': true, }, 'username': { label: 'Username', required: true, }, 'password': { label: 'Password', hideList: true, type: 'password', }, 'server': { label: 'Server', hideList: true, }, 'tenant_id': { label: 'Tenant ID', hideList: true, }, 'client_id': { label: 'Client ID', hideList: true, }, 'client_secret': { label: 'Client secret', hideList: true, }, 'user_id': { label: 'User ID', hideList: true, }, 'is_connected': { label: 'Connected?', hideEdit: true, 'type': 'boolean', 'booleanOn': "1", 'booleanOff': "0" }, 'connection_error': { label: 'Connection error', hideEdit: true, }, 'is_first_connection': { hideList: true, hideEdit: true, }, }, buttons: { 'CC':{ 'id': 'cc', 'name': 'connect', 'inline': true, 'icon':'fa-wifi', 'label': 'Create connection', 'parentScope': true, 'action': 'emailBoxConnect', 'customClass': 'button-icon-only', 'function': 'update', // backend function to check rights 'tooltipLabel': 'connect', 'whereField': 'is_first_connection', 'where': { '==': '1', } }, 'RC':{ 'id': 'rc', 'name': 'connect', 'inline': true, 'icon':'fa-wifi', 'label': 'Refresh connection', 'parentScope': true, 'action': 'emailBoxConnect', 'customClass': 'button-icon-only', 'function': 'update', // backend function to check rights 'tooltipLabel': 'connect', 'whereField': 'is_first_connection', 'where': { '==': '', } }, }, }; $scope.emailBoxConnect = function (btn, row) { if (row.username?.length && row.tenant_id?.length && row.client_id?.length && row.client_secret?.length) { window.open('/email_box/execute/' + row.id, '_self'); } else { swal('Error', 'The required mailbox credentials aren\'t provided.', 'error'); } } });