[cleanup] form links dashboard and added blocked in Desktop Icons, standard icons hidden by default

This commit is contained in:
Rushabh Mehta 2016-04-13 17:21:07 +05:30
parent 7cd187dacc
commit 5ab8a8d405
19 changed files with 107 additions and 38 deletions

View file

@ -13,6 +13,11 @@ def get_data():
"label": _("To Do"),
"description": _("Documents assigned to you and by you."),
},
{
"type": "doctype",
"name": "File",
"label": _("Files"),
},
{
"type": "doctype",
"name": "Event",

View file

@ -18,20 +18,23 @@ def get_data():
"icon": "octicon octicon-file-directory",
"label": _("File Manager"),
"link": "List/File",
"type": "list"
"type": "list",
"hidden": 1
},
{
"module_name": "Website",
"color": "#16a085",
"icon": "octicon octicon-globe",
"type": "module"
"type": "module",
"hidden": 1
},
{
"module_name": "Setup",
"color": "#bdc3c7",
"reverse": 1,
"icon": "octicon octicon-settings",
"type": "module"
"type": "module",
"hidden": 1
},
{
"module_name": "Core",
@ -39,6 +42,7 @@ def get_data():
"color": "#589494",
"icon": "octicon octicon-circuit-board",
"type": "module",
"system_manager": 1
"system_manager": 1,
"hidden": 1
},
]

View file

@ -18,6 +18,9 @@
</select>
</div>
</div>
<div class="block-warning hidden">
<div class="alert alert-warning small" style="margin: 0px; margin-top: 15px;">{{ _("Global Settings: Users will only be able to choose checked icons") }}</div>
</div>
</div>
{% endif %}
{% include "frappe/core/page/modules_setup/includes/module_icons.html" %}

View file

@ -9,7 +9,9 @@ frappe.pages['modules_setup'].on_page_load = function(wrapper) {
page.content = $(frappe.templates.modules_setup).appendTo(page.body);
page.content.find('select[name="setup_for"]').on('change', function() {
page.content.find('select[name="user"]').toggle($(this).val() !== "everyone");
var val = $(this).val();
page.content.find('select[name="user"]').toggle(val !== "everyone");
page.content.find('.block-warning').toggleClass('hidden', val !== 'everyone');
frappe.reload_modules_setup_icons(page);
});

View file

@ -49,7 +49,7 @@ def get_user_icons(user):
icons = []
for icon in get_desktop_icons(user):
add = True
if icon.hidden_in_standard:
if icon.blocked:
add = False
if not icon.custom:

View file

@ -8,7 +8,6 @@ import frappe
import json
import random
from frappe.model.document import Document
from frappe import _
class DesktopIcon(Document):
def validate(self):
@ -30,7 +29,7 @@ def get_desktop_icons(user=None):
if not user_icons:
fields = ['module_name', 'hidden', 'label', 'link', 'type', 'icon', 'color',
'_doctype', 'idx', 'force_show', 'reverse', 'custom', 'standard']
'_doctype', 'idx', 'force_show', 'reverse', 'custom', 'standard', 'blocked']
standard_icons = frappe.db.get_all('Desktop Icon',
fields=fields, filters={'standard': 1})
@ -53,7 +52,7 @@ def get_desktop_icons(user=None):
if standard_icon.get(key):
icon[key] = standard_icon.get(key)
if standard_icon.hidden:
if standard_icon.blocked:
icon.hidden = 1
# flag for modules_setup page
@ -168,14 +167,18 @@ def set_hidden(module_name, user=None, hidden=1):
hide/unhide it globally'''
if user:
icon = get_user_copy(module_name, user)
if hidden and icon.custom:
frappe.delete_doc(icon.doctype, icon.name, ignore_permissions=True)
return
else:
# hidden by user
icon.db_set('hidden', hidden)
else:
icon = frappe.get_doc('Desktop Icon', {'standard': 1, 'module_name': module_name})
if hidden and icon.custom:
frappe.delete_doc(icon.doctype, icon.name, ignore_permissions=True)
return
icon.db_set('hidden', hidden)
# blocked is globally hidden
icon.db_set('blocked', hidden)
def get_all_icons():
return [d.module_name for d in frappe.get_all('Desktop Icon',

View file

@ -199,7 +199,7 @@ def get_open_count(doctype, name):
filters[fieldname] = name
if filters:
open_count = len(frappe.get_list(doctype, fields='name',
open_count = len(frappe.get_all(doctype, fields='name',
filters=filters, limit_page_length=6, distinct=True))
out.append({'name': doctype, 'count': open_count})

View file

@ -26,7 +26,8 @@ frappe.pages['modules'].on_page_load = function(wrapper) {
}
// render sidebar
page.sidebar.html(frappe.render_template('modules_sidebar', {modules: frappe.get_desktop_icons(true)}));
page.sidebar.html(frappe.render_template('modules_sidebar',
{modules: frappe.get_desktop_icons(true)}));
page.activate_link = function(link) {
page.last_link = link;

View file

@ -1,6 +1,6 @@
<ul class="module-sidebar-nav nav nav-pills nav-stacked">
{% for (var i=0, l= modules.length; i < l; i++) { var item = modules[i];
if(item.type==="module" && !item.hidden_in_standard) { %}
if(item.type==="module" && !item.blocked) { %}
{{ frappe.render_template("modules_sidebar_item", {"item": item}) }}
{% }; } %}
</ul>

View file

@ -123,3 +123,4 @@ frappe.patches.v6_24.sync_desktop_icons
frappe.patches.v6_20x.set_allow_draft_for_print
frappe.patches.v6_20x.remove_roles_from_website_user
frappe.patches.v7_0.set_user_fullname
frappe.patches.v7_0.desktop_icons_hidden_by_admin_as_blocked

View file

@ -0,0 +1,9 @@
import frappe
def execute():
# all icons hidden in standard are "blocked"
# this is for the use case where the admin wants to remove icon for everyone
# in 7.0, icons may be hidden by default, but still can be shown to the user
# e.g. Accounts, Stock etc, so we need a new property for blocked
frappe.db.sql('update `tabDesktop Icon` set blocked = 1 where standard=1 and hidden=1')

View file

@ -150,7 +150,7 @@
"public/js/frappe/form/templates/users_in_sidebar.html",
"public/js/frappe/form/templates/set_sharing.html",
"public/js/frappe/form/templates/form_sidebar.html",
"public/js/frappe/form/templates/form_documents.html",
"public/js/frappe/form/templates/form_links.html",
"public/js/frappe/views/formview.js",
"public/js/legacy/form.js",
"public/js/legacy/clientscriptAPI.js",

View file

@ -379,7 +379,7 @@ frappe.get_module = function(m, default_module) {
return module;
};
frappe.get_desktop_icons = function(show_hidden) {
frappe.get_desktop_icons = function(show_hidden, show_global) {
// filter valid icons
var out = [];
@ -406,10 +406,13 @@ frappe.get_desktop_icons = function(show_hidden) {
out = frappe.boot.user.allow_modules.indexOf(m.module_name) !== -1
}
}
if(out && !show_hidden) {
if(m.hidden) out = false;
if(m.hidden&& !show_hidden) {
out = false;
}
if(m.blocked && !show_global) {
out = false;
}
console.log(module, out);
return out;
}

View file

@ -14,7 +14,9 @@ frappe.ui.form.Dashboard = Class.extend({
this.wrapper.toggle(false);
this.body.empty();
this.badge_area = $('<div class="hidden" \
style="padding-left: 15px; padding-right: 15px;"></div>').appendTo(this.body);
style="padding-left: 15px; padding-right: 15px;">\
<p class="text-muted small" style="margin-bottom: 0px;">'
+ __("Documents related to {0}", [this.frm.doc.name]) +'</p></div>').appendTo(this.body);
this.clear_headline();
},
set_headline: function(html) {
@ -83,20 +85,43 @@ frappe.ui.form.Dashboard = Class.extend({
return progress_chart;
},
show_documents: function() {
show_links: function() {
this.reset();
if(this.frm.doc.__islocal)
return;
this.links = this.frm.doc.__onload.links;
this.render_document_list();
if(!this.links) {
this.links = this.frm.doc.__onload.links;
this.filter_permissions();
}
this.render_links();
this.set_open_count();
},
render_document_list: function() {
filter_permissions: function() {
// filter out transactions for which the user
// does not have permission
var transactions = [];
this.links.transactions.forEach(function(group) {
var items = [];
group.items.forEach(function(doctype) {
if(frappe.model.can_read(doctype)) {
items.push(doctype);
}
});
// only add thie group, if there is atleast
// one item with permission
if(items.length) {
group.items = items;
transactions.push(group);
}
});
this.links.transactions = transactions;
},
render_links: function() {
var me = this;
$(frappe.render_template('form_documents',
$(frappe.render_template('form_links',
{transactions: this.links.transactions}))
.appendTo(this.badge_area)
@ -151,7 +176,7 @@ frappe.ui.form.Dashboard = Class.extend({
callback: function(r) {
$.each(r.message, function(i, d) {
if(d.count) {
me.frm.dashboard.set_badge_count(d.name, d.count > 5 ? '5+' : d.count)
me.frm.dashboard.set_badge_count(d.name, (d.count > 5) ? '5+' : d.count)
}
})
}
@ -162,6 +187,6 @@ frappe.ui.form.Dashboard = Class.extend({
$(this.wrapper)
.find('.open-notification[data-doctype="'+doctype+'"]')
.removeClass('hidden')
.html(cint(count));
.html(count);
}
});

View file

@ -222,7 +222,7 @@ frappe.ui.form.Toolbar = Class.extend({
},
get_action_status: function() {
var status = null;
if (this.frm.page.current_view_name==='print') {
if (this.frm.page.current_view_name==='print' || this.frm.hidden) {
status = "Edit";
} else if (this.can_submit()) {
status = "Submit";
@ -253,6 +253,7 @@ frappe.ui.form.Toolbar = Class.extend({
if(status === "Edit") {
this.page.set_primary_action(__("Edit"), function() {
me.frm.page.set_view('main');
me.frm.set_hidden(false);
}, 'octicon octicon-pencil');
} else if(status === "Cancel") {
this.page.set_secondary_action(__(status), function() {

View file

@ -302,7 +302,7 @@ frappe.views.DocListView = frappe.ui.Listing.extend({
// found in parent
doctype = me.doctype;
} else {
frappe.meta.get_table_fields(me.doctype).forEach(function(d) {
frappe.meta.get_table_fields(me.doctype).every(function(d) {
if(frappe.meta.has_field(d.options, key)) {
doctype = d.options;
return false;

View file

@ -110,7 +110,7 @@ $.extend(frappe.meta, {
},
get_table_fields: function(dt) {
return $.map(frappe.meta.docfield_map[dt], function(d, fieldname) {
return $.map(frappe.meta.docfield_list[dt], function(d) {
return d.fieldtype==='Table' ? d : null});
},

View file

@ -29,7 +29,7 @@ _f.frms = {};
_f.Frm = function(doctype, parent, in_form) {
this.docname = '';
this.doctype = doctype;
this.display = 0;
this.hidden = false;
this.refresh_if_stale_for = 120;
var me = this;
@ -178,6 +178,14 @@ _f.Frm.prototype.print_doc = function() {
this.print_preview.set_user_lang();
}
_f.Frm.prototype.set_hidden = function(status) {
// set hidden if hide_first is set
this.hidden = status;
this.page.wrapper.find('.form-page').toggleClass('hidden', this.hidden);
this.toolbar.refresh();
}
_f.Frm.prototype.hide_print = function() {
if(this.setup_done && this.page.current_view_name==="print") {
this.page.set_view(this.page.previous_view_name==="print" ?
@ -427,9 +435,13 @@ _f.Frm.prototype.refresh = function(docname) {
this.print_preview.preview();
}
if(this.show_print_first && is_a_different_doc && this.doc.docstatus===1) {
// show print view
this.print_doc();
if(is_a_different_doc) {
if(this.show_print_first && this.doc.docstatus===1) {
// show print view
this.print_doc();
} else if(this.hide_first && !this.doc.__unsaved) {
this.set_hidden(true);
}
}
this.show_if_needs_refresh();