[enhancement] Note comes in read-only on opening, with edit button
This commit is contained in:
parent
20a332bf86
commit
e5056d6bb1
2 changed files with 46 additions and 1 deletions
39
frappe/desk/doctype/note/note.js
Normal file
39
frappe/desk/doctype/note/note.js
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
frappe.ui.form.on("Note", {
|
||||
refresh: function(frm) {
|
||||
if(frm.doc.__islocal) {
|
||||
frm.events.set_editable(frm, true);
|
||||
} else {
|
||||
// toggle edit
|
||||
frm.add_custom_button("Edit", function() {
|
||||
frm.events.set_editable(frm, !frm.is_note_editable);
|
||||
})
|
||||
frm.events.set_editable(frm, false);
|
||||
}
|
||||
},
|
||||
set_editable: function(frm, editable) {
|
||||
// hide all fields other than content
|
||||
|
||||
// no permission
|
||||
if(editable && !frm.perm[0].write) return;
|
||||
|
||||
// content read_only
|
||||
frm.set_df_property("content", "read_only", editable ? 0: 1);
|
||||
|
||||
// hide all other fields
|
||||
$.each(frm.fields_dict, function(fieldname, field) {
|
||||
|
||||
if(fieldname !== "content"
|
||||
&& !in_list(["Section Break", "Column Break"], field.df.fieldtype)) {
|
||||
frm.set_df_property(fieldname, "hidden", editable ? 0: 1);
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
// no label, description for content either
|
||||
frm.get_field("content").toggle_label(editable);
|
||||
frm.get_field("content").toggle_description(editable);
|
||||
|
||||
// set flag for toggle
|
||||
frm.is_note_editable = editable;
|
||||
}
|
||||
});
|
||||
|
|
@ -180,6 +180,12 @@ frappe.ui.form.ControlInput = frappe.ui.form.Control.extend({
|
|||
</div>').appendTo(this.parent);
|
||||
}
|
||||
},
|
||||
toggle_label: function(show) {
|
||||
this.$wrapper.find(".control-label").toggleClass("hide", !show);
|
||||
},
|
||||
toggle_description: function(show) {
|
||||
this.$wrapper.find(".help-box").toggleClass("hide", !show);
|
||||
},
|
||||
set_input_areas: function() {
|
||||
if(this.only_input) {
|
||||
this.input_area = this.wrapper;
|
||||
|
|
@ -637,7 +643,7 @@ frappe.ui.form.ControlButton = frappe.ui.form.ControlData.extend({
|
|||
this.input = this.$input.get(0);
|
||||
this.set_input_attributes();
|
||||
this.has_input = true;
|
||||
this.$wrapper.find(".control-label").addClass("hide");
|
||||
this.toggle_label(false);
|
||||
},
|
||||
onclick: function() {
|
||||
if(this.frm && this.frm.doc) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue