Browse Source

[minor] fix blog post route and formatter for item, employee

version-14
Rushabh Mehta 9 years ago
parent
commit
1a8d8c90aa
5 changed files with 32 additions and 3 deletions
  1. +0
    -0
      frappe/docs/user/en/guides/desk/__init__.py
  2. +17
    -0
      frappe/docs/user/en/guides/desk/formatter_for_link_fields.md
  3. +5
    -0
      frappe/docs/user/en/guides/desk/index.md
  4. +9
    -2
      frappe/public/js/frappe/form/formatters.js
  5. +1
    -1
      frappe/website/doctype/blog_post/blog_post.py

+ 0
- 0
frappe/docs/user/en/guides/desk/__init__.py View File


+ 17
- 0
frappe/docs/user/en/guides/desk/formatter_for_link_fields.md View File

@@ -0,0 +1,17 @@
In case where a code and a name is maintained for an entity, (for example for Employee there may be an Employee Code and Employee Name) and we want to show both the ID and name in a link field, we can make a formatter.

#### Example:

frappe.form.link_formatters['Employee'] = function(value, doc) {
if(doc.employee_name && doc.employee_name !== value) {
return value + ': ' + doc.employee_name;
} else {
return value;
}
}

Notes:

1. Both the primary key (`name) and the descriptive name (e.g. `employee_name`) must be present in the document. The descriptive name field could be hidden
1. This needs to be loaded before the document is loaded and can be re-used for all forms. You can also add it in `build.json`


+ 5
- 0
frappe/docs/user/en/guides/desk/index.md View File

@@ -0,0 +1,5 @@
# Desk Customization

Articles related to customization of Frappe Desk

{index}

+ 9
- 2
frappe/public/js/frappe/form/formatters.js View File

@@ -5,6 +5,8 @@

frappe.provide("frappe.form.formatters");

frappe.form.link_formatters = {};

frappe.form.formatters = {
_right: function(value, options) {
if(options && options.inline) {
@@ -60,11 +62,16 @@ frappe.form.formatters = {
return '<i class="icon-ban-circle text-extra-muted" style="margin-right: 3px;"></i>';
}
},
Link: function(value, docfield, options) {
Link: function(value, docfield, options, doc) {
var doctype = docfield._options || docfield.options;
if(value && value.match(/^['"].*['"]$/)) {
return value.replace(/^.(.*).$/, "$1");
value.replace(/^.(.*).$/, "$1");
}

if(frappe.form.link_formatters[doctype]) {
value = frappe.form.link_formatters[doctype](value, doc);
}

if(options && options.for_print) {
return value;
}


+ 1
- 1
frappe/website/doctype/blog_post/blog_post.py View File

@@ -21,7 +21,7 @@ class BlogPost(WebsiteGenerator):

def make_route(self):
if not self.route:
return 'blog/' + frappe.db.get_value('Blog Category', self.blog_category,
return frappe.db.get_value('Blog Category', self.blog_category,
'route') + '/' + self.scrub(self.title)

def get_feed(self):


Loading…
Cancel
Save