diff --git a/core/doctype/custom_script/custom_script.py b/core/doctype/custom_script/custom_script.py index 4f520bc9a7..a080dd0171 100644 --- a/core/doctype/custom_script/custom_script.py +++ b/core/doctype/custom_script/custom_script.py @@ -15,6 +15,26 @@ class DocType: if self.doc.script_type=="Server" and webnotes.session.user!="Administrator": webnotes.throw("Only Administrator is allowed to edit Server Script") + # fix indentation + tabs = None + for line in self.doc.script.split("\n"): + if line.strip(): + for i, char in enumerate(line): + if char=="\t": + tabs = "\t" + break + if char!=" ": + if i==0: + webnotes.throw("Custom Script must be indented by one tab") + tabs = " " * i + break + if tabs: + break + + self.doc.script = self.doc.script.replace(tabs, " ") + if not self.doc.script.startswith("\n"): + self.doc.script = "\n" + self.doc.script + def on_update(self): webnotes.clear_cache(doctype=self.doc.dt) webnotes.cache().delete_value("_server_script:" + self.doc.dt) diff --git a/public/css/common.css b/public/css/common.css index 0f7dca9710..a0c49d1e3c 100644 --- a/public/css/common.css +++ b/public/css/common.css @@ -178,59 +178,45 @@ div#freeze { width: 100%; } -.appframe .info-bar { - padding: 7px; - border-bottom: 1px solid #e7e7e7; - margin-left: -15px; - margin-right: -15px; +.appframe .mini-bar { + float: right; + margin-top: -10px; } -.appframe .info-bar { - padding: 7px; - height: 35px; +.appframe .mini-bar ul { + list-style: none; + margin: 0 0 0 0; + padding: 0 0 0 0; } -.appframe .info-bar .form-icon { +.appframe .mini-bar li { + display: inline-block; + padding-left: 4px; + padding-right: 4px; +} + +.appframe .mini-bar li:last-child { + padding-right: 0px; +} + +.appframe .mini-bar i { margin-top: 4px; margin-right: 4px; color: #888; cursor: pointer; } -.appframe .info-bar .form-icon:hover { +.appframe .mini-bar i:hover { color: #444; } -.appframe .info-bar .form-icon:active { +.appframe .mini-bar i:active { color: #5bc0de; } -.appframe .info-bar ul { - width: 80%; - list-style: none; - margin: 0 0 0 0; - padding: 0 0 0 0; -} - -.appframe .info-bar li { - font-size: 90%; - display: inline-block; - padding-left: 15px; - padding-right: 15px; -} - -.appframe .info-bar li a { - color: #999; - text-decoration: none; -} - -.appframe .info-bar li a:hover { - text-decoration: underline; -} - - -.appframe .info-bar li.bold a { +.appframe .mini-bar .appframe-mini-bar-active i { font-weight: bold; + color: orange; } .appframe .title-icon { diff --git a/public/js/legacy/form.js b/public/js/legacy/form.js index 810b3e9410..d7a549ee1a 100644 --- a/public/js/legacy/form.js +++ b/public/js/legacy/form.js @@ -703,6 +703,15 @@ _f.Frm.prototype.save = function(save_action, callback, btn, on_error) { on_error(); } callback && callback(r); + + if(wn._from_link) { + if(me.doctype===wn._from_link.df.options) { + wn._from_link.parse_validate_and_set_in_model(me.docname); + wn.set_route("Form", wn._from_link.frm.doctype, wn._from_link.frm.docname); + setTimeout(function() { scroll(0, wn._from_link_scrollY); }, 100); + } + wn._from_link = null; + } }, btn); } diff --git a/public/js/wn/form/control.js b/public/js/wn/form/control.js index 54028d383e..5991af24e5 100644 --- a/public/js/wn/form/control.js +++ b/public/js/wn/form/control.js @@ -737,7 +737,8 @@ wn.ui.form.ControlLink = wn.ui.form.ControlData.extend({ // new if(wn.model.can_create(me.df.options)) { this.$input_area.find(".btn-new").on("click", function() { - new_doc(me.df.options) + wn._from_link = me; wn._from_link_scrollY = scrollY; + new_doc(me.df.options); }); } else { this.$input_area.find(".btn-new").remove(); diff --git a/public/js/wn/form/footer.js b/public/js/wn/form/footer.js index a05dc51d6e..b353280be2 100644 --- a/public/js/wn/form/footer.js +++ b/public/js/wn/form/footer.js @@ -29,26 +29,26 @@ wn.ui.form.Footer = Class.extend({ \
\
\ -
\ -
'+wn._("Tags")+'
\ -
\ -

\
\
'+wn._("Comments")+'
\
\
\
\ +
\ +
'+wn._("Tags")+'
\ +
\ +

\
\
\ - '+wn._("Assigned To")+': \ - \
\

\
\
\ '+wn._("Attachments")+':\ - \
\
\ diff --git a/public/js/wn/form/infobar.js b/public/js/wn/form/infobar.js index fd1fd500ee..cf4be421c8 100644 --- a/public/js/wn/form/infobar.js +++ b/public/js/wn/form/infobar.js @@ -4,46 +4,83 @@ wn.ui.form.InfoBar = Class.extend({ init: function(opts) { $.extend(this, opts); + this.make(); this.refresh(); }, - refresh: function() { + make: function() { var me = this; - this.appframe.clear_infobar(); - if(this.frm.doc.__islocal) - return; - this.appframe.add_infobar( - wn.user.full_name(this.frm.doc.modified_by) + " / " + comment_when(this.frm.doc.modified), function() { - msgprint("Created By: " + wn.user.full_name(me.frm.doc.owner) + "
" + - "Created On: " + dateutil.str_to_user(me.frm.doc.creation) + "
" + - "Last Modified By: " + wn.user.full_name(me.frm.doc.modified_by) + "
" + - "Last Modifed On: " + dateutil.str_to_user(me.frm.doc.modified), "History"); - }) - this.make_links(); - this.make_side_icons(); - }, - make_links: function() { - - var me = this, - docinfo = wn.model.docinfo[this.frm.doctype][this.frm.docname], - comments = docinfo.comments.length, - attachments = keys(docinfo.attachments).length, - assignments = docinfo.assignments.length; - - var $li1 = this.appframe.add_infobar( - (comments ? ' ' : '') - + '' + comments + " " - + (comments===1 ? wn._("Comment") : wn._("Comments")) + '', - function() { - $('html, body').animate({ - scrollTop: $(me.frm.wrapper).find(".form-comments").offset().top - }, 2000); + this.$timestamp = this.appframe.add_to_mini_bar("icon-user", "Creation / Modified By", + function() { }) + + this.$comments = this.appframe.add_to_mini_bar("icon-comments", "Comments", function() { + me.scroll_to(".form-comments"); }); - if(comments) { - $li1.addClass("bold"); - var last = docinfo.comments[0]; - $li1.find(".comment-text") + this.$attachments = this.appframe.add_to_mini_bar("icon-paper-clip", "Attachments", function() { + me.scroll_to(".form-attachments"); + }); + + this.$assignments = this.appframe.add_to_mini_bar("icon-flag", "Assignments", function() { + me.scroll_to(".form-attachments"); + }); + + + this.$links = this.appframe.add_to_mini_bar("icon-link", "Linked With", + function() { me.frm.toolbar.show_linked_with(); }); + + if(!me.frm.meta.allow_print) { + this.$print = this.appframe.add_to_mini_bar("icon-print", "Print", + function() { me.frm.print_doc(); }); + } + + if(!me.frm.meta.allow_email) { + this.$print = this.appframe.add_to_mini_bar("icon-envelope", "Email", + function() { me.frm.email_doc(); }); + } + + if(!this.frm.meta.issingle) { + this.$prev = this.appframe.add_to_mini_bar("icon-arrow-left", "Previous Record", + function() { me.go_prev_next(true); }); + + this.$next = this.appframe.add_to_mini_bar("icon-arrow-right", "Next Record", + function() { me.go_prev_next(false); }); + } + + }, + + refresh: function() { + if(this.frm.doc.__islocal) { + this.appframe.hide_mini_bar(); + } else { + this.docinfo = wn.model.docinfo[this.frm.doctype][this.frm.docname]; + this.appframe.show_mini_bar(); + + // highlight comments + this.highlight_items(); + } + }, + + highlight_items: function() { + var me = this; + + this.$timestamp + .popover("destroy") + .popover({ + title: "Created and Modified By", + content: "Created By: " + wn.user.full_name(me.frm.doc.owner) + "
" + + "Created On: " + dateutil.str_to_user(me.frm.doc.creation) + "
" + + "Last Modified By: " + wn.user.full_name(me.frm.doc.modified_by) + "
" + + "Last Modifed On: " + dateutil.str_to_user(me.frm.doc.modified), + trigger:"hover", + html: true, + placement: "bottom" + }) + + if(this.docinfo.comments.length) { + var last = this.docinfo.comments[0]; + this.$comments + .popover("destroy") .popover({ title: "Last Comment", content: last.comment @@ -52,65 +89,25 @@ wn.ui.form.InfoBar = Class.extend({ + " / " + comment_when(last.creation) + '

', trigger:"hover", - html: true + html: true, + placement: "bottom" }); } - - - var $li2 = this.appframe.add_infobar(attachments + " " + (attachments===1 ? - wn._("Attachment") : wn._("Attachments")), - function() { - $('html, body').animate({ - scrollTop: $(me.frm.wrapper).find(".form-attachments").offset().top - }, 2000); - }); - attachments > 0 && $li2.addClass("bold"); - - var $li3 = this.appframe.add_infobar(assignments + " " + (assignments===1 ? - wn._("Assignment") : wn._("Assignments")), - function() { - $('html, body').animate({ - scrollTop: $(me.frm.wrapper).find(".form-assignments").offset().top - }, 2000); - }) - assignments > 0 && $li3.addClass("bold"); + $.each(["comments", "attachments", "assignments"], function(i, v) { + if(me.docinfo[v].length) + me["$" + v].addClass("appframe-mini-bar-active"); + else + me["$" + v].removeClass("appframe-mini-bar-active"); + }) }, - make_side_icons: function() { - var me = this; - this.appframe.$w.find(".form-icon").remove(); - if(!this.frm.meta.issingle) { - $('') - .click(function() { - me.go_prev_next(false); - }) - .appendTo(this.appframe.$w.find(".info-bar")); - - $('') - .click(function() { - me.go_prev_next(true); - }) - .appendTo(this.appframe.$w.find(".info-bar")); - } - - if(!me.frm.meta.allow_print) { - $('') - .click(function() { - me.frm.print_doc(); - }) - .appendTo(this.appframe.$w.find(".info-bar")); - } - - if(!me.frm.meta.allow_email) { - $('') - .click(function() { - me.frm.email_doc(); - }) - .appendTo(this.appframe.$w.find(".info-bar")); - } - + scroll_to: function(cls) { + $('html, body').animate({ + scrollTop: $(this.frm.wrapper).find(cls).offset().top + }, 1000); }, + go_prev_next: function(prev) { var me = this; return wn.call({ diff --git a/public/js/wn/form/toolbar.js b/public/js/wn/form/toolbar.js index b26b3d9a60..01dc1c6c9c 100644 --- a/public/js/wn/form/toolbar.js +++ b/public/js/wn/form/toolbar.js @@ -32,11 +32,11 @@ wn.ui.form.Toolbar = Class.extend({ this.make(); }, set_title: function() { - var title = this.frm.docname; + var title = wn._(this.frm.docname); if(title.length > 30) { title = title.substr(0,30) + "..."; } - this.appframe.set_title(title, wn._(this.frm.docname)); + this.appframe.set_title(title + this.get_lock_status(), wn._(this.frm.docname)); this.appframe.set_sub_title(wn._(this.frm.doctype)); }, show_infobar: function() { @@ -65,27 +65,18 @@ wn.ui.form.Toolbar = Class.extend({ get_dropdown_menu: function(label) { return this.appframe.add_dropdown(label); }, - set_docstatus_label: function() { - var status_bar_parent = this.frm.appframe.$w.find(".status-bar").empty(); + get_lock_status: function() { if(this.frm.meta.is_submittable && !this.frm.doc.__islocal) { - var status_bar = $("
") - .css({"margin": "0px", "margin-top": "-10px"}) - .appendTo(status_bar_parent); - switch(this.frm.doc.docstatus) { case 0: - $(' To Submit') - .appendTo(status_bar); - break; + return ' '; case 1: - $(' Submitted') - .appendTo(status_bar); - break; + return ' '; case 2: - $(' Cancelled') - .appendTo(status_bar); - break; + return ' '; } + } else { + return ""; } }, make_file_menu: function() { @@ -121,12 +112,7 @@ wn.ui.form.Toolbar = Class.extend({ // Linked With if(!me.frm.doc.__islocal && !me.frm.meta.issingle) { this.appframe.add_dropdown_button("File", wn._('Linked With'), function() { - if(!me.frm.linked_with) { - me.frm.linked_with = new wn.ui.form.LinkedWith({ - frm: me.frm - }); - } - me.frm.linked_with.show(); + me.show_linked_with(); }, "icon-link") } @@ -150,6 +136,14 @@ wn.ui.form.Toolbar = Class.extend({ } }, + show_linked_with: function() { + if(!this.frm.linked_with) { + this.frm.linked_with = new wn.ui.form.LinkedWith({ + frm: this.frm + }); + } + this.frm.linked_with.show(); + }, set_title_button: function() { var me = this; var docstatus = cint(this.frm.doc.docstatus); @@ -221,8 +215,8 @@ wn.ui.form.Toolbar = Class.extend({ this.appframe.get_title_area() .toggleClass("text-warning", this.frm.doc.__unsaved ? true : false); + this.set_title(); this.set_title_button(); - this.set_docstatus_label(); }, make_actions_menu: function() { if(this.actions_setup) return; diff --git a/public/js/wn/ui/appframe.js b/public/js/wn/ui/appframe.js index c9098c2096..699209faf4 100644 --- a/public/js/wn/ui/appframe.js +++ b/public/js/wn/ui/appframe.js @@ -20,11 +20,10 @@ wn.ui.AppFrame = Class.extend({ \
\
 
\ -
\ +
    \
    \
    \ \ - \
    ').prependTo(parent); this.$w.find('.close').click(function() { @@ -46,8 +45,9 @@ wn.ui.AppFrame = Class.extend({ return this.$w.find(".title-area"); }, set_title: function(txt, full_text) { + // strip icon this.title = txt; - document.title = txt; + document.title = txt.replace(/<[^>]*>/g, ""); this.$w.find(".breadcrumb .appframe-title").html(txt); this.$w.find(".title-text").html(txt); }, @@ -55,21 +55,26 @@ wn.ui.AppFrame = Class.extend({ this.$w.find(".sub-title-area").html(txt); }, - add_infobar: function(label, onclick) { - var $ul = this.$w.find(".info-bar").toggle(true).find("ul"), - $li = $('
  • ' + label + '
  • ') - .appendTo($ul) - .click(function() { - onclick(); - return false; - }) + add_to_mini_bar: function(icon, label, click) { + var $ul = this.$w.find(".mini-bar ul"), + $li = $('
  • ') + .attr("title", label) + .appendTo($ul) + .click(function() { + click(); + return false; + }) return $li; }, - clear_infobar: function() { - this.$w.find(".info-bar").toggle(false).find("ul").empty(); + hide_mini_bar: function() { + this.$w.find(".mini-bar").toggle(false); }, - + + show_mini_bar: function() { + this.$w.find(".mini-bar").toggle(true); + }, + add_module_icon: function(module, doctype, onclick) { var module_info = wn.modules[module]; if(!module_info) { diff --git a/webnotes/model/code.py b/webnotes/model/code.py index 01e7a1c1ef..fa9ae0dc64 100644 --- a/webnotes/model/code.py +++ b/webnotes/model/code.py @@ -18,16 +18,10 @@ methods in following modules are imported for backward compatibility custom_class = ''' import webnotes -from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, now, nowdate, set_default, user_format, validate_email_add -from webnotes.model import db_exists -from webnotes.model.doc import Document, addchild, getchildren -from webnotes.model.utils import getlist -from webnotes.utils.email_lib import sendmail -from webnotes.model.code import get_obj, get_server_obj, run_server_obj -from webnotes import session, form, msgprint, errprint - -sql = webnotes.conn.sql - +from webnotes.utils import cint, cstr, flt +from webnotes.model.doc import Document +from webnotes.model.code import get_obj +from webnotes import msgprint class CustomDocType(DocType): def __init__(self, doc, doclist): @@ -87,7 +81,7 @@ def get_server_obj(doc, doclist = [], basedoctype = ''): if custom_script: global custom_class - exec custom_class + custom_script.replace('\t',' ') in locals() + exec custom_class + '\n' + custom_script.replace('\t',' ') in locals() return CustomDocType(doc, doclist) else: diff --git a/website/doctype/blog_post/blog_post.txt b/website/doctype/blog_post/blog_post.txt index 79c1aee94f..fce379d84b 100644 --- a/website/doctype/blog_post/blog_post.txt +++ b/website/doctype/blog_post/blog_post.txt @@ -2,7 +2,7 @@ { "creation": "2013-03-28 10:35:30", "docstatus": 0, - "modified": "2013-07-05 15:08:30", + "modified": "2013-10-10 15:07:21", "modified_by": "Administrator", "owner": "Administrator" }, @@ -45,18 +45,18 @@ "label": "Title", "reqd": 1 }, - { - "doctype": "DocField", - "fieldname": "published", - "fieldtype": "Check", - "label": "Published" - }, { "doctype": "DocField", "fieldname": "published_on", "fieldtype": "Date", "label": "Published On" }, + { + "doctype": "DocField", + "fieldname": "published", + "fieldtype": "Check", + "label": "Published" + }, { "doctype": "DocField", "fieldname": "column_break_3", diff --git a/website/doctype/top_bar_item/top_bar_item.txt b/website/doctype/top_bar_item/top_bar_item.txt index 58d101e12a..7e2c4dc437 100644 --- a/website/doctype/top_bar_item/top_bar_item.txt +++ b/website/doctype/top_bar_item/top_bar_item.txt @@ -2,7 +2,7 @@ { "creation": "2013-02-22 01:28:08", "docstatus": 0, - "modified": "2013-07-10 14:54:25", + "modified": "2013-10-10 15:09:57", "modified_by": "Administrator", "owner": "Administrator" }, @@ -34,6 +34,14 @@ "width": "120px" }, { + "description": "If you set this, this Item will come in a drop-down under the selected parent.", + "doctype": "DocField", + "fieldname": "parent_label", + "fieldtype": "Select", + "label": "Parent Label" + }, + { + "description": "Link to the page you want to open", "doctype": "DocField", "fieldname": "url", "fieldtype": "Data", @@ -42,16 +50,11 @@ "width": "200px" }, { + "description": "Select target = \"_blank\" to open in a new page.", "doctype": "DocField", "fieldname": "target", "fieldtype": "Select", "label": "Target", "options": "\ntarget = \"_blank\"" - }, - { - "doctype": "DocField", - "fieldname": "parent_label", - "fieldtype": "Select", - "label": "Parent Label" } ] \ No newline at end of file