Et2Favorites: Update sidebox favorite icons when user changes default favorite

This commit is contained in:
nathan 2023-02-09 16:47:59 -07:00
parent 4322937ea7
commit 570edaa1e0
2 changed files with 33 additions and 3 deletions

View File

@ -165,6 +165,11 @@ export class Et2Favorites extends Et2DropdownButton implements et2_INextmatchHea
} }
} }
get preferred() : string
{
return this._preferred;
}
_optionTemplate(option : SelectOption) : TemplateResult _optionTemplate(option : SelectOption) : TemplateResult
{ {
let radio = html`<input type="radio" slot="prefix" name="favorite" value="${option.value}" let radio = html`<input type="radio" slot="prefix" name="favorite" value="${option.value}"
@ -279,9 +284,17 @@ export class Et2Favorites extends Et2DropdownButton implements et2_INextmatchHea
{ {
options.push({value: Et2Favorites.ADD_VALUE, label: this.egw().lang('Add current')}); options.push({value: Et2Favorites.ADD_VALUE, label: this.egw().lang('Add current')});
} }
this.requestUpdate("select_options");
return options; return options;
} }
public load_favorites(app)
{
this.__select_options = this._load_favorites(app);
this.requestUpdate("select_options");
}
/** /**
* Add the current settings as a new favorite * Add the current settings as a new favorite
*/ */
@ -362,7 +375,9 @@ export class Et2Favorites extends Et2DropdownButton implements et2_INextmatchHea
this.egw().set_preference(this.app, this.defaultPref, pref); this.egw().set_preference(this.app, this.defaultPref, pref);
this._preferred = pref; this._preferred = pref;
this.dropdownNode.hide(); this.dropdownNode.hide();
this.requestUpdate(); this.requestUpdate("select_options");
this.dispatchEvent(new Event("change", {bubbles: true}));
} }
_handleDelete(_ev : MouseEvent) _handleDelete(_ev : MouseEvent)
@ -481,5 +496,4 @@ export class Et2Favorites extends Et2DropdownButton implements et2_INextmatchHea
} }
} }
// @ts-ignore TypeScript is not recognizing that this is a LitElement
customElements.define("et2-favorites", Et2Favorites); customElements.define("et2-favorites", Et2Favorites);

View File

@ -861,6 +861,23 @@ export abstract class EgwApp
{ {
self.highlight_favorite(); self.highlight_favorite();
}); });
egw_fw.applications[this.appname].browser.baseDiv.addEventListener("change", (e) =>
{
if(e.target.localName == "et2-favorites")
{
sidebox[0].querySelectorAll("li:not([data-id='add']) > a > div:first-child").forEach(f =>
{
f.classList.add("sideboxstar");
f.classList.remove('ui-icon', 'ui-heart');
});
const new_pref = sidebox[0].querySelector("li[data-id='" + e.target.preferred + "'] > a > div:first-child");
if(new_pref)
{
new_pref.classList.add('ui-icon', 'ui-icon-heart');
new_pref.classList.remove("sideboxstar");
}
}
})
} }
return true; return true;
} }
@ -904,7 +921,6 @@ export abstract class EgwApp
et2[i].widgetContainer.iterateOver(function(_widget) et2[i].widgetContainer.iterateOver(function(_widget)
{ {
_widget.stored_filters = _widget.load_favorites(self.appname); _widget.stored_filters = _widget.load_favorites(self.appname);
_widget.init_filters(_widget);
}, self, Et2Favorites); }, self, Et2Favorites);
} }
} }