micro-templates, refactor, fix

This commit is contained in:
Rushabh Mehta 2014-07-28 18:12:41 +05:30 committed by Anand Doshi
parent 3d21b88ccc
commit 63306511ad
6 changed files with 37 additions and 11 deletions

View file

@ -895,7 +895,7 @@ html {
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
body {
font-family: "Noto Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
line-height: 1.42857143;
color: #333;

View file

@ -1,3 +1,5 @@
@import url(http://fonts.googleapis.com/css?family=Open+Sans:400,700);
html {
min-height: 100%;
position: relative;

View file

@ -274,7 +274,8 @@ frappe.ui.form.GridRow = Class.extend({
if(this.grid.template) {
$('<div class="col-xs-10">').appendTo(this.row)
.html(frappe.render(this.grid.template, {doc:this.doc, frm:this.frm, grid_row: this}));
.html(frappe.render(this.grid.template, {
doc:this.doc || null, frm:this.frm, row: this}));
} else {
this.add_visible_columns();
}
@ -315,7 +316,7 @@ frappe.ui.form.GridRow = Class.extend({
var df = this.static_display_template[ci][0];
var colsize = this.static_display_template[ci][1];
var txt = this.doc ?
frappe.format(this.doc[df.fieldname], df, null, this.doc) :
this.get_formatted(df.fieldname) :
__(df.label);
if(this.doc && df.fieldtype === "Select") {
txt = __(txt);
@ -455,11 +456,12 @@ frappe.ui.form.GridRow = Class.extend({
frm: this.frm,
});
this.layout.make();
this.layout.refresh(this.doc);
this.fields = this.layout.fields;
this.fields_dict = this.layout.fields_dict;
this.layout.refresh(this.doc);
// copy get_query to fields
$.each(this.grid.fieldinfo || {}, function(fieldname, fi) {
$.extend(me.fields_dict[fieldname], fi);
@ -538,8 +540,7 @@ frappe.ui.form.GridRow = Class.extend({
refresh_field: function(fieldname) {
var $col = this.row.find("[data-fieldname='"+fieldname+"']");
if($col.length) {
var value = frappe.model.get_value(this.doc.doctype, this.doc.name, fieldname);
$col.html(frappe.format(value, $col.data("df"), null, this.doc));
$col.html(this.get_formatted(fieldname));
}
// in form
@ -547,4 +548,9 @@ frappe.ui.form.GridRow = Class.extend({
this.fields_dict[fieldname].refresh();
}
},
get_formatted: function(fieldname) {
var df = frappe.meta.get_docfield(this.grid.doctype, fieldname, this.frm.docname);
return frappe.format(this.doc[fieldname], df, null, this.doc);
},
});

View file

@ -268,3 +268,9 @@ _f.Frm.prototype.set_read_only = function() {
});
cur_frm.perm = perm;
}
_f.Frm.prototype.get_formatted = function(fieldname) {
return frappe.format(this.doc[fieldname],
frappe.meta.get_docfield(this.doctype, fieldname, this.docname),
{no_icon:true}, this.doc);
}

View file

@ -19,12 +19,21 @@ frappe.template.compile = function(str) {
.replace(/((^|%})[^\t]*)'/g, "$1\r")
.replace(/\t=(.*?)%}/g, "',$1,'")
.split("\t").join("');")
.split("%}").join("p.push('")
.split("%}").join("\np.push('")
.split("\r").join("\\'")
+ "');}return p.join('');";
frappe.template.debug[str] = fn_str;
frappe.template.compiled[str] = new Function("obj", fn_str);
try {
frappe.template.compiled[str] = new Function("obj", fn_str);
} catch (e) {
console.log("Error in Template:");
console.log(fn_str);
if(e.lineNumber) {
console.log("Error in Line 9, Col 11:");
console.log(fn_str.split("\n")[8]);
}
}
}
return frappe.template.compiled[str];

View file

@ -8,12 +8,15 @@ Built on Frappe.io. Free and Open Source Framework for the Web. https://frappe.i
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ title }}</title>
<meta name="generator" content="frappe">
<script type="text/javascript" src="/assets/frappe/js/lib/jquery/jquery.min.js"></script>
<script type="text/javascript"
src="/assets/frappe/js/lib/jquery/jquery.min.js"></script>
<link rel="shortcut icon"
href="{{ favicon or "/assets/frappe/images/favicon.ico" }}" type="image/x-icon">
href="{{ favicon or "/assets/frappe/images/favicon.ico" }}"
type="image/x-icon">
<link rel="icon"
href="{{ favicon or "/assets/frappe/images/favicon.ico" }}" type="image/x-icon">
href="{{ favicon or "/assets/frappe/images/favicon.ico" }}"
type="image/x-icon">
{%- block head_include %}{% endblock -%}
{%- block head -%}
{% if meta_block is defined %}