diff --git a/UI/GeneralUI.js b/UI/GeneralUI.js index 2b4029e..3beba59 100644 --- a/UI/GeneralUI.js +++ b/UI/GeneralUI.js @@ -54,14 +54,26 @@ export class GeneralUI */ bindHref (e) { - e = e !== null ? e.querySelectorAll('[data-href]') : document.querySelectorAll('[data-href]'); + e = e !== null ? e.querySelectorAll('[data-href], [href]') : document.querySelectorAll('[data-href], [href]'); const length = e.length; for (let i = 0; i < length; ++i) { + if (e[i].getAttribute('data-action') !== null) { + continue; + } + e[i].addEventListener('click', function(event) { jsOMS.preventAll(event); history.pushState(null, null, window.location); - window.location = UriFactory.build(this.getAttribute('data-href')); + + let uri = this.getAttribute('data-href'); + uri = uri === null ? this.getAttribute('href') : uri; + + if (this.getAttribute('target') === '_blank' || this.getAttribute(['data-target']) === '_blank') { + window.open(UriFactory.build(uri), '_blank'); + } else { + window.location = UriFactory.build(uri); + } }); } }; diff --git a/Uri/UriFactory.js b/Uri/UriFactory.js index 54a317c..383a248 100644 --- a/Uri/UriFactory.js +++ b/Uri/UriFactory.js @@ -1,4 +1,5 @@ import { Http } from './Http.js'; +import { FormView } from './../Views//FormView.js'; /** * Uri factory. @@ -190,7 +191,18 @@ export class UriFactory const e = document.getElementById(match.substr(1)); if (e) { - return e.value; + if (e.tagName.toLowerCase() !== 'form') { + return e.value; + } + + let value = ''; + const form = (new FormView(e.id)).getData(); + + for (let pair of form.entries()) { + value += '&' + pair[0] + '=' + pair[1]; + } + + return value; } return ''; diff --git a/Views/FormView.js b/Views/FormView.js index 0d6b9de..26ea002 100644 --- a/Views/FormView.js +++ b/Views/FormView.js @@ -1,4 +1,4 @@ -import { Input } from '../UI/Component/Input.js'; +import { Input } from '/jsOMS/UI/Component/Input.js'; /** * Form view. @@ -312,24 +312,38 @@ export class FormView specialLength = specialExt.length; for (let i = 0; i < inputLength; ++i) { - if ((inputs[i].type === 'checkbox' || inputs[i].type === 'radio') && !inputs[i].checked) { + if (inputs[i] === undefined + || (typeof inputs[i] !== 'undefined' + && (inputs[i].type === 'checkbox' || inputs[i].type === 'radio') + && !inputs[i].checked) + ) { delete inputs[i]; } } for (let i = 0; i < externalLength; ++i) { - if (form.contains(external[i])) { + if (external[i] === undefined + || (typeof external[i] !== 'undefined' + && form.contains(external[i])) + ) { delete external[i]; continue; } - if ((external[i].type === 'checkbox' || external[i].type === 'radio') && !external[i].checked) { + if ( external[i] === undefined + || (typeof external[i] !== 'undefined' + && (external[i].type === 'checkbox' || external[i].type === 'radio') + && !external[i].checked) + ) { delete external[i]; } } for (let i = 0; i < specialLength; ++i) { - if (form.contains(specialExt[i])) { + if (specialExt[i] === undefined + || (typeof specialExt[i] !== 'undefined' + && form.contains(specialExt[i])) + ) { delete specialExt[i]; continue; }