class ProjectSelect extends DataSelect { /** * The data type for which this select should display the options. */ get type() { return "project"; } /** * Override this to provide filters for the options that should get into the dropdown. */ get filters() { return { deleted: 0, completed: 0 }; } setOptionInformation(option, projectId, project) { option.value = projectId; option.innerText = project.name; } /*constructor(element) { super(element); this.options = { }; TimeCards.dataManager.addDataListener("project", { deleted: 0 }, this.onProjectUpdate.bind(this)); } setOptionInformation(option, project) { option.value = project.project_id; option.innerText = project.name; } /** * Adds a static option to the dropdown. * addOption(value, label) { var option = document.createElement("OPTION"); option.value = value; option.innerText = label; this.options[value] = option; this.element.appendChild(option); } onProjectUpdate(projectId, project, sortedBefore) { if (!project) { //Handle the deleted project. if (!(projectId in this.options)) { console.warn("Trying to remove a project from a project select that was never added."); return; } var option = this.options[projectId]; //Do nothing if it is a completed project. It will not be in the dropdown in the first place. if (option.parentNode == this.element) { this.element.removeChild(option); } delete this.options[projectId]; } else if (!(projectId in this.options)) { //Handle the added project. var option = document.createElement("OPTION"); this.setOptionInformation(option, project); this.options[projectId] = option; //Only add the dropdown entry if the project is not completed. if (!project.completed) { this.element.insertBefore(option, sortedBefore ? this.options[sortedBefore] : null); } } else { //Handle the changed project. var option = this.options[projectId]; this.setOptionInformation(option, project); //Add or remove the option depending on whether the project is completed or not. if (project.completed) { if (this.element.contains(option)) { this.element.removeChild(option); } } else { //Re-add the option to maintain the sort order in case of a name change. this.element.insertBefore(option, sortedBefore ? this.options[sortedBefore] : null); } } }*/ } UIKit.registerViewType(ProjectSelect);