Merge branch 'wsgi' of github.com:webnotes/wnframework into wsgi

This commit is contained in:
Anand Doshi 2013-10-10 16:05:06 +05:30
commit c0ea5ecc2c
11 changed files with 203 additions and 194 deletions

View file

@ -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)

View file

@ -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 {

View file

@ -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);
}

View file

@ -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();

View file

@ -29,26 +29,26 @@ wn.ui.form.Footer = Class.extend({
</div>\
<div class="after-save">\
<div class="col-md-8">\
<div class="form-tags">\
<h5 style="display: inline-block"><i class="icon-tag"></i> '+wn._("Tags")+'</h5>\
<span class="tag-area"></span><br>\
</div><hr>\
<div class="form-comments">\
<h5><i class="icon-comments"></i> '+wn._("Comments")+'</h5>\
</div>\
</div>\
<div class="col-md-4">\
<div class="form-tags">\
<h5 style="display: inline-block"><i class="icon-tag"></i> '+wn._("Tags")+'</h5>\
<span class="tag-area"></span><br>\
</div><hr>\
<div class="form-assignments" style="margin-bottom: 7px;">\
<h5>\
<i class="icon-ok-sign"></i> '+wn._("Assigned To")+': \
<button class="btn btn-small btn-default pull-right"\
<i class="icon-flag"></i> '+wn._("Assigned To")+': \
<button class="btn small btn-default pull-right"\
style="margin-top:-7px;">'+wn._("Add")+'</button>\
</h5>\
</div><hr>\
<div class="form-attachments">\
<h5>\
<i class="icon-paper-clip"></i> '+wn._("Attachments")+':\
<button class="btn btn-small btn-default pull-right"\
<button class="btn small btn-default pull-right"\
style="margin-top:-7px;">'+wn._("Add")+'</button>\
</h5>\
</div>\

View file

@ -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) + "<br>" +
"Created On: " + dateutil.str_to_user(me.frm.doc.creation) + "<br>" +
"Last Modified By: " + wn.user.full_name(me.frm.doc.modified_by) + "<br>" +
"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 ? '<i class="icon-comments" style="font-size: 120%; color: orange"></i> ' : '')
+ '<span class="comment-text">' + comments + " "
+ (comments===1 ? wn._("Comment") : wn._("Comments")) + '</span>',
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) + "<br>" +
"Created On: " + dateutil.str_to_user(me.frm.doc.creation) + "<br>" +
"Last Modified By: " + wn.user.full_name(me.frm.doc.modified_by) + "<br>" +
"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)
+ '</p>',
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) {
$('<i class="icon-arrow-right pull-right form-icon" title="Next Record"></i>')
.click(function() {
me.go_prev_next(false);
})
.appendTo(this.appframe.$w.find(".info-bar"));
$('<i class="icon-arrow-left pull-right form-icon" title="Previous Record"></i>')
.click(function() {
me.go_prev_next(true);
})
.appendTo(this.appframe.$w.find(".info-bar"));
}
if(!me.frm.meta.allow_print) {
$('<i class="icon-print pull-right form-icon" title="Print"></i>')
.click(function() {
me.frm.print_doc();
})
.appendTo(this.appframe.$w.find(".info-bar"));
}
if(!me.frm.meta.allow_email) {
$('<i class="icon-envelope pull-right form-icon" title="Email"></i>')
.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({

View file

@ -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 = $("<div>")
.css({"margin": "0px", "margin-top": "-10px"})
.appendTo(status_bar_parent);
switch(this.frm.doc.docstatus) {
case 0:
$('<span class="label label-default"><i class="icon-unlock"> To Submit</span>')
.appendTo(status_bar);
break;
return ' <i class="icon-unlock text-muted" title="Not Submitted">';
case 1:
$('<span class="label label-success"><i class="icon-lock"> Submitted</span>')
.appendTo(status_bar);
break;
return ' <i class="icon-lock text-muted" title="Submitted">';
case 2:
$('<span class="label label-danger"><i class="icon-remove"> Cancelled</span>')
.appendTo(status_bar);
break;
return ' <i class="icon-remove text-muted" title="Cancelled">';
}
} 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;

View file

@ -20,11 +20,10 @@ wn.ui.AppFrame = Class.extend({
<span class="title-icon" style="display: none"></span>\
<span class="title-text"></span></h2></div>\
<div class="sub-title-area text-muted small">&nbsp;</div>\
<div class="status-bar"></div>\
<div class="mini-bar"><ul></ul></div>\
</div>\
</div>\
<div class="appframe-toolbar" style="display: none;"></div>\
<div class="info-bar" style="display: none;"><ul class="hidden-xs-inline"></ul></div>\
<div>').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 = $('<li><a href="#">' + label + '</a></li>')
.appendTo($ul)
.click(function() {
onclick();
return false;
})
add_to_mini_bar: function(icon, label, click) {
var $ul = this.$w.find(".mini-bar ul"),
$li = $('<li><i class="'+icon+'"></i></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) {

View file

@ -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:

View file

@ -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",

View file

@ -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"
}
]