您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

editable.js 1.4 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. wn.make_editable = function(editor, doctype, name, fieldname) {
  2. wn.require("/assets/js/editor.min.js");
  3. WebPageEditor = bsEditor.extend({
  4. onhide: function(action) {
  5. this._super(action);
  6. this.toggle_edit_mode(false);
  7. },
  8. setup_editor: function(editor) {
  9. this._super(editor);
  10. this.toggle_edit_mode(false);
  11. },
  12. toggle_edit_mode: function(bool) {
  13. var me = this;
  14. this._super(bool);
  15. if(!bool) {
  16. // remove existing web page editor toggles
  17. $('li.editable-toggle + li').remove();
  18. $('li.editable-toggle').remove();
  19. var $edit_btn = $(repl('<li class="editable-toggle">\
  20. <a href="#"><i class="icon-fixed-width icon-pencil"></i>Edit %(doctype)s</a></li>\
  21. <li class="divider"></li>', {doctype: doctype}))
  22. .prependTo($("#website-post-login ul.dropdown-menu"));
  23. $edit_btn.find("a")
  24. .on("click", function() {
  25. me.toggle_edit_mode(true);
  26. $edit_btn.remove();
  27. return false;
  28. });
  29. }
  30. }
  31. });
  32. bseditor = new WebPageEditor({
  33. editor: editor,
  34. onsave: function(bseditor) {
  35. wn.call({
  36. type: "POST",
  37. method: "webnotes.client.set_value",
  38. args: {
  39. doctype: doctype,
  40. name: name,
  41. fieldname: fieldname,
  42. value: bseditor.get_value()
  43. },
  44. callback: function(r) {
  45. wn.msgprint(r.exc ? "Error" : "Saved");
  46. if(!r.exc)
  47. editor.html(r.message[0][fieldname]);
  48. }
  49. });
  50. }
  51. });
  52. };