Add more generalized legacy Lookup integration

This commit is contained in:
gconsidine
2017-06-22 17:36:23 -04:00
parent dc1bff9048
commit b7982bf202
4 changed files with 18 additions and 22 deletions

View File

@@ -1,12 +1,11 @@
const DEFAULT_ORGANIZATION_PLACEHOLDER = 'SELECT AN ORGANIZATION'; const DEFAULT_ORGANIZATION_PLACEHOLDER = 'SELECT AN ORGANIZATION';
function AddCredentialsController (models, organizationList, $state) { function AddCredentialsController (models, $state) {
let vm = this || {}; let vm = this || {};
let me = models.me; let me = models.me;
let credential = models.credential; let credential = models.credential;
let credentialType = models.credentialType; let credentialType = models.credentialType;
let organization = models.organization;
vm.panelTitle = 'NEW CREDENTIAL'; vm.panelTitle = 'NEW CREDENTIAL';
@@ -23,8 +22,8 @@ function AddCredentialsController (models, organizationList, $state) {
omit: ['user', 'team', 'inputs'] omit: ['user', 'team', 'inputs']
}); });
vm.form.organization._model = organization; vm.form.organization._resource = 'organization';
vm.form.organization._placeholder = DEFAULT_ORGANIZATION_PLACEHOLDER; vm.form.organization._route = 'credentials.add.organization';
vm.form.credential_type._data = credentialType.get('results'); vm.form.credential_type._data = credentialType.get('results');
vm.form.credential_type._placeholder = 'SELECT A TYPE'; vm.form.credential_type._placeholder = 'SELECT A TYPE';
@@ -53,7 +52,6 @@ function AddCredentialsController (models, organizationList, $state) {
AddCredentialsController.$inject = [ AddCredentialsController.$inject = [
'resolvedModels', 'resolvedModels',
'OrganizationList',
'$state' '$state'
]; ];

View File

@@ -3,13 +3,12 @@ import AddController from './add-credentials.controller.js';
import EditController from './edit-credentials.controller.js'; import EditController from './edit-credentials.controller.js';
import { N_ } from '../../src/i18n'; import { N_ } from '../../src/i18n';
function CredentialsResolve ($q, $stateParams, Me, Credential, CredentialType, Organization) { function CredentialsResolve ($q, $stateParams, Me, Credential, CredentialType) {
let id = $stateParams.credential_id; let id = $stateParams.credential_id;
let promises = { let promises = {
me: new Me('get'), me: new Me('get'),
credentialType: new CredentialType('get'), credentialType: new CredentialType('get')
organization: new Organization('get')
}; };
if (id) { if (id) {
@@ -26,8 +25,7 @@ CredentialsResolve.$inject = [
'$stateParams', '$stateParams',
'MeModel', 'MeModel',
'CredentialModel', 'CredentialModel',
'CredentialTypeModel', 'CredentialTypeModel'
'OrganizationModel'
]; ];
function CredentialsConfig ($stateExtenderProvider, legacyProvider, pathProvider) { function CredentialsConfig ($stateExtenderProvider, legacyProvider, pathProvider) {

View File

@@ -2,9 +2,6 @@ function atInputLookupLink (scope, element, attrs, controllers) {
let formController = controllers[0]; let formController = controllers[0];
let inputController = controllers[1]; let inputController = controllers[1];
scope.ns = 'lookup';
scope[scope.ns] = { modal: {} };
if (scope.tab === '1') { if (scope.tab === '1') {
element.find('input')[0].focus(); element.find('input')[0].focus();
} }
@@ -16,27 +13,30 @@ function AtInputLookupController (baseInputController, $state) {
let vm = this || {}; let vm = this || {};
let scope; let scope;
let modal;
vm.init = (_scope_, element, form) => { vm.init = (_scope_, element, form) => {
baseInputController.call(vm, 'input', _scope_, element, form); baseInputController.call(vm, 'input', _scope_, element, form);
scope = _scope_; scope = _scope_;
scope.$watch('organization', () => { scope.$watch(scope.state._resource, () => {
if (scope.organization) { if (scope[scope.state._resource]) {
scope.state._value = scope.organization; scope.state._value = scope[scope.state._resource];
scope.state._displayValue = scope.organization_name; scope.state._displayValue = scope[`${scope.state._resource}_name`];
} }
}); });
modal = scope.lookup.modal;
vm.check(); vm.check();
}; };
vm.search = () => { vm.search = () => {
$state.go('credentials.add.organization'); let params = {};
if (scope.state._value) {
params.selected = scope.state._value;
}
$state.go(scope.state._route, params);
}; };
} }

View File

@@ -23,5 +23,5 @@
<at-input-message></at-input-message> <at-input-message></at-input-message>
</div> </div>
<div ui-view="organization"></div> <div ui-view="{{ state._resource }}"></div>
</div> </div>