chore: refactor nexcloud plugin- related to NC-addressbook

This commit is contained in:
Fahim Salam Chowdhury 2024-09-03 12:37:37 +06:00
parent 2e3fbe0a12
commit 552a91acc2
5 changed files with 200 additions and 163 deletions

View file

@ -1,38 +0,0 @@
(rl => {
if (rl) {
addEventListener('rl-view-model', e => {
if ('SettingsContacts' === e.detail.viewModelTemplateID) {
const container = e.detail.viewModelDom.querySelector('.form-horizontal');
if (container) {
rl.pluginRemoteRequest((iError, oData) => {
if (!iError) {
const mainDivElement = Element.fromHTML('<div class="control-group">'
+ '<label>' + rl.i18n("NEXTCLOUD/ADDRESS_BOOK") + '</label>'
+ '</div>');
const selectElement = Element.fromHTML('<select></select>');
const books = JSON.parse(oData.Result.addressbooks);
books.forEach(book => {
if (book.selected) {
selectElement.append(Element.fromHTML('<option value="' + book.uri + '" selected="selected">' + book.name + '</option>'));
} else {
selectElement.append(Element.fromHTML('<option value="' + book.uri + '">' + book.name + '</option>'));
}
});
selectElement.onchange = function() {
rl.pluginRemoteRequest(() => { }, 'NextcloudUpdateAddressBook', {
uri: selectElement.value
});
}
mainDivElement.append(selectElement);
container.append(mainDivElement);
}
}, "NextcloudGetAddressBooks");
}
}
});
}
})(window.rl);

View file

@ -13,14 +13,16 @@
addEventListener('rl-view-model', e => {
if ('SystemDropDown' === e.detail.viewModelTemplateID) {
const container = e.detail.viewModelDom.querySelector('.dropdown-menu');
if (container) {
for (i = 0; i < container.children.length; i++) {
const element = container.children[i];
const attr = element.getAttribute("data-bind");
if (attr && attr.includes("visible: allowContacts")) {
element.remove();
break;
}
if (!container) {
return;
}
for (i = 0; i < container.children.length; i++) {
const element = container.children[i];
const attr = element.getAttribute("data-bind");
if (attr && attr.includes("visible: allowContacts")) {
element.remove();
break;
}
}
}
@ -29,14 +31,16 @@
addEventListener('rl-view-model', e => {
if ('PopupsCompose' === e.detail.viewModelTemplateID) {
const container = e.detail.viewModelDom.querySelector('.pull-right');
if (container) {
for (i = 0; i < container.children.length; i++) {
const element = container.children[i];
const attr = element.getAttribute("data-bind");
if (attr && attr.includes("visible: allowContacts")) {
element.remove();
break;
}
if(!container) {
return;
}
for (i = 0; i < container.children.length; i++) {
const element = container.children[i];
const attr = element.getAttribute("data-bind");
if (attr && attr.includes("visible: allowContacts")) {
element.remove();
break;
}
}
}

View file

@ -0,0 +1,42 @@
(rl => {
if (rl) {
addEventListener('rl-view-model', e => {
if ('SettingsContacts' === e.detail.viewModelTemplateID) {
const container = e.detail.viewModelDom.querySelector('.form-horizontal');
if (!container) {
return;
}
rl.pluginRemoteRequest((iError, oData) => {
if (iError) {
return;
}
const mainDivElement = Element.fromHTML('<div class="control-group">'
+ '<label>' + rl.i18n("NEXTCLOUD/ADDRESS_BOOK") + '</label>'
+ '</div>');
const selectElement = Element.fromHTML('<select></select>');
const addressbooks = JSON.parse(oData.Result.addressbooks);
addressbooks.forEach(addressbook => {
if (addressbook.selected) {
selectElement.append(Element.fromHTML('<option value="' + addressbook.uri + '" selected="selected">' + addressbook.name + '</option>'));
} else {
selectElement.append(Element.fromHTML('<option value="' + addressbook.uri + '">' + addressbook.name + '</option>'));
}
});
selectElement.onchange = function() {
rl.pluginRemoteRequest(() => { }, 'NextcloudUpdateAddressBook', {
uri: selectElement.value
});
}
mainDivElement.append(selectElement);
container.append(mainDivElement);
}, "NextcloudGetAddressBooks");
}
});
}
})(window.rl);