Sfoglia il codice sorgente

cleaned up item, fixed bug in dependency, removed legacy Listing, re-layed out DocField, refactored build.json for web, added featured_item and item_website_specification

version-14
Rushabh Mehta 12 anni fa
parent
commit
c89ead85c5
13 ha cambiato i file con 508 aggiunte e 1440 eliminazioni
  1. +255
    -354
      core/doctype/docfield/docfield.txt
  2. +7
    -2
      core/doctype/profile/profile.txt
  3. +6
    -9
      public/build.json
  4. +1
    -3
      public/js/legacy/widgets/form/form.js
  5. +0
    -131
      public/js/legacy/widgets/form/form_comments.js
  6. +5
    -8
      public/js/legacy/widgets/form/form_fields.js
  7. +2
    -2
      public/js/legacy/widgets/form/form_grid.js
  8. +0
    -694
      public/js/legacy/widgets/listing.js
  9. +0
    -4
      public/js/legacy/wn/widgets/form/comments.js
  10. +8
    -0
      public/js/wn/assets.js
  11. +0
    -8
      public/js/wn/misc/tools.js
  12. +0
    -225
      public/js/wn/views/doclistview.js
  13. +224
    -0
      public/js/wn/views/listview.js

+ 255
- 354
core/doctype/docfield/docfield.txt Vedi File

@@ -1,356 +1,257 @@
# DocType, DocField
[

# These values are common in all dictionaries
{
'creation': '2012-03-27 14:35:35',
'docstatus': 0,
'modified': '2012-03-27 18:23:58',
'modified_by': u'Administrator',
'owner': u'Administrator'
},

# These values are common for all DocType
{
'_last_update': u'1307624201',
'allow_copy': 0,
'allow_email': 0,
'allow_print': 0,
'autoname': u'FL.#####',
'colour': u'White:FFF',
'doctype': 'DocType',
'hide_heading': 0,
'hide_toolbar': 0,
'issingle': 0,
'istable': 1,
'module': u'Core',
'name': '__common__',
'read_only': 0,
'section_style': u'Simple',
'server_code_error': u' ',
'show_in_menu': 0,
'version': 6
},

# These values are common for all DocField
{
'doctype': u'DocField',
'name': '__common__',
'parent': u'DocField',
'parentfield': u'fields',
'parenttype': u'DocType',
'permlevel': 0
},

# These values are common for all DocPerm
{
'cancel': 0,
'create': 0,
'doctype': u'DocPerm',
'execute': 0,
'name': '__common__',
'parent': u'DocField',
'parentfield': u'permissions',
'parenttype': u'DocType',
'permlevel': 0,
'read': 0,
'role': u'Administrator',
'submit': 0,
'write': 0
},

# DocType, DocField
{
'doctype': 'DocType',
'name': u'DocField'
},

# DocPerm
{
'doctype': u'DocPerm'
},

# DocField
{
'doctype': u'DocField',
'fieldname': u'label',
'fieldtype': u'Data',
'hidden': 0,
'label': u'Label',
'oldfieldname': u'label',
'oldfieldtype': u'Data',
'reqd': 0,
'search_index': 1
},

# DocField
{
'doctype': u'DocField',
'fieldname': u'fieldtype',
'fieldtype': u'Select',
'hidden': 0,
'label': u'Type',
'oldfieldname': u'fieldtype',
'oldfieldtype': u'Select',
'options': u'Data\nSelect\nText\nSmall Text\nText Editor\nLink\nInt\nDate\nTime\nCurrency\nTable\nFloat\nCheck\nSection Break\nColumn Break\nButton\nRead Only\nCode\nHTML\nImage\nBlob\nPassword',
'reqd': 1,
'search_index': 1
},

# DocField
{
'doctype': u'DocField',
'fieldname': u'fieldname',
'fieldtype': u'Data',
'hidden': 0,
'label': u'Name',
'oldfieldname': u'fieldname',
'oldfieldtype': u'Data',
'reqd': 0,
'search_index': 1
},

# DocField
{
'description': u'For Links, enter the DocType as range\nFor Select, enter list of Options separated by comma',
'doctype': u'DocField',
'fieldname': u'options',
'fieldtype': u'Text',
'hidden': 0,
'label': u'Options',
'oldfieldname': u'options',
'oldfieldtype': u'Text',
'reqd': 0,
'search_index': 0
},

# DocField
{
'default': u'0',
'doctype': u'DocField',
'fieldname': u'permlevel',
'fieldtype': u'Int',
'hidden': 0,
'label': u'Perm Level',
'oldfieldname': u'permlevel',
'oldfieldtype': u'Int',
'reqd': 0,
'search_index': 0
},

# DocField
{
'doctype': u'DocField',
'fieldname': u'width',
'fieldtype': u'Data',
'hidden': 0,
'label': u'Width',
'oldfieldname': u'width',
'oldfieldtype': u'Data',
'reqd': 0,
'search_index': 0,
'width': u'50px'
},

# DocField
{
'doctype': u'DocField',
'fieldname': u'reqd',
'fieldtype': u'Check',
'hidden': 0,
'label': u'Reqd',
'oldfieldname': u'reqd',
'oldfieldtype': u'Check',
'reqd': 0,
'search_index': 0,
'width': u'50px'
},

# DocField
{
'doctype': u'DocField',
'fieldname': u'search_index',
'fieldtype': u'Check',
'hidden': 0,
'label': u'Index',
'oldfieldname': u'search_index',
'oldfieldtype': u'Check',
'reqd': 0,
'search_index': 0,
'width': u'50px'
},

# DocField
{
'doctype': u'DocField',
'fieldname': u'in_filter',
'fieldtype': u'Check',
'label': u'In Filter',
'oldfieldname': u'in_filter',
'oldfieldtype': u'Check',
'width': u'50px'
},

# DocField
{
'doctype': u'DocField',
'fieldname': u'hidden',
'fieldtype': u'Check',
'hidden': 0,
'label': u'Hidden',
'oldfieldname': u'hidden',
'oldfieldtype': u'Check',
'reqd': 0,
'search_index': 0,
'width': u'50px'
},

# DocField
{
'doctype': u'DocField',
'fieldname': u'no_column',
'fieldtype': u'Check',
'label': u'No Column'
},

# DocField
{
'doctype': u'DocField',
'fieldname': u'print_hide',
'fieldtype': u'Check',
'hidden': 0,
'label': u'Print Hide',
'oldfieldname': u'print_hide',
'oldfieldtype': u'Check',
'reqd': 0,
'search_index': 0
},

# DocField
{
'doctype': u'DocField',
'fieldname': u'no_copy',
'fieldtype': u'Check',
'label': u'No Copy',
'oldfieldname': u'no_copy',
'oldfieldtype': u'Check',
'width': u'50px'
},

# DocField
{
'colour': u'White:FFF',
'doctype': u'DocField',
'fieldname': u'report_hide',
'fieldtype': u'Check',
'label': u'Report Hide',
'oldfieldname': u'report_hide',
'oldfieldtype': u'Check'
},

# DocField
{
'doctype': u'DocField',
'fieldname': u'allow_on_submit',
'fieldtype': u'Check',
'label': u'Allow on Submit',
'oldfieldname': u'allow_on_submit',
'oldfieldtype': u'Check'
},

# DocField
{
'doctype': u'DocField',
'fieldname': u'depends_on',
'fieldtype': u'Data',
'label': u'Depends On',
'oldfieldname': u'depends_on',
'oldfieldtype': u'Data'
},

# DocField
{
'doctype': u'DocField',
'fieldname': u'description',
'fieldtype': u'Text',
'label': u'Description',
'oldfieldname': u'description',
'oldfieldtype': u'Text',
'width': u'300px'
},

# DocField
{
'doctype': u'DocField',
'fieldname': u'trigger',
'fieldtype': u'Select',
'hidden': 0,
'label': u'Trigger',
'oldfieldname': u'trigger',
'oldfieldtype': u'Select',
'options': u'\nClient\nServer',
'reqd': 0,
'search_index': 0
},

# DocField
{
'doctype': u'DocField',
'fieldname': u'default',
'fieldtype': u'Text',
'hidden': 0,
'label': u'Default',
'oldfieldname': u'default',
'oldfieldtype': u'Text',
'reqd': 0,
'search_index': 0
},

# DocField
{
'doctype': u'DocField',
'fieldname': u'colour',
'fieldtype': u'Select',
'hidden': 0,
'label': u'Colour',
'oldfieldname': u'colour',
'oldfieldtype': u'Select',
'options': u'White:FFF\nLight Blue:DEF\nLight Green:DFE\nPeach:FEF3C5\nPink:FEF2EA\nLilac:FDEAFE\nAqua:EAFEFA',
'reqd': 0,
'search_index': 0
},

# DocField
{
'doctype': u'DocField',
'fieldname': u'icon',
'fieldtype': u'Data',
'label': u'Icon',
'oldfieldname': u'icon',
'oldfieldtype': u'Data'
},

# DocField
{
'doctype': u'DocField',
'fieldname': u'oldfieldname',
'fieldtype': u'Data',
'hidden': 1,
'oldfieldname': u'oldfieldname',
'oldfieldtype': u'Data',
'reqd': 0,
'search_index': 0
},

# DocField
{
'doctype': u'DocField',
'fieldname': u'oldfieldtype',
'fieldtype': u'Data',
'hidden': 1,
'oldfieldname': u'oldfieldtype',
'oldfieldtype': u'Data',
'reqd': 0,
'search_index': 0
}
{
"owner": "Administrator",
"docstatus": 0,
"creation": "2012-11-30 18:13:32",
"modified_by": "Administrator",
"modified": "2012-12-07 15:09:55"
},
{
"istable": 1,
"allow_print": 0,
"module": "Core",
"autoname": "FL.#####",
"read_only": 0,
"allow_email": 0,
"hide_heading": 0,
"issingle": 0,
"name": "__common__",
"doctype": "DocType",
"hide_toolbar": 0,
"allow_copy": 0
},
{
"name": "__common__",
"parent": "DocField",
"doctype": "DocField",
"parenttype": "DocType",
"permlevel": 0,
"parentfield": "fields"
},
{
"parent": "DocField",
"read": 0,
"cancel": 0,
"execute": 0,
"name": "__common__",
"create": 0,
"doctype": "DocPerm",
"submit": 0,
"write": 0,
"parenttype": "DocType",
"role": "Administrator",
"permlevel": 0,
"parentfield": "permissions"
},
{
"name": "DocField",
"doctype": "DocType"
},
{
"oldfieldtype": "Data",
"doctype": "DocField",
"label": "Label",
"oldfieldname": "label",
"width": "163",
"fieldname": "label",
"fieldtype": "Data",
"search_index": 1,
"reqd": 0,
"hidden": 0
},
{
"oldfieldtype": "Select",
"doctype": "DocField",
"label": "Type",
"oldfieldname": "fieldtype",
"fieldname": "fieldtype",
"fieldtype": "Select",
"search_index": 1,
"reqd": 1,
"hidden": 0,
"options": "Data\nSelect\nText\nSmall Text\nText Editor\nLink\nInt\nDate\nTime\nCurrency\nTable\nFloat\nCheck\nSection Break\nColumn Break\nButton\nRead Only\nCode\nHTML\nImage\nBlob\nPassword"
},
{
"oldfieldtype": "Data",
"doctype": "DocField",
"label": "Name",
"oldfieldname": "fieldname",
"fieldname": "fieldname",
"fieldtype": "Data",
"search_index": 1,
"reqd": 0,
"hidden": 0
},
{
"description": "For Links, enter the DocType as range\nFor Select, enter list of Options separated by comma",
"oldfieldtype": "Text",
"doctype": "DocField",
"label": "Options",
"oldfieldname": "options",
"fieldname": "options",
"fieldtype": "Text",
"search_index": 0,
"reqd": 0,
"hidden": 0
},
{
"default": "0",
"oldfieldtype": "Int",
"doctype": "DocField",
"label": "Perm Level",
"oldfieldname": "permlevel",
"width": "50px",
"fieldname": "permlevel",
"fieldtype": "Int",
"search_index": 0,
"reqd": 0,
"hidden": 0
},
{
"oldfieldtype": "Data",
"doctype": "DocField",
"label": "Width",
"oldfieldname": "width",
"width": "50px",
"fieldname": "width",
"fieldtype": "Data",
"search_index": 0,
"reqd": 0,
"hidden": 0
},
{
"oldfieldtype": "Check",
"doctype": "DocField",
"label": "Reqd",
"oldfieldname": "reqd",
"width": "50px",
"fieldname": "reqd",
"fieldtype": "Check",
"search_index": 0,
"reqd": 0,
"hidden": 0
},
{
"oldfieldtype": "Text",
"doctype": "DocField",
"label": "Default",
"oldfieldname": "default",
"fieldname": "default",
"fieldtype": "Text",
"search_index": 0,
"reqd": 0,
"hidden": 0
},
{
"oldfieldtype": "Check",
"doctype": "DocField",
"label": "Hidden",
"oldfieldname": "hidden",
"width": "50px",
"fieldname": "hidden",
"fieldtype": "Check",
"search_index": 0,
"reqd": 0,
"hidden": 0
},
{
"oldfieldtype": "Data",
"doctype": "DocField",
"label": "Depends On",
"oldfieldname": "depends_on",
"fieldname": "depends_on",
"fieldtype": "Data"
},
{
"oldfieldtype": "Check",
"doctype": "DocField",
"label": "Print Hide",
"oldfieldname": "print_hide",
"width": "50px",
"fieldname": "print_hide",
"fieldtype": "Check",
"search_index": 0,
"reqd": 0,
"hidden": 0
},
{
"oldfieldtype": "Check",
"doctype": "DocField",
"label": "No Copy",
"oldfieldname": "no_copy",
"width": "50px",
"fieldname": "no_copy",
"fieldtype": "Check"
},
{
"oldfieldtype": "Check",
"doctype": "DocField",
"label": "Allow on Submit",
"oldfieldname": "allow_on_submit",
"width": "50px",
"fieldname": "allow_on_submit",
"fieldtype": "Check"
},
{
"oldfieldtype": "Check",
"doctype": "DocField",
"label": "In Filter",
"oldfieldname": "in_filter",
"width": "50px",
"fieldname": "in_filter",
"fieldtype": "Check"
},
{
"oldfieldtype": "Check",
"doctype": "DocField",
"label": "Report Hide",
"oldfieldname": "report_hide",
"width": "50px",
"fieldname": "report_hide",
"fieldtype": "Check"
},
{
"oldfieldtype": "Check",
"doctype": "DocField",
"label": "Index",
"oldfieldname": "search_index",
"width": "50px",
"fieldname": "search_index",
"fieldtype": "Check",
"search_index": 0,
"reqd": 0,
"hidden": 0
},
{
"oldfieldtype": "Text",
"doctype": "DocField",
"label": "Description",
"oldfieldname": "description",
"width": "300px",
"fieldname": "description",
"fieldtype": "Text"
},
{
"oldfieldtype": "Data",
"doctype": "DocField",
"oldfieldname": "oldfieldname",
"fieldname": "oldfieldname",
"fieldtype": "Data",
"search_index": 0,
"reqd": 0,
"hidden": 1
},
{
"oldfieldtype": "Data",
"doctype": "DocField",
"oldfieldname": "oldfieldtype",
"fieldname": "oldfieldtype",
"fieldtype": "Data",
"search_index": 0,
"reqd": 0,
"hidden": 1
},
{
"doctype": "DocPerm"
}
]

+ 7
- 2
core/doctype/profile/profile.txt Vedi File

@@ -2,9 +2,9 @@
{
"owner": "Administrator",
"docstatus": 0,
"creation": "2012-12-03 10:13:44",
"creation": "2012-12-06 15:56:49",
"modified_by": "Administrator",
"modified": "2012-12-03 11:38:56"
"modified": "2012-12-07 14:26:04"
},
{
"istable": 0,
@@ -278,6 +278,7 @@
"label": "Sync Inbox",
"fieldname": "sync_inbox",
"fieldtype": "Check",
"hidden": 1,
"permlevel": 0
},
{
@@ -287,6 +288,7 @@
"label": "Email Host",
"fieldname": "email_host",
"fieldtype": "Data",
"hidden": 1,
"permlevel": 0
},
{
@@ -294,6 +296,7 @@
"label": "Email Use SSL",
"fieldname": "email_use_ssl",
"fieldtype": "Check",
"hidden": 1,
"permlevel": 0
},
{
@@ -301,6 +304,7 @@
"label": "Email Login",
"fieldname": "email_login",
"fieldtype": "Data",
"hidden": 1,
"permlevel": 0
},
{
@@ -308,6 +312,7 @@
"label": "Email Password",
"fieldname": "email_password",
"fieldtype": "Password",
"hidden": 1,
"permlevel": 0
},
{


+ 6
- 9
public/build.json Vedi File

@@ -57,14 +57,12 @@
"lib/public/js/wn/model.js",
"lib/public/js/wn/perm.js",
"lib/public/js/wn/meta.js",
"lib/public/js/wn/misc/tools.js",
"lib/public/js/wn/misc/user.js",
"lib/public/js/wn/misc/utils.js",
"lib/public/js/lib/public/json2.js",
"lib/public/js/wn/router.js",
"lib/public/js/wn/ui/messages.js",
"lib/public/js/wn/ui/listing.js",
"lib/public/js/wn/ui/filters.js",
"lib/public/js/wn/views/container.js",
"lib/public/js/wn/views/pageview.js",
"lib/public/js/wn/request.js",
@@ -80,7 +78,6 @@
"lib/public/js/wn/ui/dialog.js",
"lib/public/js/wn/ui/button.js",
"lib/public/js/legacy/widgets/dialog.js",
"lib/public/js/legacy/webpage/page_header.js",
"lib/public/js/legacy/webpage/loaders.js",
"lib/public/js/legacy/model/local_data.js",
"lib/public/js/legacy/model/doclist.js",
@@ -100,22 +97,26 @@
"lib/public/js/lib/tiny_mce_3.5.7/jquery.tinymce.js:concat",
"lib/public/js/lib/mousetrap.min.js",
"lib/public/js/lib/sprintf.js",
"lib/public/js/wn/misc/tools.js",
"lib/public/js/legacy/utils/printElement.js",
"lib/public/js/legacy/widgets/form/fields.js",
"lib/public/js/wn/ui/field_group.js",
"lib/public/js/wn/ui/themes.js",
"lib/public/js/wn/ui/filters.js",
"lib/public/js/wn/ui/search.js",
"lib/public/js/wn/ui/tree.js",
"lib/public/js/wn/upload.js",
"lib/public/js/wn/misc/about.js",
"lib/public/js/wn/views/doclistview.js",
"lib/public/js/wn/views/listview.js",
"lib/public/js/wn/views/formview.js",
"lib/public/js/wn/form/formatters.js",
"lib/public/js/wn/views/load_reportview.js",
"lib/public/js/wn/views/reportview.js",
"lib/public/js/wn/views/grid_report.js",
"lib/public/js/wn/views/communication.js",
"lib/public/js/legacy/webpage/page_header.js",
"lib/public/js/legacy/widgets/layout.js",
"lib/public/js/legacy/widgets/tags.js",
"lib/public/js/legacy/widgets/export_query.js",
@@ -168,11 +169,7 @@

{
"public/css/fields.css": ["lib/public/css/legacy/fields.css"]
},

{
"public/js/listing.js": ["lib/public/js/legacy/widgets/listing.js"]
},
}

]


+ 1
- 3
public/js/legacy/widgets/form/form.js Vedi File

@@ -725,9 +725,7 @@ _f.Frm.prototype.refresh_dependency = function() {
} else if(f.df.depends_on.substr(0,3)=='fn:') {
f.guardian_has_value = me.runclientscript(f.df.depends_on.substr(3), me.doctype, me.docname);
} else {
if(v || (v==0 && !v.substr)) {
// guardian has value
} else {
if(!v) {
f.guardian_has_value = false;
}
}


+ 0
- 131
public/js/legacy/widgets/form/form_comments.js Vedi File

@@ -75,135 +75,4 @@ wn.widgets.form.comments = {
f.comment_list[dn]
);
}
}

// Comment Listing
// ===============
CommentList = function(parent, dt, dn) {
this.wrapper = $a(parent, 'div', '', {margin:'16px'});
this.input_area = $a(this.wrapper, 'div', '', {margin:'2px'});
this.lst_area = $a(this.wrapper, 'div', '', {margin:'2px'});
this.make_input();
this.make_lst();
this.dt;
this.dn;
}

CommentList.prototype.run = function() {
this.lst.run();
}

CommentList.prototype.make_input = function() {
var me = this;
// make the input text area and button
this.input = $a(this.input_area, 'textarea', '', {height:'60px', width:'300px', fontSize:'14px'});
this.btn = $btn($a(this.input_area, 'div'), 'Post', function() {me.add_comment();},{marginTop:'8px'});
}

// Add comment listing
// --------------------
CommentList.prototype.add_comment = function() {
var me = this;
var callback = function(input, dt, dn) {
me.lst.run();
}
wn.widgets.form.comments.add(this.input, cur_frm.docname, cur_frm.doctype, callback)
}

// Make comment listing
// --------------------
CommentList.prototype.make_lst = function() {
if(!this.lst) {
wn.require('js/listing.js');
var l = new Listing('Comments', 1);
var me = this;
// define the columns etc
l.colwidths = ['100%'];

// define options
l.opts.hide_export = 1; l.opts.hide_print = 1; l.opts.hide_refresh = 1; l.opts.no_border = 1;
l.opts.hide_rec_label = 0; l.opts.show_calc = 0; l.opts.round_corners = 0;
l.opts.alt_cell_style = {};
l.opts.cell_style = {padding:'3px'};
l.no_rec_message = 'No comments yet. Be the first one to comment!';
l.get_query = function(){
//---------------------- 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
this.query = repl("select t1.name, t1.comment, t1.comment_by, '', \
t1.creation, t1.comment_doctype, t1.comment_docname, \
ifnull(concat_ws(' ',ifnull(t2.first_name,''),ifnull(t2.middle_name,''),\
ifnull(t2.last_name,'')),''), '', \
DAYOFMONTH(t1.creation), MONTHNAME(t1.creation), YEAR(t1.creation), \
hour(t1.creation), minute(t1.creation), second(t1.creation) \
from `tabComment` t1, `tabProfile` t2 \
where t1.comment_doctype = '%(dt)s' and t1.comment_docname = '%(dn)s' \
and t1.comment_by = t2.name order by t1.creation desc",{dt:me.dt, dn:me.dn});
this.query_max = repl("select count(name) from `tabComment` where \
comment_doctype='%(dt)s' and comment_docname='%(dn)s'",{'dt': me.dt, 'dn': me.dn});
}

l.show_cell = function(cell, ri, ci, d){
new CommentItem(cell, ri, ci, d, me)
}
this.lst = l;
this.lst.make(this.lst_area);

}
}

// Comment Item
//=============
CommentItem = function(cell, ri, ci, d, comment) {
this.comment = comment;
$y(cell, {padding:'4px 0px'})
var t = make_table(cell, 1, 3, '100%', ['15%', '65%', '20%'], {padding:'4px'});
// image
this.img = $a($td(t,0,0), 'img', '', {width:'40px'});
this.cmt_by = $a($td(t,0,0), 'div');
this.set_picture(d, ri);

// comment
this.cmt_dtl = $a($td(t,0,1), 'div', 'comment', {fontSize:'11px'});
this.cmt = $a($td(t,0,1), 'div','',{fontSize:'14px'});
this.show_cmt($td(t,0,1), ri, ci, d);

this.cmt_delete($td(t,0,2), ri, ci, d);
}
// Set picture
// -----------
CommentItem.prototype.set_picture = function(d, ri){
this.user.src = wn.user_info(d[ri][2]).image;
this.cmt_by.innerHTML = d[ri][7] ? d[ri][7] : d[ri][2];
}

// Set comment details
// -------------------
CommentItem.prototype.show_cmt = function(cell, ri, ci, d) {
//time and date of comment
if(d[ri][4]){
hr = d[ri][12]; min = d[ri][13]; sec = d[ri][14];
if(parseInt(hr) > 12) { time = (parseInt(hr)-12) + ':' + min + ' PM' }
else{ time = hr + ':' + min + ' AM'}
}
this.cmt_dtl.innerHTML = 'On ' + d[ri][10].substring(0,3) + ' ' + d[ri][9] + ', ' + d[ri][11] + ' at ' + time;
this.cmt.innerHTML = replace_newlines(d[ri][1]);
}

// Set delete button
// -----------------
CommentItem.prototype.cmt_delete = function(cell, ri, ci, d) {
var me = this;
if(d[ri][2] == user || d[ri][3] == user) {
del = $a(cell,'i','icon-remove-sign',{cursor:'pointer'});
del.cmt_id = d[ri][0];
del.onclick = function(){
wn.widgets.form.comments.remove(cur_frm.doctype, cur_frm.docname, this.cmt_id,
function() { me.comment.lst.run(); })
}
}
}

+ 5
- 8
public/js/legacy/widgets/form/form_fields.js Vedi File

@@ -181,13 +181,14 @@ _f.TableField.prototype = new Field();
_f.TableField.prototype.with_label = 0;
_f.TableField.prototype.make_body = function() {
if(this.perm[this.df.permlevel] && this.perm[this.df.permlevel][READ]) {
this.wrapper = $("<div>").appendTo(this.parent).get(0);
this.grid = new _f.FormGrid(this);
if(this.frm)this.frm.grids[this.frm.grids.length] = this;
this.grid.make_buttons();
// description
if(this.df.description) {
this.desc_area = $a(this.parent, 'div', 'help small',
this.desc_area = $a(this.wrapper, 'div', 'help small',
{marginBottom:'9px', marginTop:'0px'}, this.df.description)
}
}
@@ -231,17 +232,13 @@ _f.TableField.prototype.refresh = function() {
}
}
//if(this.old_status!=st) {
if(st=='Write') {
// nothing
this.grid.show();
} else if(st=='Read') {
if(st=='Write' || st=="Read") {
$(this.wrapper).toggle(true);
this.grid.show();
} else {
$(this.wrapper).toggle(false);
this.grid.hide();
}
// this.old_status = st; // save this if next time
//}

this.grid.refresh();
}


+ 2
- 2
public/js/legacy/widgets/form/form_grid.js Vedi File

@@ -31,8 +31,8 @@ _f.FormGrid = function(field) {
this.col_break_width = cint(this.field.col_break_width);
if(!this.col_break_width) this.col_break_width = 100;
$y(field.parent,{marginTop:'8px'});
this.init(field.parent, field.df.width);
$y(field.wrapper,{marginTop:'8px'});
this.init(field.wrapper, field.df.width);
this.setup();
}



+ 0
- 694
public/js/legacy/widgets/listing.js Vedi File

@@ -1,694 +0,0 @@
// Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
//
// MIT License (MIT)
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

// Listing
// this listing object will soon be
// deprecated because it has a very non standard way of creation
// the new listing object is at wn.ui.Listing
// -----------------------

list_opts = {
cell_style : {padding:'3px 2px'},
alt_cell_style : {},
head_style : {height:'20px',overflow:'hidden',verticalAlign:'middle',fontWeight:'bold',padding:'1px',fontSize:'13px'},
head_main_style : {padding:'0px'},
hide_export : 1,
hide_print : 1,
hide_refresh : 0,
hide_rec_label: 0,
show_calc: 1,
show_empty_tab : 0,
no_border: 1,
append_records: 1,
table_width: null
};

// -------------------------------------------------------

function Listing(head_text, no_index, no_loading) {
this.start = 0;
this.page_len = 20;
this.filters_per_line = 7;
this.cell_idx = 0;
this.head_text = head_text ? head_text : 'Result';
this.keyword = 'records';
this.no_index = no_index;
this.underline = 1;
this.no_rec_message = 'No Result';
// interfaces
// show_cell(cell, cell_id, data) - override cell display
// show_result()
// server_call(srs, call_back) - override query function

this.show_cell = null;
this.show_result = null;
this.colnames = null; // sr num is required
this.colwidths = null;
this.coltypes = null;
this.coloptions = null;
this.filters = {};
this.sort_list = {};
this.sort_order_dict = {};
this.sort_heads = {};
this.is_std_query = false;
this.server_call = null;
this.no_loading = no_loading;
this.opts = copy_dict(list_opts);
}

// -------------------------------------------------------

Listing.prototype.make = function(parent) {
var me = this;
this.wrapper = parent;
// filter
this.filter_wrapper = $a(parent, 'div', 'srs_filter_wrapper');
this.filter_area = $a(this.filter_wrapper, 'div', 'srs_filter_area');
$dh(this.filter_wrapper);

this.btn_area = $a(parent, 'div', '', {margin:'8px 0px'});
this.body_area = $a(parent,'div','srs_body_area');

if(!this.opts.hide_rec_label)
this.rec_label = $a(this.body_area, 'div', '', {margin:'4px 0px',color:'#888'});

// results
this.results = $a($a(this.body_area, 'div','srs_results_area'),'div');
this.fetching_area = $a(this.body_area, 'div','',{height:'120px', background:'url("lib/images/ui/square_loading.gif") center no-repeat', display:'none'});
this.show_no_records = $a(this.body_area,'div','',{margin:'200px 0px', textAlign:'center', fontSize:'14px', color:'#888', display:'none'});
this.show_no_records.innerHTML = 'No Result';

// empty table (old style)
if(this.opts.show_empty_tab)
this.make_result_tab();
this.bottom_div = $a(this.body_area,'div','',{paddingTop:'8px'});
this.make_toolbar();
}

// -------------------------------------------------------

Listing.prototype.make_toolbar = function() {
var me = this;
this.buttons = {};

// buttons
var make_btn = function(label,icon,onclick,bold) {
var btn = $btn(me.btn_area,label,onclick,{marginRight:'4px'});
if(bold)$y(btn,{fontWeight: 'bold'});
me.buttons[label] = btn;
}
// refresh btn
if(!this.opts.hide_refresh) {
make_btn('Refresh','ui-icon-refresh',function(btn) {
me.start = 0;
me.run();
},1);
}

// new
if(this.opts.show_new) {
make_btn('New ','ui-icon-document',function() { new_doc(me.dt); },1);
}

// report
if(this.opts.show_report) {
make_btn('Report Builder','ui-icon-clipboard',function() { loadreport(me.dt, null, null, null, 1); },0);
}
// export
if(!this.opts.hide_export) {
make_btn('Export','ui-icon-circle-arrow-e',function() {me.do_export();});
}

// calc
if(this.opts.show_calc) {
make_btn('Calc','ui-icon-calculator',function() {me.do_calc();});
$dh(me.buttons['Calc'])
}
this.loading_img = $a(this.btn_area,'img','',{display:'none',marginBottom:'-2px'});
this.loading_img.src = 'lib/images/ui/button-load.gif';
if(!keys(this.buttons).length)
$dh(this.btn_area);
}

Listing.prototype.do_calc = function() {
show_calc(this.result_tab, this.colnames, this.coltypes, 0)
}

// -------------------------------------------------------

Listing.prototype.add_filter = function(label, ftype, options, tname, fname, cond) {
if(!this.filter_area){alert('[Listing] make() must be called before add_filter');}
var me = this;

// create filter area
if(!this.filter_set) {
// actual area
var h = $a(this.filter_area, 'div', '', {fontSize:'14px', fontWeight:'bold', marginBottom:'4px'});
h.innerHTML = 'Filter your search';
this.filter_area.div = $a(this.filter_area, 'div');
this.perm = [[1,1],]
this.filters = {};
}
$ds(this.filter_wrapper);

// create new table (or new line)
if((!this.inp_tab) || (this.cell_idx==this.filters_per_line)) {
this.inp_tab = $a(this.filter_area.div, 'table','',{width:'100%', tableLayout:'fixed'});
this.inp_tab.insertRow(0);
for(var i=0;i<this.filters_per_line;i++) {
this.inp_tab.rows[0].insertCell(i);
}
this.cell_idx = 0;
}

var c= this.inp_tab.rows[0].cells[this.cell_idx];
this.cell_idx++;
$y(c,{width:cint(100/this.filters_per_line) + '%',textAlign:'left',verticalAlign:'top'});
// filter label
var d1= $a(c,'div','',{fontSize:'11px', marginBottom:'2px'}); d1.innerHTML = label;
if(ftype=='Link') d1.innerHTML += ' <img src="lib/images/icons/link.png" style="margin-bottom:-5px" title="Link">';
var d2= $a(c,'div');
// create the filter
if(in_list(['Text', 'Small Text', 'Code', 'Text Editor','Read Only'],ftype))
ftype='Data';
// add empty option in select (if missing)
if(ftype=='Select' && !in_list(options.split('\n'), '')) options = '\n'+options
var inp = make_field({fieldtype:ftype, 'label':label, 'options':options, no_buttons:1}, '', d2, this, 0, 1);
inp.not_in_form = 1;
inp.report = this;

// filter style
inp.df.single_select = 1;
inp.parent_cell = c;
inp.parent_tab = this.input_tab;
$y(inp.wrapper,{width:'95%'});
inp.refresh();
//if(!inp.input.custom_select && !inp.input.txt)
// $y(inp.input,{width:'100%'});
inp.tn = tname; inp.fn = fname; inp.condition = ftype=='Data' ? 'like' : cond;
var me = this;
inp.onchange = function() { me.start = 0; }
this.filters[label] = inp;
this.filter_set = 1;
}

// -------------------------------------------------------

Listing.prototype.remove_filter = function(label) {
var inp = this.filters[label];
inp.parent_tab.rows[0].deleteCell(inp.parent_cell.cellIndex);
delete this.filters[label];
}

// -------------------------------------------------------

Listing.prototype.remove_all_filters = function() {
for(var k in this.filters) this.remove_filter(k);
$dh(this.filter_wrapper);
}

Listing.prototype.add_sort = function(ci, fname) { this.sort_list[ci]=fname; }
Listing.prototype.has_data = function() { return this.n_records; }

// -------------------------------------------------------

Listing.prototype.set_default_sort = function(fname, sort_order) {
this.sort_order = sort_order;
this.sort_order_dict[fname] = sort_order;
this.sort_by = fname;
if(this.sort_heads[fname])
this.sort_heads[fname].set_sorting_as(sort_order);
}

// -------------------------------------------------------

Listing.prototype.set_sort = function(cell, ci, fname) {
var me = this;
$y(cell.sort_cell,{width:'18px'});

cell.sort_img = $a(cell.sort_cell, 'img');
cell.fname = fname;
$dh(cell.sort_img);

cell.set_sort_img = function(order) {
var t = 'images/icons/sort_desc.gif';
if(order=='ASC') {
t = 'images/icons/sort_asc.gif';
}
this.sort_img.src = t;
}

cell.set_sorting_as = function(order) {
// set values for query building
me.sort_order = order;
me.sort_by = this.fname
me.sort_order_dict[this.fname] = order;

// set the image
this.set_sort_img(order)
// deselect active
if(me.cur_sort) {
$y(me.cur_sort, {backgroundColor:"#FFF"});
$dh(me.cur_sort.sort_img);
}
// set at active
me.cur_sort = this;
$y(this, {backgroundColor:"#DDF"});
$di(this.sort_img);
}

$y(cell.label_cell,{color:'#44A',cursor:'pointer'});

// set default image
cell.set_sort_img(me.sort_order_dict[fname] ? me.sort_order_dict[fname] : 'ASC');
cell.onmouseover = function() {
$di(this.sort_img);
}
cell.onmouseout = function() {
if(this != me.cur_sort)
$dh(this.sort_img);
}
cell.onclick = function() {
// switch
this.set_sorting_as((me.sort_order_dict[fname]=='ASC') ? 'DESC' : 'ASC');
// run
me.run();
}
this.sort_heads[fname] = cell;
}

// -------------------------------------------------------

Listing.prototype.do_export = function() {
this.build_query();
var me = this;
me.cn = [];
if(this.no_index)
me.cn = this.colnames; // No index
else {
for(var i=1;i<this.colnames.length;i++)
me.cn.push(this.colnames[i]); // Ignore the SR label
}
var q = export_query(this.query,
function(query) {
export_csv(query, me.head_text, null, 1, null, me.cn);
});
}

// -------------------------------------------------------

Listing.prototype.build_query = function() {
if(this.get_query)this.get_query(this);
if(!this.query) { alert('No Query!'); return; }

if(!this.prefix) this.prefix = 'tab';

// add filters
var cond = [];
for(var i in this.filters) {
var f = this.filters[i];
var val = f.get_value();
var c = f.condition;
if(!c)c='=';
if(val && c.toLowerCase()=='like')val += '%';
if(f.tn && val && !in_list(['All','Select...',''],val))
cond.push(repl(' AND `%(prefix)s%(dt)s`.%(fn)s %(condition)s "%(val)s"', {
prefix: this.prefix, dt:f.tn, fn:f.fn, condition:c, val:val}));
}

if(cond) {
this.query += NEWLINE + cond.join(NEWLINE)
if(this.query_max)
this.query_max += NEWLINE + cond.join(NEWLINE)
}

// add grouping
if(this.group_by)
this.query += ' ' + this.group_by + ' ';

// add sorting
if(this.sort_by && this.sort_order) {
this.query += NEWLINE + ' ORDER BY `' + this.sort_by + '` ' + this.sort_order;
}
if(this.show_query) msgprint(this.query);
}

// -------------------------------------------------------

Listing.prototype.set_rec_label = function(total, cur_page_len) {
if(this.opts.hide_rec_label)
return;
else if(total==-1)
this.rec_label.innerHTML = 'Fetching...'
else if(total > 0)
this.rec_label.innerHTML = repl('Total %(total)s %(keyword)s. Showing %(start)s to %(end)s', {total:total,start:cint(this.start)+1,end:cint(this.start)+cint(cur_page_len), keyword:this.keyword});
else if(total==null)
this.rec_label.innerHTML = ''
else if(total==0)
this.rec_label.innerHTML = this.no_rec_message;
}

// -------------------------------------------------------

Listing.prototype.run = function(run_callback) {
this.build_query();
var q = this.query;
var me = this;

// add limits
if(this.max_len && this.start>=this.max_len) this.start-= this.page_len;
q += ' LIMIT ' + this.start + ',' + this.page_len;
// callback
var call_back = function(r,rt) {
$dh(me.loading_img);
// show results
me.max_len = r.n_values;
// result!
if(r.values && r.values.length) {
me.n_records = r.values.length;
var nc = r.values[0].length;
if(me.colwidths) nc = me.colwidths.length-(me.no_index?0:1); // -1 for sr no

// redraw table
if(me.opts.append_records && me.start!=0) {
// add columns
me.append_rows(r.values.length);
} else {
me.clear_tab();
if(!me.show_empty_tab) {
me.remove_result_tab();
me.make_result_tab(r.values.length);
}
}
me.refresh(r.values.length, nc, r.values, r.n_values);
me.total_records = r.n_values;
me.set_rec_label(r.n_values, r.values.length);
// no result
} else {
me.n_records = 0;
me.set_rec_label(0);
me.clear_tab();
if(!me.opts.append_records) {
if(me.show_empty_tab) {
me.clear_tab();
} else {
me.remove_result_tab();
me.make_result_tab(0);
if(me.opts.show_no_records_label) {
$ds(me.show_no_records);
}
}
}
}
$ds(me.results);
if(run_callback)run_callback();
if(me.onrun) me.onrun();
}
// run
$dh(me.show_no_records);
this.set_rec_label(-1);
$di(this.loading_img);
if(this.server_call) {
this.server_call(this, call_back);
} else {
args={ query_max: (this.query_max ? this.query_max : '') }
if(this.is_std_query) args.query = q;
else args.simple_query = q;
if(this.opts.formatted) args.formatted = 1;
$c('webnotes.widgets.query_builder.runquery', args, call_back, null, this.no_loading);
}
}

// -------------------------------------------------------

Listing.prototype.remove_result_tab = function() {
if(!this.result_tab) return;
this.result_tab.parentNode.removeChild(this.result_tab);
delete this.result_tab;
}

// -------------------------------------------------------

Listing.prototype.reset_tab = function() {
this.remove_result_tab();
this.make_result_tab();
}

// -------------------------------------------------------

Listing.prototype.make_result_tab = function(nr) {
if(this.result_tab)return;
if(!this.colwidths) alert("Listing: Must specify column widths");
var has_headrow = this.colnames ? 1 : 0;
if(nr==null)nr = this.page_len;
nr += has_headrow;
var nc = this.colwidths.length;
var t=make_table(this.results, nr, nc, (this.opts.table_width ? this.opts.table_width : '100%'), this.colwidths,{padding:'0px'});
t.className = 'srs_result_tab'; this.result_tab = t;
$y(t,{borderCollapse:'collapse'});

if(this.opts.table_width) {
$y(this.results, {overflowX:'auto'});
$y(t,{tableLayout:'fixed'});
}

// display headings
if(has_headrow) {
this.make_headings(t,nr,nc);
// hilight sorted cell
if(this.sort_by && this.sort_heads[this.sort_by]) {
this.sort_heads[this.sort_by].set_sorting_as(this.sort_order);
}
}
// style
this.set_table_style();

if(this.opts.no_border == 1) {
$y(t,{border:'0px'});
}

this.result_tab = t;
}

// -------------------------------------------------------

Listing.prototype.set_table_style = function() {
// set style
var t = this.result_tab;
for(var ri=(this.colnames?1:0); ri<t.rows.length; ri++) {
for(var ci=0; ci<t.rows[ri].cells.length; ci++) {
// default style
if(this.opts.cell_style)$y($td(t,ri,ci), this.opts.cell_style);
// color alternate rows (itunes style)
if(this.opts.alt_cell_style && (ri % 2))$y($td(t,ri,ci), this.opts.alt_cell_style);
// show blank empty cells
if(this.opts.show_empty_tab && !$td(t, ri, ci).innerHTML)$td(t, ri, ci).innerHTML = '&nbsp;';
}
}
}

// -------------------------------------------------------

Listing.prototype.append_rows = function(nr) {
for(var i=0; i<nr; i++) { append_row(this.result_tab); }
this.set_table_style();
}

// -------------------------------------------------------

Listing.prototype.clear_tab = function() {
$dh(this.results);
if(this.result_tab) {
var nr = this.result_tab.rows.length;
var nc = this.result_tab.rows[0].cells.length;
for(var ri=(this.colnames?1:0); ri<nr; ri++)
for(var ci=0; ci < nc; ci++)
$td(this.result_tab, ri, ci).innerHTML = (this.opts.show_empty_tab ? '&nbsp;' : '');
}
}

// -------------------------------------------------------

Listing.prototype.clear = function() {
this.rec_label.innerHTML = '';
this.clear_tab();
}

// -------------------------------------------------------


Listing.prototype.refresh_calc = function() {
if(!this.opts.show_calc) return;
if(has_common(this.coltypes, ['Currency','Int','Float'])) {
$di(this.buttons['Calc']);
} else {
$dh(this.buttons['Calc']);
}
}

// -------------------------------------------------------


Listing.prototype.refresh = function(nr, nc, d, n_values) {

this.refresh_more_button(nr, n_values);
this.refresh_calc();
if(this.show_result)
this.show_result();
else {
if(nr) {
// Standard Result Display
var start = this.result_tab.rows.length - nr;
// display results
for(var ri=start ; ri<start+nr ; ri++) {
var c0 = $td(this.result_tab,ri,0);
// show index
if(!this.no_index) {
c0.innerHTML = cint(this.start) + cint(ri-start) + 1;
}
// columns
for(var ci=0 ; ci<nc ; ci++) {
var c = $td(this.result_tab, ri, ci+(this.no_index?0:1));
if(c) {
c.innerHTML = ''; // clear
if(this.show_cell) this.show_cell(c, ri-start, ci, d);
else this.std_cell(c, ri-start, ci, d);
}
}
}
}
}
}
// -------------------------------------------------------

Listing.prototype.refresh_more_button = function(nr, n_values) {
var me = this;
if(this.more_btn) {
$dh(this.more_btn);
}
if((this.start + nr) == this.max_len || (!this.max_len && nr < this.page_len)) {
// all records shown
} else if(nr) {
if(!this.more_btn) {

// make button
$y(this.bottom_div, {margin:'8px 0px 16px 0px', textAlign:'center'});
this.more_btn = $btn(this.bottom_div, 'Show more results...',
function() {
me.start = me.start + me.page_len;
me.more_btn.set_working();
me.run(function() { me.more_btn.done_working(); });
}, {fontSize:'14px'}, 0, 1);
$y(this.more_btn.loading_img, {marginBottom:'0px'});
}
$di(this.more_btn);
}
}

// -------------------------------------------------------

Listing.prototype.make_headings = function(t,nr,nc) {
for(var ci=0 ; ci<nc ; ci++) {
var tmp = make_table($td(t,0,ci),1,2,'100%',['','0px'],this.opts.head_style);
$y(tmp,{tableLayout:'fixed',borderCollapse:'collapse'});
$y($td(t,0,ci),this.opts.head_main_style); // right border on main table
$td(t,0,ci).sort_cell = $td(tmp,0,1);
$td(t,0,ci).label_cell = $td(tmp,0,0);
$td(tmp,0,1).style.padding = '0px';
$td(tmp,0,0).innerHTML = this.colnames[ci]?this.colnames[ci]:'&nbsp;';
if(this.sort_list[ci])this.set_sort($td(t,0,ci), ci, this.sort_list[ci]);
var div = $a($td(t,0,ci), 'div');
$td(t,0,ci).style.borderBottom ='1px solid #CCC';
if(this.coltypes && this.coltypes[ci] && in_list(['Currency','Float','Int'], this.coltypes[ci])) $y($td(t,0,ci).label_cell,{textAlign:'right'})
}
}

// -------------------------------------------------------

Listing.prototype.std_cell = function(cell, ri, ci, d) {
var has_headrow = this.colnames ? 1 : 0;
cell.div = $a(cell, 'div');
$s(
cell.div,
d[ri][ci],
this.coltypes ? this.coltypes[ci+(this.no_index?0:1)] : null,
this.coloptions ? this.coloptions[ci+(this.no_index?0:1)] : null
);
}

+ 0
- 4
public/js/legacy/wn/widgets/form/comments.js Vedi File

@@ -75,10 +75,6 @@ wn.widgets.form.sidebar.Comments = function(parent, sidebar, doctype, docname) {

if(cl) {
this.msg.innerHTML = cl.length + ' out of ' + f.n_comments[me.docname] + ' comments';
if(f.n_comments[me.docname] > cl.length) {
this.msg.innerHTML += ' <span class="link_type" \
onclick="cur_frm.show_comments()">Show all</span>'
}
for(var i=0; i< cl.length; i++) {
this.render_one_comment(cl[i]);
}


+ 8
- 0
public/js/wn/assets.js Vedi File

@@ -131,3 +131,11 @@ wn.assets = {
}
}
}

wn.markdown = function(txt) {
if(!wn.md2html) {
wn.require('lib/js/lib/showdown.js');
wn.md2html = new Showdown.converter();
}
return wn.md2html.makeHtml(txt);
}

+ 0
- 8
public/js/wn/misc/tools.js Vedi File

@@ -1,11 +1,3 @@
wn.markdown = function(txt) {
if(!wn.md2html) {
wn.require('lib/js/lib/showdown.js');
wn.md2html = new Showdown.converter();
}
return wn.md2html.makeHtml(txt);
}

wn.downloadify = function(data, roles, me) {
if(roles && roles.length && !has_common(roles, user_roles)) {
msgprint("Export not allowed. You need " + wn.utils.comma_or(roles)


+ 0
- 225
public/js/wn/views/doclistview.js Vedi File

@@ -375,229 +375,4 @@ wn.views.DocListView = wn.ui.Listing.extend({
}
this.run();
}
});

wn.views.ListView = Class.extend({
init: function(doclistview) {
this.doclistview = doclistview;
this.doctype = doclistview.doctype;
var t = "`tab"+this.doctype+"`.";
this.fields = [t + 'name', t + 'owner', t + 'docstatus',
t + '_user_tags', t + 'modified'];
this.stats = ['_user_tags'];
this.show_hide_check_column();

},
columns: [
{width: '3%', content:'check'},
{width: '4%', content:'avatar'},
{width: '3%', content:'docstatus', css: {"text-align": "center"}},
{width: '35%', content:'name'},
{width: '40%', content:'tags', css: {'color':'#aaa'}},
{width: '15%', content:'modified', css: {'text-align': 'right', 'color':'#222'}}
],
render_column: function(data, parent, opts) {
var me = this;
// style
if(opts.css) {
$.each(opts.css, function(k, v) { $(parent).css(k, v)});
}
// multiple content
if(opts.content.indexOf && opts.content.indexOf('+')!=-1) {
$.map(opts.content.split('+'), function(v) {
me.render_column(data, parent, {content:v});
});
return;
}
// content
if(typeof opts.content=='function') {
opts.content(parent, data, me);
}
else if(opts.content=='name') {
$(parent).append(repl('<a href="#!Form/%(doctype)s/%(name)s">%(name)s</a>', data));
}
else if(opts.content=='avatar') {
$(parent).append(repl('<span class="avatar avatar avatar-small"><img src="%(avatar)s" \
title="Created By: %(fullname)s"/></span>',
data));
}
else if(opts.content=='avatar_modified') {
$(parent).append(repl('<span class="avatar avatar avatar-small">\
<img src="%(avatar_modified)s" \
title="Last Updated By: %(fullname_modified)s"/></span>',
data));
}
else if(opts.content=='check') {
$(parent).append('<input class="list-delete" type="checkbox">');
$(parent).find('input').data('name', data.name);
}
else if(opts.content=='docstatus') {
$(parent).append(repl('<span class="docstatus"><i class="%(docstatus_icon)s" \
title="%(docstatus_title)s"></i></span>', data));
}
else if(opts.content=='tags') {
this.add_user_tags(parent, data);
}
else if(opts.content=='modified') {
$(parent).append(data.when);
}
else if(opts.type=='bar-graph') {
this.render_bar_graph(parent, data, opts.content, opts.label);
}
else if(opts.type=='link' && opts.doctype) {
$(parent).append(repl('<a href="#!Form/'+opts.doctype+'/'
+data[opts.content]+'">'+data[opts.content]+'</a>', data));
}
else if(opts.template) {
$(parent).append(repl(opts.template, data));
}
else if(data[opts.content]) {
if(opts.type=="date") {
data[opts.content] = wn.datetime.str_to_user(data[opts.content])
}
$(parent).append(repl('<span title="%(title)s"> %(content)s</span>', {
"title": opts.title || opts.content, "content": data[opts.content]}));
}
},
render: function(row, data) {
var me = this;
this.prepare_data(data);
rowhtml = '';
// make table
$.each(this.columns, function(i, v) {
if(v.content && v.content.substr && v.content.substr(0,6)=="avatar") {
rowhtml += repl('<td style="width: 40px;"></td>');
} else {
rowhtml += repl('<td style="width: %(width)s"></td>', v);
}
});
var tr = $(row).html('<table class="doclist-row"><tbody><tr>' + rowhtml + '</tr></tbody></table>').find('tr').get(0);
// render cells
$.each(this.columns, function(i, v) {
me.render_column(data, tr.cells[i], v);
});
},
prepare_data: function(data) {
data.fullname = wn.user_info(data.owner).fullname;
data.avatar = wn.user_info(data.owner).image;

data.fullname_modified = wn.user_info(data.modified_by).fullname;
data.avatar_modified = wn.user_info(data.modified_by).image;
if(data.modified)
this.prepare_when(data, data.modified);
// docstatus
if(data.docstatus==0 || data.docstatus==null) {
data.docstatus_icon = 'icon-pencil';
data.docstatus_title = 'Editable';
} else if(data.docstatus==1) {
data.docstatus_icon = 'icon-lock';
data.docstatus_title = 'Submitted';
} else if(data.docstatus==2) {
data.docstatus_icon = 'icon-remove';
data.docstatus_title = 'Cancelled';
}
// nulls as strings
for(key in data) {
if(data[key]==null) {
data[key]='';
}
}
},
prepare_when: function(data, date_str) {
if (!date_str) date_str = data.modified;
// when
data.when = (dateutil.str_to_user(date_str)).split(' ')[0];
var diff = dateutil.get_diff(dateutil.get_today(), date_str.split(' ')[0]);
if(diff==0) {
data.when = dateutil.comment_when(date_str);
}
if(diff == 1) {
data.when = 'Yesterday'
}
if(diff == 2) {
data.when = '2 days ago'
}
},
add_user_tags: function(parent, data) {
var me = this;
if(data._user_tags) {
if($(parent).html().length > 0) {
$(parent).append('<br />');
}
$.each(data._user_tags.split(','), function(i, t) {
if(t) {
$('<span class="label label-info" style="cursor: pointer; line-height: 200%">'
+ strip(t) + '</span>')
.click(function() {
me.doclistview.set_filter('_user_tags', $(this).text())
})
.appendTo(parent);
}
});
}
},
show_hide_check_column: function() {
if(!this.doclistview.can_delete) {
this.columns = $.map(this.columns, function(v, i) { if(v.content!='check') return v });
}
},
render_bar_graph: function(parent, data, field, label) {
var args = {
percent: data[field],
fully_delivered: (data[field] > 99 ? 'bar-complete' : ''),
label: label
}
$(parent).append(repl('<span class="bar-outer" style="width: 30px; float: right" \
title="%(percent)s% %(label)s">\
<span class="bar-inner %(fully_delivered)s" \
style="width: %(percent)s%;"></span>\
</span>', args));
},
render_icon: function(parent, icon_class, label) {
var icon_html = "<i class='%(icon_class)s' title='%(label)s'></i>";
$(parent).append(repl(icon_html, {icon_class: icon_class, label: label || ''}));
}
});

wn.provide('wn.views.RecordListView');
wn.views.RecordListView = wn.views.DocListView.extend({
init: function(doctype, wrapper, ListView) {
this.doctype = doctype;
this.wrapper = wrapper;
this.listview = new ListView(this);
this.listview.parent = this;
this.setup();
},

setup: function() {
var me = this;
me.page_length = 10;

$(me.wrapper).empty();

me.init_list();
},

get_args: function() {
var args = this._super();
$.each((this.default_filters || []), function(i, f) {
args.filters.push(f);
});
args.docstatus = args.docstatus.concat((this.default_docstatus || []));
return args;
},
});

+ 224
- 0
public/js/wn/views/listview.js Vedi File

@@ -0,0 +1,224 @@
wn.views.ListView = Class.extend({
init: function(doclistview) {
this.doclistview = doclistview;
this.doctype = doclistview.doctype;
var t = "`tab"+this.doctype+"`.";
this.fields = [t + 'name', t + 'owner', t + 'docstatus',
t + '_user_tags', t + 'modified'];
this.stats = ['_user_tags'];
this.show_hide_check_column();

},
columns: [
{width: '3%', content:'check'},
{width: '4%', content:'avatar'},
{width: '3%', content:'docstatus', css: {"text-align": "center"}},
{width: '35%', content:'name'},
{width: '40%', content:'tags', css: {'color':'#aaa'}},
{width: '15%', content:'modified', css: {'text-align': 'right', 'color':'#222'}}
],
render_column: function(data, parent, opts) {
var me = this;
// style
if(opts.css) {
$.each(opts.css, function(k, v) { $(parent).css(k, v)});
}
// multiple content
if(opts.content.indexOf && opts.content.indexOf('+')!=-1) {
$.map(opts.content.split('+'), function(v) {
me.render_column(data, parent, {content:v});
});
return;
}
// content
if(typeof opts.content=='function') {
opts.content(parent, data, me);
}
else if(opts.content=='name') {
$(parent).append(repl('<a href="#!Form/%(doctype)s/%(name)s">%(name)s</a>', data));
}
else if(opts.content=='avatar') {
$(parent).append(repl('<span class="avatar avatar avatar-small"><img src="%(avatar)s" \
title="Created By: %(fullname)s"/></span>',
data));
}
else if(opts.content=='avatar_modified') {
$(parent).append(repl('<span class="avatar avatar avatar-small">\
<img src="%(avatar_modified)s" \
title="Last Updated By: %(fullname_modified)s"/></span>',
data));
}
else if(opts.content=='check') {
$(parent).append('<input class="list-delete" type="checkbox">');
$(parent).find('input').data('name', data.name);
}
else if(opts.content=='docstatus') {
$(parent).append(repl('<span class="docstatus"><i class="%(docstatus_icon)s" \
title="%(docstatus_title)s"></i></span>', data));
}
else if(opts.content=='tags') {
this.add_user_tags(parent, data);
}
else if(opts.content=='modified') {
$(parent).append(data.when);
}
else if(opts.type=='bar-graph') {
this.render_bar_graph(parent, data, opts.content, opts.label);
}
else if(opts.type=='link' && opts.doctype) {
$(parent).append(repl('<a href="#!Form/'+opts.doctype+'/'
+data[opts.content]+'">'+data[opts.content]+'</a>', data));
}
else if(opts.template) {
$(parent).append(repl(opts.template, data));
}
else if(data[opts.content]) {
if(opts.type=="date") {
data[opts.content] = wn.datetime.str_to_user(data[opts.content])
}
$(parent).append(repl('<span title="%(title)s"> %(content)s</span>', {
"title": opts.title || opts.content, "content": data[opts.content]}));
}
},
render: function(row, data) {
var me = this;
this.prepare_data(data);
rowhtml = '';
// make table
$.each(this.columns, function(i, v) {
if(v.content && v.content.substr && v.content.substr(0,6)=="avatar") {
rowhtml += repl('<td style="width: 40px;"></td>');
} else {
rowhtml += repl('<td style="width: %(width)s"></td>', v);
}
});
var tr = $(row).html('<table class="doclist-row"><tbody><tr>' + rowhtml + '</tr></tbody></table>').find('tr').get(0);
// render cells
$.each(this.columns, function(i, v) {
me.render_column(data, tr.cells[i], v);
});
},
prepare_data: function(data) {
data.fullname = wn.user_info(data.owner).fullname;
data.avatar = wn.user_info(data.owner).image;

data.fullname_modified = wn.user_info(data.modified_by).fullname;
data.avatar_modified = wn.user_info(data.modified_by).image;
if(data.modified)
this.prepare_when(data, data.modified);
// docstatus
if(data.docstatus==0 || data.docstatus==null) {
data.docstatus_icon = 'icon-pencil';
data.docstatus_title = 'Editable';
} else if(data.docstatus==1) {
data.docstatus_icon = 'icon-lock';
data.docstatus_title = 'Submitted';
} else if(data.docstatus==2) {
data.docstatus_icon = 'icon-remove';
data.docstatus_title = 'Cancelled';
}
// nulls as strings
for(key in data) {
if(data[key]==null) {
data[key]='';
}
}
},
prepare_when: function(data, date_str) {
if (!date_str) date_str = data.modified;
// when
data.when = (dateutil.str_to_user(date_str)).split(' ')[0];
var diff = dateutil.get_diff(dateutil.get_today(), date_str.split(' ')[0]);
if(diff==0) {
data.when = dateutil.comment_when(date_str);
}
if(diff == 1) {
data.when = 'Yesterday'
}
if(diff == 2) {
data.when = '2 days ago'
}
},
add_user_tags: function(parent, data) {
var me = this;
if(data._user_tags) {
if($(parent).html().length > 0) {
$(parent).append('<br />');
}
$.each(data._user_tags.split(','), function(i, t) {
if(t) {
$('<span class="label label-info" style="cursor: pointer; line-height: 200%">'
+ strip(t) + '</span>')
.click(function() {
me.doclistview.set_filter('_user_tags', $(this).text())
})
.appendTo(parent);
}
});
}
},
show_hide_check_column: function() {
if(!this.doclistview.can_delete) {
this.columns = $.map(this.columns, function(v, i) { if(v.content!='check') return v });
}
},
render_bar_graph: function(parent, data, field, label) {
var args = {
percent: data[field],
fully_delivered: (data[field] > 99 ? 'bar-complete' : ''),
label: label
}
$(parent).append(repl('<span class="bar-outer" style="width: 30px; float: right" \
title="%(percent)s% %(label)s">\
<span class="bar-inner %(fully_delivered)s" \
style="width: %(percent)s%;"></span>\
</span>', args));
},
render_icon: function(parent, icon_class, label) {
var icon_html = "<i class='%(icon_class)s' title='%(label)s'></i>";
$(parent).append(repl(icon_html, {icon_class: icon_class, label: label || ''}));
}
});

wn.provide('wn.views.RecordListView');
wn.views.RecordListView = wn.views.DocListView.extend({
init: function(doctype, wrapper, ListView) {
this.doctype = doctype;
this.wrapper = wrapper;
this.listview = new ListView(this);
this.listview.parent = this;
this.setup();
},

setup: function() {
var me = this;
me.page_length = 10;

$(me.wrapper).empty();

me.init_list();
},

get_args: function() {
var args = this._super();
$.each((this.default_filters || []), function(i, f) {
args.filters.push(f);
});
args.docstatus = args.docstatus.concat((this.default_docstatus || []));
return args;
},
});

Caricamento…
Annulla
Salva