fix: only allow to add existing number card on workspace

separated logic for dashboard and workspace implementation
This commit is contained in:
Shariq Ansari 2023-02-28 10:56:56 +05:30
parent bf6bd60b89
commit 7abb3e48e1
5 changed files with 36 additions and 3 deletions

View file

@ -95,6 +95,7 @@ export default class Block {
const dialog_class = get_dialog_constructor(widget_type);
let block_name = block + "_name";
this.dialog = new dialog_class({
for_workspace: true,
label: this.label,
type: widget_type,
primary_action: (widget) => {

View file

@ -23,6 +23,7 @@ export default class NumberCard extends Block {
allow_hiding: false,
allow_edit: true,
allow_resize: true,
for_workspace: true,
};
}

View file

@ -131,6 +131,7 @@ export default class Widget {
const dialog_class = get_dialog_constructor(this.widget_type);
this.edit_dialog = new dialog_class({
for_workspace: this.options?.for_workspace,
label: this.label,
type: this.widget_type,
values: this.get_config(),

View file

@ -11,7 +11,7 @@ export default class NumberCardWidget extends Widget {
get_config() {
return {
name: this.name,
number_card_name: this.number_card_name || this.name,
number_card_name: this.number_card_name,
label: this.label,
color: this.color,
hidden: this.hidden,

View file

@ -511,6 +511,32 @@ class NumberCardDialog extends WidgetDialog {
get_fields() {
let fields;
if (this.for_workspace) {
return [
{
fieldtype: "Link",
fieldname: "number_card_name",
label: __("Number Cards"),
options: "Number Card",
reqd: 1,
get_query: () => {
return {
query: "frappe.desk.doctype.number_card.number_card.get_cards_for_user",
filters: {
document_type: this.document_type,
},
};
},
},
{
fieldtype: "Data",
fieldname: "label",
label: __("Label"),
},
];
}
fields = [
{
fieldtype: "Select",
@ -605,7 +631,7 @@ class NumberCardDialog extends WidgetDialog {
}
setup_dialog_events() {
if (!this.document_type) {
if (!this.document_type && !this.for_workspace) {
if (this.default_values && this.default_values["doctype"]) {
this.document_type = this.default_values["doctype"];
this.setup_filter(this.default_values["doctype"]);
@ -638,12 +664,16 @@ class NumberCardDialog extends WidgetDialog {
}
process_data(data) {
if (this.for_workspace) {
data.label = data.label ? data.label : data.number_card_name;
return data;
}
if (data.new_or_existing == "Existing Card") {
data.name = data.card;
}
data.stats_filter = this.filter_group && JSON.stringify(this.filter_group.get_filters());
data.document_type = this.document_type;
data.label = data.label ? data.label : data.card;
return data;
}
}