fix: Edit Shortcut
This commit is contained in:
parent
788c511274
commit
e07fb1f736
7 changed files with 49 additions and 34 deletions
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
import json
|
||||
from json import loads, dumps
|
||||
from frappe import _, DoesNotExistError, ValidationError, _dict
|
||||
from frappe.boot import get_allowed_pages, get_allowed_reports
|
||||
|
|
@ -549,6 +550,11 @@ def save_new_widget(page, new_widgets):
|
|||
if widgets.card:
|
||||
original_page.build_links_table_from_card(widgets.card)
|
||||
|
||||
content = frappe.db.get_value("Internal Wiki Page", page, "content")
|
||||
for wid in ['shortcut']:
|
||||
widd = [x['data'][ wid + '_name'] for x in json.loads(content) if x['type'] == wid]
|
||||
original_page.set(wid+'s', [ele for ele in original_page.get(wid+'s') if ele.label in widd])
|
||||
|
||||
try:
|
||||
original_page.save(ignore_permissions=True)
|
||||
except (ValidationError, TypeError) as e:
|
||||
|
|
|
|||
|
|
@ -101,13 +101,8 @@ class Workspace(Document):
|
|||
})
|
||||
|
||||
def build_links_table_from_card(self, config):
|
||||
# Empty links table
|
||||
# self.links = []
|
||||
# order = config.get('order')
|
||||
# widgets = config.get('widgets')
|
||||
|
||||
for idx, card in enumerate(config):
|
||||
# card = widgets[name].copy()
|
||||
links = loads(card.get('links'))
|
||||
|
||||
self.append('links', {
|
||||
|
|
|
|||
|
|
@ -404,6 +404,7 @@ frappe.views.Wiki = class Wiki {
|
|||
this.dirty = true;
|
||||
},
|
||||
readOnly: true,
|
||||
logLevel: 'ERROR'
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -440,22 +441,19 @@ frappe.views.Wiki = class Wiki {
|
|||
frappe.dom.unfreeze();
|
||||
if (res.message) {
|
||||
let cur_page = res.message;
|
||||
if (!$.isEmptyObject(new_widgets)) {
|
||||
frappe.call('frappe.desk.desktop.save_new_widget', {
|
||||
page: me.title,
|
||||
new_widgets: new_widgets
|
||||
}).then(res => {
|
||||
if (res.message) {
|
||||
me.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
frappe.show_alert({ message: __("Page Saved Successfully"), indicator: "green" });
|
||||
me.title = '';
|
||||
me.parent = '';
|
||||
me.sorted_sidebar_items = [];
|
||||
me.new_page = cur_page;
|
||||
me.reload();
|
||||
frappe.call('frappe.desk.desktop.save_new_widget', {
|
||||
page: me.title,
|
||||
new_widgets: new_widgets
|
||||
}).then(res => {
|
||||
if (res.message) {
|
||||
frappe.show_alert({ message: __("Page Saved Successfully"), indicator: "green" });
|
||||
me.title = '';
|
||||
me.parent = '';
|
||||
me.sorted_sidebar_items = [];
|
||||
me.new_page = cur_page;
|
||||
me.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -170,6 +170,7 @@ export default class Widget {
|
|||
data.name = this.name;
|
||||
|
||||
this.refresh();
|
||||
this.options.on_edit && this.options.on_edit(data);
|
||||
},
|
||||
primary_action_label: __("Save")
|
||||
});
|
||||
|
|
|
|||
|
|
@ -208,7 +208,8 @@ export class SingleWidgetGroup {
|
|||
});
|
||||
widget_object.options = {
|
||||
...this.options,
|
||||
on_delete: (name) => this.on_delete(name)
|
||||
on_delete: () => this.on_delete(),
|
||||
on_edit: () => this.on_edit(widget_object)
|
||||
};
|
||||
this.widgets_list.push(widget_object);
|
||||
this.widgets_dict[widget.name] = widget_object;
|
||||
|
|
@ -216,10 +217,14 @@ export class SingleWidgetGroup {
|
|||
return widget_object;
|
||||
}
|
||||
|
||||
on_delete(name, setup_new) {
|
||||
on_delete() {
|
||||
this.api.blocks.delete();
|
||||
}
|
||||
|
||||
on_edit(widget_object) {
|
||||
this.block.call("on_edit", widget_object);
|
||||
}
|
||||
|
||||
customize() {
|
||||
this.widgets_list.forEach((wid) => {
|
||||
wid.customize(this.options);
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ export default class Card {
|
|||
wid.options = {
|
||||
...this.options,
|
||||
on_delete: () => this.api.blocks.delete()
|
||||
}
|
||||
};
|
||||
wid.customize(this.options);
|
||||
this.wrapper.setAttribute("card_name", wid.label);
|
||||
this.new_card_widget = wid.get_config();
|
||||
|
|
|
|||
|
|
@ -11,9 +11,10 @@ export default class Shortcut {
|
|||
return true;
|
||||
}
|
||||
|
||||
constructor({data, api, config, readOnly}) {
|
||||
constructor({data, api, config, readOnly, block}) {
|
||||
this.data = data;
|
||||
this.api = api;
|
||||
this.block = block;
|
||||
this.config = config;
|
||||
this.readOnly = readOnly;
|
||||
this.col = this.data.col ? this.data.col : "12";
|
||||
|
|
@ -69,18 +70,19 @@ export default class Shortcut {
|
|||
type: 'shortcut',
|
||||
primary_action: (widget) => {
|
||||
widget.in_customize_mode = 1;
|
||||
let wid = frappe.widget.make_widget({
|
||||
this.shortcut_widget = frappe.widget.make_widget({
|
||||
...widget,
|
||||
widget_type: 'shortcut',
|
||||
container: this.wrapper
|
||||
});
|
||||
wid.options = {
|
||||
this.shortcut_widget.options = {
|
||||
...this.options,
|
||||
on_delete: () => this.api.blocks.delete(),
|
||||
}
|
||||
wid.customize(this.options);
|
||||
this.wrapper.setAttribute("shortcut_name", wid.label);
|
||||
this.new_shortcut_widget = wid.get_config();
|
||||
on_edit: () => this.on_edit(this.shortcut_widget)
|
||||
};
|
||||
this.shortcut_widget.customize(this.options);
|
||||
this.wrapper.setAttribute("shortcut_name", this.shortcut_widget.label);
|
||||
this.new_shortcut_widget = this.shortcut_widget.get_config();
|
||||
},
|
||||
});
|
||||
|
||||
|
|
@ -155,22 +157,30 @@ export default class Shortcut {
|
|||
this.shortcut_field.make();
|
||||
}
|
||||
|
||||
on_edit(shortcut_obj) {
|
||||
let shortcut = shortcut_obj.get_config();
|
||||
this.shortcut_widget.widgets = shortcut;
|
||||
this.wrapper.setAttribute("shortcut_name", shortcut.label);
|
||||
this.new_shortcut_widget = shortcut_obj.get_config();
|
||||
}
|
||||
|
||||
_make_shortcuts(shortcut_name) {
|
||||
let shortcut = this.config.page_data.shortcuts.items.find(obj => {
|
||||
return obj.label == shortcut_name;
|
||||
});
|
||||
this.wrapper.innerHTML = '';
|
||||
shortcut.in_customize_mode = !this.readOnly;
|
||||
let shortcut_widget = new frappe.widget.SingleWidgetGroup({
|
||||
this.shortcut_widget = new frappe.widget.SingleWidgetGroup({
|
||||
container: this.wrapper,
|
||||
type: "shortcut",
|
||||
options: this.options,
|
||||
widgets: shortcut,
|
||||
api: this.api
|
||||
api: this.api,
|
||||
block: this.block
|
||||
});
|
||||
this.wrapper.setAttribute("shortcut_name", shortcut_name);
|
||||
if (!this.readOnly) {
|
||||
shortcut_widget.customize();
|
||||
this.shortcut_widget.customize();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue