From c89ead85c5603b33d9ad896c8df88acd02e385e9 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Fri, 7 Dec 2012 15:47:32 +0530 Subject: [PATCH] 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 --- core/doctype/docfield/docfield.txt | 609 +++++++-------- core/doctype/profile/profile.txt | 9 +- public/build.json | 15 +- public/js/legacy/widgets/form/form.js | 4 +- .../js/legacy/widgets/form/form_comments.js | 131 ---- public/js/legacy/widgets/form/form_fields.js | 13 +- public/js/legacy/widgets/form/form_grid.js | 4 +- public/js/legacy/widgets/listing.js | 694 ------------------ public/js/legacy/wn/widgets/form/comments.js | 4 - public/js/wn/assets.js | 8 + public/js/wn/misc/tools.js | 8 - public/js/wn/views/doclistview.js | 225 ------ public/js/wn/views/listview.js | 224 ++++++ 13 files changed, 508 insertions(+), 1440 deletions(-) delete mode 100644 public/js/legacy/widgets/listing.js create mode 100644 public/js/wn/views/listview.js diff --git a/core/doctype/docfield/docfield.txt b/core/doctype/docfield/docfield.txt index 961d6c001a..a6a8783550 100644 --- a/core/doctype/docfield/docfield.txt +++ b/core/doctype/docfield/docfield.txt @@ -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" + } ] \ No newline at end of file diff --git a/core/doctype/profile/profile.txt b/core/doctype/profile/profile.txt index bf2209bb21..7e19841eb7 100644 --- a/core/doctype/profile/profile.txt +++ b/core/doctype/profile/profile.txt @@ -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 }, { diff --git a/public/build.json b/public/build.json index 00eab1c0bc..bd343f984d 100644 --- a/public/build.json +++ b/public/build.json @@ -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"] - }, + } ] diff --git a/public/js/legacy/widgets/form/form.js b/public/js/legacy/widgets/form/form.js index 0c31690a40..e591f6eab5 100644 --- a/public/js/legacy/widgets/form/form.js +++ b/public/js/legacy/widgets/form/form.js @@ -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; } } diff --git a/public/js/legacy/widgets/form/form_comments.js b/public/js/legacy/widgets/form/form_comments.js index 16257ad9e9..56bf6a24d2 100644 --- a/public/js/legacy/widgets/form/form_comments.js +++ b/public/js/legacy/widgets/form/form_comments.js @@ -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(); }) - } - } } \ No newline at end of file diff --git a/public/js/legacy/widgets/form/form_fields.js b/public/js/legacy/widgets/form/form_fields.js index 5ea2be24f8..fe336e3cc9 100644 --- a/public/js/legacy/widgets/form/form_fields.js +++ b/public/js/legacy/widgets/form/form_fields.js @@ -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 = $("
").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(); } diff --git a/public/js/legacy/widgets/form/form_grid.js b/public/js/legacy/widgets/form/form_grid.js index 148da1d46b..b28b903bb4 100644 --- a/public/js/legacy/widgets/form/form_grid.js +++ b/public/js/legacy/widgets/form/form_grid.js @@ -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(); } diff --git a/public/js/legacy/widgets/listing.js b/public/js/legacy/widgets/listing.js deleted file mode 100644 index 9c1ce5b02b..0000000000 --- a/public/js/legacy/widgets/listing.js +++ /dev/null @@ -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 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 cl.length) { - this.msg.innerHTML += ' Show all' - } for(var i=0; i< cl.length; i++) { this.render_one_comment(cl[i]); } diff --git a/public/js/wn/assets.js b/public/js/wn/assets.js index b7129a6adb..559ae232a8 100644 --- a/public/js/wn/assets.js +++ b/public/js/wn/assets.js @@ -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); +} diff --git a/public/js/wn/misc/tools.js b/public/js/wn/misc/tools.js index 4df2da1758..2ecbeee6ef 100644 --- a/public/js/wn/misc/tools.js +++ b/public/js/wn/misc/tools.js @@ -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) diff --git a/public/js/wn/views/doclistview.js b/public/js/wn/views/doclistview.js index 30050b9dae..99c645710f 100644 --- a/public/js/wn/views/doclistview.js +++ b/public/js/wn/views/doclistview.js @@ -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('%(name)s', data)); - } - else if(opts.content=='avatar') { - $(parent).append(repl('', - data)); - } - else if(opts.content=='avatar_modified') { - $(parent).append(repl('\ - ', - data)); - } - else if(opts.content=='check') { - $(parent).append(''); - $(parent).find('input').data('name', data.name); - } - else if(opts.content=='docstatus') { - $(parent).append(repl('', 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(''+data[opts.content]+'', 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(' %(content)s', { - "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(''); - } else { - rowhtml += repl('', v); - } - }); - var tr = $(row).html('' + rowhtml + '
').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('
'); - } - $.each(data._user_tags.split(','), function(i, t) { - if(t) { - $('' - + strip(t) + '') - .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('\ - \ - ', args)); - }, - render_icon: function(parent, icon_class, label) { - var icon_html = ""; - $(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; - }, }); \ No newline at end of file diff --git a/public/js/wn/views/listview.js b/public/js/wn/views/listview.js new file mode 100644 index 0000000000..4132d315cf --- /dev/null +++ b/public/js/wn/views/listview.js @@ -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('%(name)s', data)); + } + else if(opts.content=='avatar') { + $(parent).append(repl('', + data)); + } + else if(opts.content=='avatar_modified') { + $(parent).append(repl('\ + ', + data)); + } + else if(opts.content=='check') { + $(parent).append(''); + $(parent).find('input').data('name', data.name); + } + else if(opts.content=='docstatus') { + $(parent).append(repl('', 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(''+data[opts.content]+'', 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(' %(content)s', { + "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(''); + } else { + rowhtml += repl('', v); + } + }); + var tr = $(row).html('' + rowhtml + '
').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('
'); + } + $.each(data._user_tags.split(','), function(i, t) { + if(t) { + $('' + + strip(t) + '') + .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('\ + \ + ', args)); + }, + render_icon: function(parent, icon_class, label) { + var icon_html = ""; + $(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; + }, +}); \ No newline at end of file