-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP]: awesome_dashboard: Tutorial chapter 2: item 11
- Loading branch information
Showing
4 changed files
with
77 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
awesome_dashboard/static/src/components/dashboard_dialog.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** @odoo-module **/ | ||
|
||
import { Component, useState} from "@odoo/owl"; | ||
import { Dialog } from "@web/core/dialog/dialog"; | ||
import { CheckBox } from "@web/core/checkbox/checkbox"; | ||
import { browser } from "@web/core/browser/browser"; | ||
|
||
export class AwesomeDashboardDialog extends Component { | ||
static template = "awesome_dashboard.AwesomeDashboardDialog"; | ||
static components = { Dialog, CheckBox } | ||
static props = { | ||
dashboardItems: Object, | ||
updateUncheckedItems: Function, | ||
} | ||
setup(){ | ||
this.dashboardItems = useState(this.props.dashboardItems); | ||
this.itemCheckmarks = useState({ }); | ||
let id; | ||
for(let i = 0; i < this.dashboardItems.length; i++){ | ||
id = this.dashboardItems.at(i).id; | ||
this.itemCheckmarks[id] = !browser.localStorage.getItem("AwesomeDashboardUncheckedItems").includes(id); | ||
} | ||
this.dialogTitle = "Dashboard items configuration"; | ||
} | ||
itemToggle(ev, id){ | ||
this.itemCheckmarks[id] = ev; | ||
} | ||
dialogSave(){ | ||
const newUncheckedItems = []; | ||
for(let i = 0; i < this.dashboardItems.length; i++){ | ||
if(this.itemCheckmarks[this.dashboardItems.at(i).id] == false){ | ||
newUncheckedItems.push(this.dashboardItems.at(i).id); | ||
} | ||
} | ||
browser.localStorage.setItem("AwesomeDashboardUncheckedItems", newUncheckedItems); | ||
this.props.updateUncheckedItems(newUncheckedItems); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
awesome_dashboard/static/src/components/dashboard_dialog.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<templates xml:space="preserve"> | ||
|
||
<t t-name="awesome_dashboard.AwesomeDashboardDialog"> | ||
<Dialog title="dialogTitle"> | ||
<p>Check items to be displayed:</p> | ||
<t t-foreach="dashboardItems" t-as="item" t-key="item.id"> | ||
<CheckBox value="itemCheckmarks[item.id]" onChange="(ev) => this.itemToggle(ev, item.id)"> | ||
<t t-esc="item.description"/> | ||
</CheckBox> | ||
</t> | ||
<t t-set-slot="footer"> | ||
<button class="btn btn-primary" t-on-click="dialogSave">Save</button> | ||
</t> | ||
</Dialog> | ||
</t> | ||
|
||
</templates> |