Skip to content

Commit

Permalink
Merge branch '4.0-dev' into jmailfinder
Browse files Browse the repository at this point in the history
  • Loading branch information
jeckodevelopment committed Mar 8, 2019
2 parents 3cb279e + 634a854 commit 7695747
Show file tree
Hide file tree
Showing 7 changed files with 354 additions and 117 deletions.
1 change: 1 addition & 0 deletions administrator/language/en-GB/en-GB.ini
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ JACTION_EDITVALUE="Edit Custom Field Value"
JACTION_EDITSTATE="Edit State"
JACTION_EXECUTETRANSITION="Execute transition"
JACTION_LOGIN_ADMIN="Administrator Login"
JACTION_LOGIN_API="Web Services Login"
JACTION_LOGIN_OFFLINE="Offline Access"
JACTION_LOGIN_SITE="Site Login"
JACTION_MANAGE="Access Administration Interface"
Expand Down
61 changes: 39 additions & 22 deletions build/media_source/system/js/fields/joomla-field-user.w-c.es6.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
((customElements) => {
(() => {
class JoomlaFieldUser extends HTMLElement {
constructor() {
super();

this.onUserSelect = '';
this.onchangeStr = '';
this.buttonClick = this.buttonClick.bind(this);
this.iframeLoad = this.iframeLoad.bind(this);
}

static get observedAttributes() {
return ['url', 'modal-class', 'modal-width', 'modal-height', 'input', 'input-name', 'button-select'];
}
Expand Down Expand Up @@ -48,26 +57,44 @@
this.modal.addEventListener('hide', this.removeIframe.bind(this));

// Check for onchange callback,
const onchangeStr = this.input.getAttribute('data-onchange');
let onUserSelect;
if (onchangeStr) {
this.onchangeStr = this.input.getAttribute('data-onchange');
if (this.onchangeStr) {
/* eslint-disable */
onUserSelect = new Function(onchangeStr);
this.input.addEventListener('change', onUserSelect.bind(this.input));
this.onUserSelect = new Function(this.onchangeStr);
this.input.addEventListener('change', this.onUserSelect);
/* eslint-enable */
}
}
}

disconnectedCallback() {
this.buttonSelect.removeEventListener('click', this);
if (this.onchangeStr && this.input) {
this.input.removeEventListener('change', this.onUserSelect);
}

if (this.buttonSelect) {
this.buttonSelect.removeEventListener('click', this);
}

this.modal.removeEventListener('hide', this);
}

buttonClick(event) {
this.setValue(event.target.getAttribute('data-user-value'), event.target.getAttribute('data-user-name'));
this.modalClose();
}

iframeLoad() {
const iframeDoc = this.iframeEl.contentWindow.document;
const buttons = [].slice.call(iframeDoc.querySelectorAll('.button-select'));

buttons.forEach((button) => {
button.addEventListener('click', this.buttonClick);
});
}

// Opens the modal
modalOpen() {
const self = this;

// Reconstruct the iframe
this.removeIframe();
const iframe = document.createElement('iframe');
Expand All @@ -80,20 +107,10 @@

this.modal.open();

const iframeEl = this.modalBody.querySelector('iframe');
this.iframeEl = this.modalBody.querySelector('iframe');

// handle the selection on the iframe
iframeEl.addEventListener('load', () => {
const iframeDoc = iframeEl.contentWindow.document;
const buttons = [].slice.call(iframeDoc.querySelectorAll('.button-select'));

buttons.forEach((button) => {
button.addEventListener('click', (event) => {
self.setValue(event.target.getAttribute('data-user-value'), event.target.getAttribute('data-user-name'));
self.modalClose();
});
});
});
this.iframeEl.addEventListener('load', this.iframeLoad);
}

// Closes the modal
Expand All @@ -115,4 +132,4 @@
}

customElements.define('joomla-field-user', JoomlaFieldUser);
})(customElements);
})();
162 changes: 91 additions & 71 deletions build/media_source/system/js/joomla-toolbar-button.w-c.es6.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,100 +3,120 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

((customElements) => {
'use strict';
window.customElements.define('joomla-toolbar-button', class extends HTMLElement {
// Attribute getters
get task() { return this.getAttribute('task'); }

class JoomlaToolbarButton extends HTMLElement {
// Attribute getters
get task() { return this.getAttribute('task'); }
get listSelection() { return this.hasAttribute('list-selection'); }

get listSelection() { return this.hasAttribute('list-selection'); }
get form() { return this.getAttribute('form'); }

get form() { return this.getAttribute('form'); }
get formValidation() { return this.hasAttribute('form-validation'); }

get formValidation() { return this.hasAttribute('form-validation'); }
get confirmMessage() { return this.getAttribute('confirm-message'); }

get confirmMessage() { return this.getAttribute('confirm-message'); }
/**
* Lifecycle
*/
constructor() {
super();

constructor() {
super();

// We need a button to support button behavior,
// because we cannot currently extend HTMLButtonElement
this.buttonElement = this.querySelector('button, a');
this.disabled = false;
if (!Joomla) {
throw new Error('Joomla API is not properly initiated');
}

// If list selection are required, set button to disabled by default
if (this.listSelection) {
this.setDisabled(true);
}
this.disabled = false;

this.addEventListener('click', e => this.executeTask(e));
// If list selection is required, set button to disabled by default
if (this.listSelection) {
this.setDisabled(true);
}

connectedCallback() {
// Check whether we have a form
const formSelector = this.form || 'adminForm';
this.formElement = document.getElementById(formSelector);
this.onChange = this.onChange.bind(this);

if (this.listSelection) {
if (!this.formElement) {
throw new Error(`The form "${formSelector}" is required to perform the task, but the form not found on the page.`);
}
this.addEventListener('click', event => this.executeTask(event));
}

// Watch on list selection
this.formElement.boxchecked.addEventListener('change', (event) => {
// Check whether we have selected something
this.setDisabled(event.target.value < 1);
});
/**
* Lifecycle
*/
connectedCallback() {
// We need a button to support button behavior,
// because we cannot currently extend HTMLButtonElement
this.buttonElement = this.querySelector('button, a');

// Check whether we have a form
const formSelector = this.form || 'adminForm';
this.formElement = document.getElementById(formSelector);

if (this.listSelection) {
if (!this.formElement) {
throw new Error(`The form "${formSelector}" is required to perform the task, but the form was not found on the page.`);
}

// Watch on list selection
this.formElement.boxchecked.addEventListener('change', this.onChange);
}
}

setDisabled(disabled) {
// Make sure we have a boolean value
this.disabled = !!disabled;
/**
* Lifecycle
*/
disconnectedCallback() {
if (this.formElement.boxchecked) {
this.formElement.boxchecked.removeEventListener('change', this.onChange);
}

// Switch attribute for current element
if (this.disabled) {
this.setAttribute('disabled', true);
} else {
this.removeAttribute('disabled');
}
this.removeEventListener('click');
}

// Switch attribute for native element
// An anchor do not support "disabled" attribute, so use class
if (this.buttonElement) {
if (this.disabled) {
if (this.buttonElement.nodeName === 'BUTTON') {
this.buttonElement.setAttribute('disabled', true);
} else {
this.buttonElement.classList.add('disabled');
}
} else if (this.buttonElement.nodeName === 'BUTTON') {
this.buttonElement.removeAttribute('disabled');
} else {
this.buttonElement.classList.remove('disabled');
}
}
onChange(event) {
// Check whether we have selected something
this.setDisabled(event.target.value < 1);
}

setDisabled(disabled) {
// Make sure we have a boolean value
this.disabled = !!disabled;

// Switch attribute for current element
if (this.disabled) {
this.setAttribute('disabled', true);
} else {
this.removeAttribute('disabled');
}

executeTask() {
// Switch attribute for native element
// An anchor does not support "disabled" attribute, so use class
if (this.buttonElement) {
if (this.disabled) {
return false;
if (this.buttonElement.nodeName === 'BUTTON') {
this.buttonElement.setAttribute('disabled', true);
} else {
this.buttonElement.classList.add('disabled');
}
} else if (this.buttonElement.nodeName === 'BUTTON') {
this.buttonElement.removeAttribute('disabled');
} else {
this.buttonElement.classList.remove('disabled');
}
}
}

// eslint-disable-next-line no-restricted-globals
if (this.confirmMessage && !confirm(this.confirmMessage)) {
return false;
}
executeTask() {
if (this.disabled) {
return false;
}

if (this.task) {
Joomla.submitbutton(this.task, this.form, this.formValidation);
}
// eslint-disable-next-line no-restricted-globals
if (this.confirmMessage && !confirm(this.confirmMessage)) {
return false;
}

return true;
if (this.task) {
Joomla.submitbutton(this.task, this.form, this.formValidation);
}
}

customElements.define('joomla-toolbar-button', JoomlaToolbarButton);
})(customElements);
return true;
}
});
1 change: 1 addition & 0 deletions language/en-GB/en-GB.ini
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ JACTION_EDIT="Edit"
JACTION_EDITOWN="Edit Own"
JACTION_EDITSTATE="Edit State"
JACTION_LOGIN_ADMIN="Administrator Login"
JACTION_LOGIN_API="Web Services Login"
JACTION_LOGIN_SITE="Site Login"
JACTION_MANAGE="Access Administration Interface"

Expand Down

0 comments on commit 7695747

Please sign in to comment.