Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix insertAtCursor #2453

Merged
merged 2 commits into from Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions core/dom/dom.ui.js
Expand Up @@ -22,11 +22,11 @@
domUtils.showLoading = function(_timeout) {
document.getElementById('div_jeedomLoading')?.seen()
//Hanging timeout:
if(domUtils.loadingTimeout && domUtils.loadingTimeout != null){
if (domUtils.loadingTimeout && domUtils.loadingTimeout != null) {
clearTimeout(domUtils.loadingTimeout)
domUtils.loadingTimeout = null
}
if(_timeout && typeof _timeout == 'number'){
if (_timeout && typeof _timeout == 'number') {
domUtils.loadingTimeout = setTimeout(() => {
if (!document.getElementById('div_jeedomLoading')?.isHidden()) {
domUtils.hideLoading()
Expand All @@ -38,7 +38,7 @@ domUtils.showLoading = function(_timeout) {
}
domUtils.hideLoading = function() {
document.getElementById('div_jeedomLoading')?.unseen()
if(domUtils.loadingTimeout && domUtils.loadingTimeout != null){
if (domUtils.loadingTimeout && domUtils.loadingTimeout != null) {
clearTimeout(domUtils.loadingTimeout)
domUtils.loadingTimeout = null
}
Expand Down Expand Up @@ -193,11 +193,12 @@ Element.prototype.fade = function(_delayms, _opacity, _callback) {
}

Element.prototype.insertAtCursor = function(_valueString) {
if (this.selectionStart || this.selectionStart == '0') {
if (this.selectionStart >= 0) {
this.value = this.value.substring(0, this.selectionStart) + _valueString + this.value.substring(this.selectionEnd, this.value.length)
} else {
this.value += _valueString
}
this.focus()
return this
}

Expand Down
200 changes: 103 additions & 97 deletions desktop/modal/cmd.human.insert.php
Expand Up @@ -41,116 +41,122 @@
</table>

<script>
(function() {// Self Isolation!
if (window.mod_insertCmd == undefined) {
window.mod_insertCmd = function() {}
mod_insertCmd.options = {}
mod_insertCmd.options.cmd = {}
mod_insertCmd.options.eqLogic = {}
mod_insertCmd.options.object = {}
}else if(mod_insertCmd?.options?.object?.id){
document.getElementById('table_mod_insertCmdValue_valueEqLogicToMessage').querySelector('td.mod_insertCmdValue_object select').jeeValue(mod_insertCmd.options.object.id)
}

mod_insertCmd.setOptions = function(_options) {
mod_insertCmd.options = _options
var _selectObject = document.getElementById('table_mod_insertCmdValue_valueEqLogicToMessage').querySelector('td.mod_insertCmdValue_object select')
if (!isset(mod_insertCmd.options.cmd)) {
(function() { // Self Isolation!
if (window.mod_insertCmd == undefined) {
window.mod_insertCmd = function() {}
mod_insertCmd.options = {}
mod_insertCmd.options.cmd = {}
}
if (!isset(mod_insertCmd.options.eqLogic)) {
mod_insertCmd.options.eqLogic = {}
}
if (!isset(mod_insertCmd.options.object)) {
mod_insertCmd.options.object = {}
}
if (mod_insertCmd?.options?.object?.id) {
document.getElementById('table_mod_insertCmdValue_valueEqLogicToMessage').querySelector('td.mod_insertCmdValue_object select').value = mod_insertCmd.options.object.id
}
if (isset(mod_insertCmd.options.cmd.type)) {
if (mod_insertCmd.options.cmd.type == "info") document.querySelector('#table_mod_insertCmdValue_valueEqLogicToMessage #thCmd').textContent = "{{Commande info}}"
if (mod_insertCmd.options.cmd.type == "action") document.querySelector('#table_mod_insertCmdValue_valueEqLogicToMessage #thCmd').textContent = "{{Commande action}}"
} else if (mod_insertCmd?.options?.object?.id > 0) {
document.getElementById('table_mod_insertCmdValue_valueEqLogicToMessage').querySelector('td.mod_insertCmdValue_object select').jeeValue(mod_insertCmd.options.object.id)
}

mod_insertCmd.changeObjectCmd(_selectObject, mod_insertCmd.options)
document.getElementById('table_mod_insertCmdValue_valueEqLogicToMessage').addEventListener('change', function(event) {
if (event.target.matches('td.mod_insertCmdValue_object select')) {
mod_insertCmd.changeObjectCmd(_selectObject, mod_insertCmd.options)
mod_insertCmd.setOptions = function(_options) {
mod_insertCmd.options = _options
var _selectObject = document.getElementById('table_mod_insertCmdValue_valueEqLogicToMessage').querySelector('td.mod_insertCmdValue_object select')
if (!isset(mod_insertCmd.options.cmd)) {
mod_insertCmd.options.cmd = {}
}
if (!isset(mod_insertCmd.options.eqLogic)) {
mod_insertCmd.options.eqLogic = {}
}
if (!isset(mod_insertCmd.options.object)) {
mod_insertCmd.options.object = {}
}
if (mod_insertCmd?.options?.object?.id) {
document.getElementById('table_mod_insertCmdValue_valueEqLogicToMessage').querySelector('td.mod_insertCmdValue_object select').value = mod_insertCmd.options.object.id
}
if (isset(mod_insertCmd.options.cmd.type)) {
if (mod_insertCmd.options.cmd.type == "info") document.querySelector('#table_mod_insertCmdValue_valueEqLogicToMessage #thCmd').textContent = "{{Commande info}}"
if (mod_insertCmd.options.cmd.type == "action") document.querySelector('#table_mod_insertCmdValue_valueEqLogicToMessage #thCmd').textContent = "{{Commande action}}"
}
})
}

mod_insertCmd.getValue = function() {
let object = document.querySelector('#table_mod_insertCmdValue_valueEqLogicToMessage .mod_insertCmdValue_object > select')?.selectedOptions
let eqlogic = document.querySelector('#table_mod_insertCmdValue_valueEqLogicToMessage .mod_insertCmdValue_eqLogic > select')?.selectedOptions
let cmd = document.querySelector('#table_mod_insertCmdValue_valueEqLogicToMessage .mod_insertCmdValue_cmd > select')?.selectedOptions
if ([object, eqlogic, cmd].filter(hc => hc.length == 0).length > 0) {
return ''
mod_insertCmd.changeObjectCmd(_selectObject, mod_insertCmd.options)
document.getElementById('table_mod_insertCmdValue_valueEqLogicToMessage').addEventListener('change', function(event) {
if (event.target.matches('td.mod_insertCmdValue_object select')) {
mod_insertCmd.changeObjectCmd(_selectObject, mod_insertCmd.options)
}
})
}
return '#[' + object[0].text.trim() + '][' + eqlogic[0].text + '][' + cmd[0].text + ']#'
}

mod_insertCmd.getCmdId = function() {
return document.querySelector('#table_mod_insertCmdValue_valueEqLogicToMessage .mod_insertCmdValue_cmd > select').value || null
}
mod_insertCmd.getValue = function() {
let object = document.querySelector('#table_mod_insertCmdValue_valueEqLogicToMessage .mod_insertCmdValue_object > select')?.selectedOptions
let eqlogic = document.querySelector('#table_mod_insertCmdValue_valueEqLogicToMessage .mod_insertCmdValue_eqLogic > select')?.selectedOptions
let cmd = document.querySelector('#table_mod_insertCmdValue_valueEqLogicToMessage .mod_insertCmdValue_cmd > select')?.selectedOptions
if ([object, eqlogic, cmd].filter(hc => hc.length == 0).length > 0) {
return ''
}
return '#[' + object[0].text.trim() + '][' + eqlogic[0].text + '][' + cmd[0].text + ']#'
}

mod_insertCmd.getType = function() {
let opt = document.querySelector('#table_mod_insertCmdValue_valueEqLogicToMessage .mod_insertCmdValue_cmd > select').selectedOptions
return opt[0] ? opt[0].getAttribute('data-type') : null
}
mod_insertCmd.getCmdId = function() {
return document.querySelector('#table_mod_insertCmdValue_valueEqLogicToMessage .mod_insertCmdValue_cmd > select').value || null
}

mod_insertCmd.getType = function() {
let opt = document.querySelector('#table_mod_insertCmdValue_valueEqLogicToMessage .mod_insertCmdValue_cmd > select').selectedOptions
return opt[0] ? opt[0].getAttribute('data-type') : null
}

mod_insertCmd.getSubType = function() {
let opt = document.querySelector('#table_mod_insertCmdValue_valueEqLogicToMessage .mod_insertCmdValue_cmd > select').selectedOptions
return opt[0] ? opt[0].getAttribute('data-subType') : null
}
mod_insertCmd.getSubType = function() {
let opt = document.querySelector('#table_mod_insertCmdValue_valueEqLogicToMessage .mod_insertCmdValue_cmd > select').selectedOptions
return opt[0] ? opt[0].getAttribute('data-subType') : null
}

mod_insertCmd.changeObjectCmd = function(_select, _options) {
mod_insertCmd.options.object.id = (_select.jeeValue() == '' ? -1 : _select.jeeValue())
jeedom.object.getEqLogic({
id: (_select.jeeValue() == '' ? -1 : _select.jeeValue()),
orderByName : true,
onlyHasCmds : _options.cmd,
error: function(error) {
jeedomUtils.showAlert({message: error.message, level: 'danger'})
},
success: function(eqLogics) {
_select.closest('tr').querySelector('.mod_insertCmdValue_eqLogic').empty()
var selectEqLogic = '<select class="form-control">'
for (var i in eqLogics) {
if (init(mod_insertCmd.options.eqLogic.eqType_name, 'all') == 'all' || eqLogics[i].eqType_name == mod_insertCmd.options.eqLogic.eqType_name) {
selectEqLogic += '<option value="' + eqLogics[i].id + '">' + eqLogics[i].name + '</option>'
mod_insertCmd.changeObjectCmd = function(_select, _options) {
mod_insertCmd.options.object.id = (_select.jeeValue() == '' ? -1 : _select.jeeValue())
jeedom.object.getEqLogic({
id: (_select.jeeValue() == '' ? -1 : _select.jeeValue()),
orderByName: true,
onlyHasCmds: _options.cmd,
error: function(error) {
jeedomUtils.showAlert({
message: error.message,
level: 'danger'
})
},
success: function(eqLogics) {
_select.closest('tr').querySelector('.mod_insertCmdValue_eqLogic').empty()
var selectEqLogic = '<select class="form-control">'
for (var i in eqLogics) {
if (init(mod_insertCmd.options.eqLogic.eqType_name, 'all') == 'all' || eqLogics[i].eqType_name == mod_insertCmd.options.eqLogic.eqType_name) {
selectEqLogic += '<option value="' + eqLogics[i].id + '">' + eqLogics[i].name + '</option>'
}
}
selectEqLogic += '</select>'
_select.closest('tr').querySelector('.mod_insertCmdValue_eqLogic').insertAdjacentHTML('beforeend', selectEqLogic)
if (mod_insertCmd?.options?.eqLogic?.id && Array.from(_select.closest('tr').querySelectorAll('.mod_insertCmdValue_eqLogic select option')).filter(o => o.value === mod_insertCmd.options.eqLogic.id).length > 0) {
_select.closest('tr').querySelector('.mod_insertCmdValue_eqLogic select').jeeValue(mod_insertCmd.options.eqLogic.id)
}
_select.closest('tr').querySelector('.mod_insertCmdValue_eqLogic select').addEventListener('change', function() {
mod_insertCmd.changeEqLogic(this, mod_insertCmd.options)
})
mod_insertCmd.changeEqLogic(_select.closest('tr').querySelector('.mod_insertCmdValue_eqLogic select'), mod_insertCmd.options)
}
selectEqLogic += '</select>'
_select.closest('tr').querySelector('.mod_insertCmdValue_eqLogic').insertAdjacentHTML('beforeend', selectEqLogic)
if (mod_insertCmd?.options?.eqLogic?.id && Array.from(_select.closest('tr').querySelectorAll('.mod_insertCmdValue_eqLogic select option')).filter( o => o.value === mod_insertCmd.options.eqLogic.id ).length > 0) {
_select.closest('tr').querySelector('.mod_insertCmdValue_eqLogic select').jeeValue(mod_insertCmd.options.eqLogic.id)
}
_select.closest('tr').querySelector('.mod_insertCmdValue_eqLogic select').addEventListener('change', function() {
mod_insertCmd.changeEqLogic(this, mod_insertCmd.options)
})
mod_insertCmd.changeEqLogic(_select.closest('tr').querySelector('.mod_insertCmdValue_eqLogic select'), mod_insertCmd.options)
}
})
}
})
}

mod_insertCmd.changeEqLogic = function(_select, _options) {
jeedom.eqLogic.buildSelectCmd({
id: _select.jeeValue(),
filter: mod_insertCmd.options.cmd,
error: function(error) {
jeedomUtils.showAlert({message: error.message, level: 'danger'})
},
success: function(html) {
try { //No tr on object without equipment
_select.closest('tr').querySelector('.mod_insertCmdValue_cmd').empty()
var selectCmd = '<select class="form-control">'
selectCmd += html
selectCmd += '</select>'
_select.closest('tr').querySelector('.mod_insertCmdValue_cmd').insertAdjacentHTML('beforeend', selectCmd)
} catch (error) { }
}
})
}
})()
mod_insertCmd.changeEqLogic = function(_select, _options) {
jeedom.eqLogic.buildSelectCmd({
id: _select.jeeValue(),
filter: mod_insertCmd.options.cmd,
error: function(error) {
jeedomUtils.showAlert({
message: error.message,
level: 'danger'
})
},
success: function(html) {
try { //No tr on object without equipment
_select.closest('tr').querySelector('.mod_insertCmdValue_cmd').empty()
var selectCmd = '<select class="form-control">'
selectCmd += html
selectCmd += '</select>'
_select.closest('tr').querySelector('.mod_insertCmdValue_cmd').insertAdjacentHTML('beforeend', selectCmd)
} catch (error) {}
}
})
}
})()
</script>