-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Autocomplete widget added for selecting a Group member (CFM-150) (#164)
- Loading branch information
Showing
9 changed files
with
697 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php | ||
/** | ||
* COmanage Registry People Autocomplete Vue.js Component | ||
* | ||
* Portions licensed to the University Corporation for Advanced Internet | ||
* Development, Inc. ("UCAID") under one or more contributor license agreements. | ||
* See the NOTICE file distributed with this work for additional information | ||
* regarding copyright ownership. | ||
* | ||
* UCAID licenses this file to you under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with the | ||
* License. You may obtain a copy of the License at: | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* @link https://www.internet2.edu/comanage COmanage Project | ||
* @package registry | ||
* @since COmanage Registry v5.0.0 | ||
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) | ||
*/ | ||
|
||
// Get parameters | ||
$fieldName = $fieldName ?? ""; | ||
$type = $type ?? ""; | ||
$htmlId = $htmlId ?? ""; | ||
|
||
// Get the CSRF Token in JavaScript | ||
$token = $this->request->getAttribute('csrfToken'); | ||
// Load my helper functions | ||
$vueHelper = $this->loadHelper('Vue'); | ||
|
||
// Create a people autocomplete text input. | ||
?> | ||
|
||
<script type="module"> | ||
<?php if(Cake\Core\Configure::read('debug')): ?> | ||
import AutocompletePeople from "<?= $this->Url->script('comanage/components/autocomplete/cm-autocomplete-people.js') ?>?time=<?= time() ?>"; | ||
<?php else: ?> | ||
import AutocompletePeople from "<?= $this->Url->script('comanage/components/autocomplete/cm-autocomplete-people.js') ?>"; | ||
<?php endif; ?> | ||
|
||
const app = Vue.createApp({ | ||
data() { | ||
return { | ||
autocompleteOptions: { | ||
fieldName: '<?= $fieldName ?>', | ||
type: '<?= $type ?>', | ||
minLength: 2, // XXX probably should be set by config and default to 3 | ||
htmlId: '<?= $htmlId ?>' | ||
}, | ||
error: '', | ||
core: { | ||
webroot: '<?= $this->request->getAttribute('webroot') ?>' | ||
}, | ||
txt: JSON.parse('<?= json_encode($vueHelper->locales()) ?>') | ||
} | ||
}, | ||
components: { | ||
AutocompletePeople | ||
}, | ||
methods: { | ||
setError(txt) { | ||
this.error = txt; | ||
}, | ||
generalXhrFailCallback(xhr) { | ||
stopSpinner(); | ||
this.successTxt = ''; | ||
if(xhr.statusText != undefined && xhr.statusText != '') { | ||
this.setError(xhr.statusText) | ||
console.log('Status Code: ', xhr.status) | ||
} else { | ||
console.error(xhr); | ||
this.setError(this.txt.error500); | ||
} | ||
} | ||
} | ||
}); | ||
|
||
app.use(primevue.config.default, {unstyled: true}); | ||
|
||
// Mount the component and provide a global reference for this app instance. | ||
window.<?= $htmlId ?> = app.mount("#<?= $htmlId ?>-container"); | ||
</script> | ||
|
||
<div id="<?= $htmlId ?>-container" class="cm-autocomplete-container"> | ||
<autocomplete-people | ||
:options="this.autocompleteOptions" | ||
:core="this.core" | ||
:txt="this.txt"> | ||
</autocomplete-people> | ||
</div> |
This file contains 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
This file contains 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
109 changes: 109 additions & 0 deletions
109
app/webroot/js/comanage/components/autocomplete/cm-autocomplete-people.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/** | ||
* COmanage Registry PeoplePicker Component JavaScript | ||
* | ||
* Portions licensed to the University Corporation for Advanced Internet | ||
* Development, Inc. ("UCAID") under one or more contributor license agreements. | ||
* See the NOTICE file distributed with this work for additional information | ||
* regarding copyright ownership. | ||
* | ||
* UCAID licenses this file to you under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with the | ||
* License. You may obtain a copy of the License at: | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* @link https://www.internet2.edu/comanage COmanage Project | ||
* @package registry | ||
* @since COmanage Registry v5.0.0 | ||
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) | ||
*/ | ||
|
||
import { camelize } from '../utils/helpers.js'; | ||
|
||
export default { | ||
props: { | ||
options: Object, | ||
core: Object, | ||
txt: Object | ||
}, | ||
components: { | ||
AutoComplete : primevue.autocomplete | ||
}, | ||
data() { | ||
return { | ||
people: [], | ||
person: '' | ||
} | ||
}, | ||
methods: { | ||
search() { | ||
this.people = [ | ||
{ | ||
"value": 16, | ||
"label": "Test J Testington IV", | ||
"email": "test.testington@myvo.org 1", | ||
"emailLabel": "Email (official): ", | ||
"identifier": "50010", | ||
"identifierLabel": "Identifier (employeenumber): " | ||
}, | ||
{ | ||
"value": 17, | ||
"label": "Test JR Testington V", | ||
"email": "test.testington@myvo.org 1", | ||
"emailLabel": "Email (official): ", | ||
"identifier": "50002", | ||
"identifierLabel": "Identifier (employeenumber): " | ||
}, | ||
{ | ||
"value": 280, | ||
"label": "Test C Testington", | ||
"email": "test.testington@myvo.org 1", | ||
"emailLabel": "Email (official): ", | ||
"identifier": "50052", | ||
"identifierLabel": "Identifier (employeenumber): " | ||
} | ||
]; | ||
}, | ||
setPerson() { | ||
const field = document.getElementById(this.options.fieldName); | ||
field.value = this.person.value; | ||
} | ||
}, | ||
template: ` | ||
<label :for="this.inputId">{{ this.txt['autocomplete.people.label'] }}</label> | ||
<AutoComplete | ||
v-model="person" | ||
inputClass="cm-autocomplete" | ||
panelClass="cm-autocomplete-panel" | ||
:inputId="this.options.htmlId" | ||
:suggestions="this.people" | ||
optionLabel="label" | ||
@complete="search" | ||
:minLength="this.options.minLength" | ||
:placeholder="this.txt['autocomplete.people.placeholder']" | ||
forceSelection | ||
@item-select="setPerson"> | ||
<template #option="slotProps"> | ||
<div class="cm-ac-item"> | ||
<div class="cm-ac-item-primary cm-ac-name">{{ slotProps.option.label }}</div> | ||
<div class="cm-ac-subitems"> | ||
<div class="cm-ac-subitem cm-ac-email" v-if="slotProps.option.email"> | ||
<span class="cm-ac-label" v-if="slotProps.option.emailLabel">{{ slotProps.option.emailLabel }}</span> | ||
<span class="cm-ac-value">{{ slotProps.option.email }}</span> | ||
</div> | ||
<div class="cm-ac-subitem cm-ac-id" v-if="slotProps.option.identifier"> | ||
<span class="cm-ac-label" v-if="slotProps.option.identifierLabel">{{ slotProps.option.identifierLabel }}</span> | ||
<span class="cm-ac-value">{{ slotProps.option.identifier }}</span> | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
</AutoComplete> | ||
` | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.