Module View, Removed Website Table of Contents

This commit is contained in:
Anand Doshi 2014-03-03 15:03:38 +05:30
parent 735b1d76ef
commit d6a0b951ae
25 changed files with 283 additions and 732 deletions

View file

@ -26,7 +26,6 @@ data = {
"Website": {
"color": "#16a085",
"icon": "icon-globe",
"link": "website-home",
"type": "module"
},
"Installer": {
@ -39,7 +38,6 @@ data = {
"Setup": {
"color": "#bdc3c7",
"icon": "icon-wrench",
"link": "Setup",
"type": "setup"
"type": "module"
},
}

View file

@ -52,12 +52,14 @@ data = [
{
"type": "doctype",
"name": "Naming Series",
"description": _("Set numbering series for transactions.")
"description": _("Set numbering series for transactions."),
"hide_count": True
},
{
"type": "doctype",
"name": "Rename Tool",
"description": _("Rename many items by uploading a .csv file.")
"description": _("Rename many items by uploading a .csv file."),
"hide_count": True
},
{
"type": "doctype",

View file

@ -35,10 +35,16 @@ frappe.desktop.render = function() {
var add_icon = function(m) {
var module = frappe.modules[m];
if(!module || (!module.link && !module.onclick) || module.is_app)
if(!module || (module.type!=="module" && !module.link && !module.onclick) || module.is_app)
return;
if(module.link)
if(module.type==="module" && !module.link) {
module.link = "Module/" + m;
}
if(module.link) {
module._link = module.link.toLowerCase().replace("/", "-");
}
module.app_icon = frappe.ui.app_icon.get_html(m);

View file

@ -1,109 +0,0 @@
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
// MIT License. See license.txt
frappe.pages['Setup'].onload = function(wrapper) {
if(msg_dialog && msg_dialog.display) msg_dialog.hide();
frappe.ui.make_app_page({
parent: wrapper,
title: frappe._('Setup'),
single_column: true
});
wrapper.appframe.add_module_icon("Setup");
wrapper.appframe.set_title_right(frappe._("Refresh"), function() {
frappe.setup.make(wrapper);
});
frappe.setup.make(wrapper);
}
frappe.setup = {
make: function(wrapper) {
frappe.call({
method: "frappe.core.page.setup.setup.get",
callback: function(r) {
frappe.setup.render(r.message, $(wrapper).find(".layout-main").empty())
}
})
},
render: function(data, wrapper) {
$('<div class="row">\
<div class="col-sm-3">\
<ul class="nav nav-pills nav-stacked"></ul>\
</div>\
<div class="col-sm-9 contents">\
</div>\
</div>').appendTo(wrapper);
var $sections = wrapper.find(".nav-pills");
$.each(data, function(i, d) {
d._label = d.label.toLowerCase().replace(/ /g, "_");
var $nav = $sections.find('[data-label="'+d._label+'"]');
if(!$sections.find('[data-label="'+d._label+'"]').length) {
$nav = $('<li><a><i class="'+d.icon+' icon-fixed-width"></i> '
+ frappe._(d.label)+'</a></li>')
.attr("data-label", d._label)
.appendTo($sections);
var $content = $('<div class="panel panel-default"></div>')
.toggle(false)
.attr("id", d._label)
.appendTo(wrapper.find(".contents"))
$('<div class="panel-heading">').appendTo($content).html('<i class="'+d.icon+'"></i> '
+ d.label);
var $list = $('<ul class="list-group">').appendTo($content);
} else {
var $content = $("#" + d._label);
var $list = $content.find(".list-group");
}
// add items
$.each(d.items, function(i, item) {
if((item.type==="doctype" && frappe.model.can_read(item.name))
|| (item.type==="page" && frappe.boot.page_info[item.name])) {
if(!item.label) {
item.label = item.name;
}
if(item.type==="doctype") {
item.icon = frappe.boot.doctype_icons[item.name];
}
$list_item = $($r('<li class="list-group-item">\
<div class="row">\
<div class="col-xs-4"><a><i class="%(icon)s icon-fixed-width"></i> %(label)s</a></div>\
<div class="col-xs-8 text-muted">%(description)s</div>\
</div>\
</li>', item)).appendTo($list);
$list_item.find("a")
.attr("data-type", item.type)
.attr("data-name", item.link || item.name)
.on("click", function() {
if($(this).attr("data-type")==="doctype") {
frappe.set_route("List", $(this).attr("data-name"))
}
else if($(this).attr("data-type")==="page") {
frappe.set_route($(this).attr("data-name"))
}
});
}
})
})
// section selection (can't use tab api - routing)
$sections.find('a').click(function (e) {
e.preventDefault();
if($(this).parent().hasClass("active")) {
return;
}
$(this).parents("ul:first").find("li.active").removeClass("active");
$(this).parent().addClass("active");
wrapper.find(".panel").toggle(false);
$("#" + $(this).parent().attr("data-label")).toggle(true);
});
$sections.find('a:first').trigger("click");
}
}

View file

@ -1,17 +0,0 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt
from __future__ import unicode_literals
import frappe, json, os
from frappe import _
@frappe.whitelist()
def get():
setup = []
for app in frappe.get_installed_apps():
try:
setup += frappe.get_attr(app + ".config.setup.data")
except ImportError, e:
pass
return setup

View file

@ -1,32 +0,0 @@
[
{
"creation": "2012-06-14 15:07:28",
"docstatus": 0,
"modified": "2014-02-07 14:50:08",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"doctype": "Page",
"icon": "icon-cog",
"module": "Core",
"name": "__common__",
"page_name": "Setup",
"standard": "Yes"
},
{
"doctype": "Page Role",
"name": "__common__",
"parent": "Setup",
"parentfield": "roles",
"parenttype": "Page",
"role": "System Manager"
},
{
"doctype": "Page",
"name": "Setup"
},
{
"doctype": "Page Role"
}
]

View file

@ -4,6 +4,7 @@ def execute():
installed = frappe.get_installed_apps()
if "webnotes" in installed:
installed.remove("webnotes")
installed = ["frappe"] + installed
if "frappe" not in installed:
installed = ["frappe"] + installed
frappe.db.set_global("installed_apps", json.dumps(installed))
frappe.clear_cache()

View file

@ -16,6 +16,7 @@ def execute():
from `tabWebsite Template` wsc where wsc.name=ws.website_template)
where ifnull(page_or_generator, '')!='Page'""")
frappe.reload_doc("website", "doctype", "website_settings")
home_page = frappe.db.get_value("Website Settings", "Website Settings", "home_page")
home_page = frappe.db.get_value("Website Route", {"docname": home_page}) or home_page
frappe.db.set_value("Website Settings", "Website Settings", "home_page",

View file

@ -4,15 +4,20 @@
frappe.provide("frappe.views.moduleview");
frappe.provide("frappe.module_page");
frappe.views.moduleview.make = function(wrapper, module) {
wrapper.module_view = new frappe.views.moduleview.ModuleView(wrapper, module);
frappe.views.ModuleFactory = frappe.views.Factory.extend({
make: function(route) {
var module = route[1];
this.page = this.make_page(false);
frappe.views.moduleview[module] = this.page;
this.page.moduleview = new frappe.views.moduleview.ModuleView(this.page, module);
},
});
frappe.views.moduleview.make = function(wrapper, module, method) {
if(!method) method = "frappe.widgets.moduleview.get";
wrapper.module_view = new frappe.views.moduleview.ModuleView(wrapper, module, method);
wrapper.refresh = function() {
// remake on refresh
if((new Date() - wrapper.module_view.created_on) > (180 * 1000)) {
wrapper.module_view = new frappe.views.moduleview.ModuleView(wrapper, module);
}
}
}
frappe.views.show_open_count_list = function(element) {
@ -31,9 +36,11 @@ frappe.views.show_open_count_list = function(element) {
frappe.views.moduleview.ModuleView = Class.extend({
init: function(wrapper, module) {
this.doctypes = [];
this.top_item_total = {};
this.top_item_open = {};
this.prepare(wrapper, module);
this.make(wrapper, module);
},
prepare: function(wrapper, module) {
var me = this;
$(wrapper).empty();
frappe.ui.make_app_page({
parent: wrapper,
@ -42,214 +49,219 @@ frappe.views.moduleview.ModuleView = Class.extend({
});
wrapper.appframe.add_module_icon(module);
wrapper.appframe.set_title_left('<i class="icon-angle-left"></i> Home', function() { frappe.set_route(""); });
this.wrapper = wrapper;
this.module = module;
this.make_body();
this.render_static();
this.render_dynamic();
this.created_on = new Date();
var me = this;
wrapper.appframe.set_title_right(frappe._("Refresh"), function() {
me.make(wrapper, module);
});
// full refresh
wrapper.refresh = function() {
// remake on refresh
if((new Date() - me.created_on) > (180 * 1000)) {
me.make(wrapper, module);
}
};
// counts
$(document).on("notification-update", function() {
me.update_open_count();
if(wrapper.$layout) {
me.update_open_count(wrapper.$layout);
}
});
},
make_body: function() {
var wrapper = this.wrapper;
// make columns
$(wrapper).find(".layout-main").html("<div class='module-top'></div>\
<div class='row'>\
<div class='col-md-6 main-section'></div>\
<div class='col-md-6 side-section'></div>\
</div>")
make: function(wrapper, module) {
var me = this;
return frappe.call({
method: "frappe.widgets.moduleview.get",
args: {
module: module
},
callback: function(r) {
me.render(wrapper, r.message);
}
});
},
render: function(wrapper, message) {
var me = this;
this.doctypes = [];
var $layout = this.make_layout(wrapper);
wrapper.$layout = $layout;
$(wrapper).on("click", ".badge-important", function() {
$.each(message.data, function(i, d) {
// d is a section
me.add_section(d, $layout);
me.add_items(d, $layout);
});
me.add_reports(message.reports, $layout);
me.show_counts(message.item_count, $layout);
me.setup_navigation($layout);
// for refresh
this.created_on = new Date();
},
make_layout: function(wrapper) {
return $('<div class="row">\
<div class="col-sm-3">\
<ul class="nav nav-pills nav-stacked"></ul>\
</div>\
<div class="col-sm-9 contents">\
</div>\
</div>').appendTo($(wrapper).find(".layout-main").empty());
},
add_section: function(d, $layout) {
if(!d._label) d._label = d.label.toLowerCase().replace(/ /g, "_");
var $sections = $layout.find(".nav-pills");
var $nav = $sections.find('[data-label="'+d._label+'"]');
// if not found, add section
if(!$nav.length) {
// create nav tab
$nav = $('<li><a><i class="'+d.icon+' icon-fixed-width"></i> '
+ frappe._(d.label)+'</a></li>')
.attr("data-label", d._label)
.appendTo($sections);
// create content pane for this nav
var $content = $('<div class="panel panel-default"></div>')
.toggle(false)
.attr("data-content-label", d._label)
.appendTo($layout.find(".contents"));
$('<div class="panel-heading">').appendTo($content).html('<i class="'+d.icon+'"></i> '
+ d.label);
var $list = $('<ul class="list-group">').appendTo($content);
}
},
add_items: function(d, $layout) {
var me = this;
var $content = $layout.find('[data-content-label="' + d._label + '"]');
var $list = $content.find(".list-group");
// add items in each pane
$.each(d.items, function(i, item) {
if(item.country && frappe.boot.control_panel.country!==item.country) return;
if((item.type==="doctype" && frappe.model.can_read(item.name))
|| (item.type==="page" && frappe.boot.page_info[item.name])
|| (item.type==="report" && frappe.model.can_get_report(item.doctype))) {
if(!item.label) {
item.label = __(item.name);
}
if(item.type==="doctype") {
item.icon = item.icon || frappe.boot.doctype_icons[item.name];
if(me.doctypes.indexOf(item.name)===-1) {
me.doctypes.push(item.name);
}
} else if(item.type==="report" && item.doctype) {
item.icon = item.icon || frappe.boot.doctype_icons[item.doctype];
}
item.description = cstr(item.description);
$list_item = $($r('<li class="list-group-item">\
<div class="row">\
<div class="col-sm-6 list-item-name">\
<a><i class="%(icon)s icon-fixed-width"></i> %(label)s</a></div>\
<div class="col-sm-6 text-muted list-item-description">%(description)s</div>\
</div>\
</li>', item)).appendTo($list);
// expand col if no description
if(!item.description) {
$list_item.find(".list-item-description").remove();
$list_item.find(".list-item-name").removeClass("col-sm-6").addClass("col-sm-12");
}
$list_item.find("a")
.on("click", function() {
if(item.route) {
frappe.set_route(item.route);
} else if(item.type==="doctype") {
frappe.set_route("List", item.name)
}
else if(item.type==="page") {
frappe.set_route(item.route || item.name);
}
else if(item.type==="report") {
if(item.is_query_report) {
frappe.set_route("query-report", item.name);
} else {
frappe.set_route("Report", item.doctype, item.name);
}
}
});
var show_count = (item.type==="doctype" || (item.type==="page" && item.doctype)) && !item.hide_count
if(show_count) {
$(repl('<span data-doctype-count="%(doctype)s" style="margin-left: 2px;"></span>',
{doctype: item.doctype || item.name})).appendTo($list_item.find(".list-item-name"));
}
}
});
},
add_reports: function(reports, $layout) {
if(!(reports && reports.length)) return;
var reports_section = {
label: __("Custom Reports"),
icon: "icon-list",
items: reports
}
this.add_section(reports_section, $layout);
this.add_items(reports_section, $layout);
},
show_counts: function(item_count, $layout) {
// total count
$.each(item_count, function(doctype, count) {
$layout.find("[data-doctype-count='"+doctype+"']")
.html(count)
.addClass("badge badge-count pull-right")
.css({cursor:"pointer"});
});
// open count
this.update_open_count($layout);
},
setup_navigation: function($layout) {
var me = this;
// section selection (can't use tab api - routing)
var $sections = $layout.find(".nav-pills");
$sections.find('a').click(function (e) {
e.preventDefault();
if($(this).parent().hasClass("active")) {
return;
}
$(this).parents("ul:first").find("li.active").removeClass("active");
$(this).parent().addClass("active");
$layout.find(".panel").toggle(false);
$layout.find('[data-content-label="'+ $(this).parent().attr("data-label") +'"]').toggle(true);
});
$sections.find('a:first').trigger("click");
$layout.on("click", ".badge-important", function() {
frappe.views.show_open_count_list(this);
});
$(wrapper).on("click", ".badge-count", function() {
$layout.on("click", ".badge-count", function() {
var doctype = $(this).attr("data-doctype-count");
frappe.set_route("List", doctype);
});
},
add_section: function(section) {
section._title = frappe._(section.title);
if(section.top) {
var module_top = $(this.wrapper).find(".module-top");
var list_group = $('<div class="row">')
.appendTo(module_top);
$('<hr class="row">')
.insertAfter(module_top);
} else {
var list_group = $('<ul class="list-group">\
<li class="list-group-item">\
<h4 class="list-group-item-heading" style="margin-bottom: 0px;">\
<i class="text-muted '+ section.icon+'"></i> '
+ frappe._(section.title) +'</h4>\
</li>\
</ul>"').appendTo(section.right
? $(this.wrapper).find(".side-section")
: $(this.wrapper).find(".main-section"));
}
section.list_group = list_group;
},
add_item: function(item, section) {
if(!item.description) item.description = "";
if(item.count==null) item.count = "";
if(!item.icon) item.icon = "";
if(section.top) {
var $parent = $(repl('<div class="col-sm-4">\
<div class="alert alert-info alert-badge"></div></div>'))
.appendTo(section.list_group)
.find(".alert-badge");
this.top_item_total[item.doctype] = 0;
} else {
var $parent = $('<li class="list-group-item">').appendTo(section.list_group);
}
$(repl('%(icon)s<span' +
((item.doctype && item.description)
? " data-doctype='"+item.doctype+"'"
: "") + ">%(link)s</span>"
+ ((item.description && !section.top)
? " <span class='text-muted small'>%(description)s</span>"
: "")
+ ((section.right || !item.doctype)
? ''
: '<span data-doctype-count="%(doctype)s" style="margin-left: 2px;"></span>'), item))
.appendTo($parent);
if(!section.top) {
$('<span class="clearfix"></span>').appendTo($parent);
}
},
set_top_item_count: function(doctype, count, open_count) {
return;
update_open_count: function($layout) {
var me = this;
if(this.top_item_total[doctype]!=null) {
if(count!=null)
this.top_item_total[doctype] = count;
if(open_count!=null)
this.top_item_open[doctype] = open_count;
var maxtop = Math.max.apply(this, values(this.top_item_total));
$.each(this.top_item_total, function(doctype, item_count) {
$(me.wrapper).find(".module-item-progress[data-doctype='"+ doctype +"']")
.find(".module-item-progress-total")
.css("width", cint(flt(item_count)/maxtop*100) + "%")
})
$.each(this.top_item_open, function(doctype, item_count) {
$(me.wrapper).find(".module-item-progress[data-doctype='"+ doctype +"']")
.find(".module-item-progress-open")
.css("width", cint(flt(item_count)/me.top_item_total[doctype]*100) + "%")
})
}
},
render_static: function() {
// render sections
var me = this;
$.each(frappe.module_page[this.module], function(i, section) {
me.add_section(section);
$.each(section.items, function(i, item) {
if(item.doctype) {
me.doctypes.push(item.doctype);
item.icon = '<i class="icon-fixed-width '+ frappe.boot.doctype_icons[item.doctype] + '"></i> ';
}
if(item.doctype && !item.route) {
item.route = "List/" + encodeURIComponent(item.doctype);
}
if(item.page && !item.route) {
item.route = item.page;
}
if(item.page) {
item.icon = '<i class="icon-fixed-width '+ frappe.boot.doctype_icons[item.page] + '"></i> ';
}
// link
item.link = repl("<a href='#%(route)s'>%(label)s</a>", item);
// doctype permissions
if(item.doctype && !frappe.model.can_read(item.doctype)) {
//item.link = item.label;
return;
}
// page permissions
if(item.page && !in_list(frappe.boot.allowed_pages, item.page)) {
//item.link = item.label;
return;
}
if((item.country && frappe.boot.control_panel.country==item.country)
|| !item.country)
me.add_item(item, section)
});
if(section.list_group.find("li").length==1) {
section.list_group.toggle(false);
}
});
},
render_dynamic: function() {
// render reports
var me = this;
return frappe.call({
method: "frappe.widgets.moduleview.get_data",
args: {
module: me.module,
doctypes: me.doctypes
},
callback: function(r) {
if(r.message) {
// reports
if(r.message.reports.length) {
var section = {
title: frappe._("Custom Reports"),
right: true,
icon: "icon-list",
}
me.add_section(section);
$.each(r.message.reports, function(i, item) {
if(frappe.model.can_read(item.doctype)) {
item.icon = '<i class="icon-fixed-width '
+ frappe.boot.doctype_icons[item.doctype] + '"></i> ';
if(item.is_query_report) {
item.link = repl("<a href=\"#query-report/%(name)s\">%(name)s</a>",
item);
} else {
item.link = repl("<a href=\"#Report/%(doctype)s/%(name)s\">\
%(name)s</a>", item);
}
me.add_item(item, section);
}
})
}
// counts
if(r.message.item_count) {
$.each(r.message.item_count, function(doctype, count) {
$(me.wrapper).find("[data-doctype-count='"+doctype+"']")
.html(count)
.addClass("badge badge-count pull-right")
.css({cursor:"pointer"});
me.set_top_item_count(doctype, count)
})
}
// open-counts
me.update_open_count();
}
}
});
},
update_open_count: function() {
var me = this;
$(me.wrapper).find(".badge-important").remove();
$layout.find(".badge-important").remove();
if(frappe.boot.notification_info.open_count_doctype) {
$.each(frappe.boot.notification_info.open_count_doctype, function(doctype, count) {
if(count && in_list(me.doctypes, doctype)) {
me.set_top_item_count(doctype, null, count);
$('<span>')
.css({
"cursor": "pointer",
@ -258,10 +270,9 @@ frappe.views.moduleview.ModuleView = Class.extend({
.addClass("badge badge-important pull-right")
.html(count)
.attr("data-doctype", doctype)
.insertAfter($(me.wrapper)
.find("[data-doctype-count='"+doctype+"']"));
.insertAfter($layout.find("[data-doctype-count='"+doctype+"']"));
}
})
}
}
},
});

View file

@ -1,38 +1,9 @@
{% block content %}
<div class="webpage-content">
{# title, breadcrumbs, table of contents #}
{% include "templates/includes/slideshow.html" %}
<div class="web-page-content" id="{{ name }}">
{{ main_section or "" }}
</div>
{# toc, parent, child, next sibling #}
{% if show_toc and toc_list -%}
<div class="well">
<h4>Contents</h4>
<ol>
{% for t in toc_list -%}
<li><a href="{{ t.page_name }}">{{ t.title }}</a></li>
{%- endfor %}
</ol>
</div>
{%- endif %}
{% if links and links.get("parent") -%}
<div class="btn-group pull-right" style="margin: 15px 0px;">
<a class='btn btn-default' href="{{ links.parent.page_name }}">
<i class="icon-arrow-up"></i> {{ links.parent.title }}</a>
{% if links.get("next") -%}
<a class='btn btn-default' href="{{ links.next.page_name }}">
<i class="icon-arrow-right"></i> {{ links.next.title }}</a>
{%- endif -%}
{% if links.get("child") -%}
<a class='btn btn-default' href="{{ links.child.page_name }}">
<i class="icon-arrow-down"></i> {{ links.child.title }}</a>
{%- endif -%}
</div>
<div class="clearfix"></div>
{%- endif %}
{% if enable_comments -%}
<hr>
<h3>Discuss</h3>

View file

@ -16,12 +16,6 @@ def get_context(context):
web_page.doc.meta_description = web_page.doc.description
# web_page.doc.breadcrumbs = get_breadcrumbs(web_page)
web_page.doc.toc_list = get_toc_list(web_page)
# parent, child, next sibling links
web_page.doc.links = get_navigation_links(web_page)
if web_page.doc.enable_comments:
web_page.doc.comment_list = frappe.db.sql("""select
comment, comment_by_fullname, creation
@ -36,58 +30,3 @@ def get_context(context):
web_page.doc.fields.update(context)
return web_page.doc.fields
def get_breadcrumbs(web_page):
breadcrumbs = []
def add_parent_of(web_page):
parent = frappe.db.sql("""select name, page_name, title from `tabWeb Page`
where exists (select parent from `tabTable of Contents`
where `tabTable of Contents`.parent=`tabWeb Page`.name
and web_page=%s)""", web_page, as_dict=True)
if parent and parent[0]:
parent = parent[0]
add_parent_of(parent.name)
breadcrumbs.append(parent)
add_parent_of(web_page.doc.name)
return breadcrumbs
def get_toc_list(web_page):
toc_list = web_page.doclist.get({"parentfield": "toc"})
if not toc_list: return []
out = frappe.db.sql("""select name, page_name, title
from `tabWeb Page` where name in (%s)""" % \
(", ".join(["%s"]*len(toc_list))),
tuple([d.web_page for d in toc_list]),
as_dict=True)
toc_idx = dict(((toc.web_page, toc.idx) for toc in toc_list))
return sorted(out, key=lambda x: toc_idx.get(x.name))
def get_navigation_links(web_page):
links = {}
if web_page.doc.toc_list:
links["child"] = web_page.doc.toc_list[0]
if web_page.doc.breadcrumbs:
if web_page.doc.breadcrumbs[-1]:
links["parent"] = web_page.doc.breadcrumbs[-1]
def set_next(current, parent, breadcrumbs):
web_page = frappe.get_obj("Web Page", parent)
toc_list = web_page.get_toc_list()
for i, toc in enumerate(toc_list):
if toc.name == current and ((i+1)<len(toc_list)):
links["next"] = toc_list[i+1]
break
if not links.get("next") and breadcrumbs:
set_next(parent, breadcrumbs[-1].name, breadcrumbs[:-1])
set_next(web_page.doc.name, web_page.doc.breadcrumbs[-1].name, web_page.doc.breadcrumbs[:-1])
return links

View file

@ -2,7 +2,7 @@
{
"creation": "2014-01-07 14:00:04",
"docstatus": 0,
"modified": "2014-01-29 16:27:45",
"modified": "2014-03-03 14:53:18",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -10,6 +10,7 @@
"autoname": "P.#######",
"doctype": "DocType",
"document_type": "Transaction",
"icon": "icon-comment",
"module": "Website",
"name": "__common__"
},

View file

@ -1,11 +0,0 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt
# For license information, please see license.txt
from __future__ import unicode_literals
import frappe
class DocType:
def __init__(self, d, dl):
self.doc, self.doclist = d, dl

View file

@ -1,38 +0,0 @@
[
{
"creation": "2013-11-11 15:19:27",
"docstatus": 0,
"modified": "2013-12-20 19:21:51",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"autoname": "TOC-.#####",
"doctype": "DocType",
"document_type": "Other",
"istable": 1,
"module": "Website",
"name": "__common__"
},
{
"doctype": "DocField",
"fieldname": "web_page",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Web Page",
"name": "__common__",
"options": "Web Page",
"parent": "Table of Contents",
"parentfield": "fields",
"parenttype": "DocType",
"permlevel": 0,
"reqd": 1
},
{
"doctype": "DocType",
"name": "Table of Contents"
},
{
"doctype": "DocField"
}
]

View file

@ -16,12 +16,6 @@ $.extend(cur_frm.cscript, {
}
}
},
onload: function() {
// set query!
cur_frm.set_query("web_page", "toc", function() {
return {"filters": {"name": ["!=", cur_frm.doc.name]}};
});
},
refresh: function(doc) {
cur_frm.cscript.layout(doc);
if(!doc.__islocal && doc.published) {

View file

@ -8,30 +8,4 @@ from frappe.website.utils import cleanup_page_name
from frappe.utils import cint
class DocType(WebsiteGenerator):
def validate(self):
for d in self.doclist.get({"parentfield": "toc"}):
if d.web_page == self.doc.name:
frappe.throw('{web_page} "{name}" {not_in_own} {toc}'.format(
web_page=_("Web Page"), name=d.web_page,
not_in_own=_("cannot be in its own"), toc=_(self.meta.get_label("toc"))))
def on_update(self):
WebsiteGenerator.on_update(self)
# clear all cache if it has toc
if self.doclist.get({"parentfield": "toc"}):
from frappe.website.render import clear_cache
clear_cache()
def on_trash(self):
# delete entry from Table of Contents of other pages
WebsiteGenerator.on_trash(self)
frappe.db.sql("""delete from `tabTable of Contents`
where web_page=%s""", self.doc.name)
# clear all cache if it has toc
if self.doclist.get({"parentfield": "toc"}):
from frappe.website.render import clear_cache
clear_cache()
pass

View file

@ -2,7 +2,7 @@
{
"creation": "2013-03-28 10:35:30",
"docstatus": 0,
"modified": "2014-02-10 18:07:29",
"modified": "2014-02-28 14:24:14",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -179,37 +179,6 @@
"label": "CSS",
"options": "CSS"
},
{
"doctype": "DocField",
"fieldname": "table_of_contents",
"fieldtype": "Section Break",
"label": "Table of Contents"
},
{
"doctype": "DocField",
"fieldname": "show_title",
"fieldtype": "Check",
"label": "Show Title"
},
{
"doctype": "DocField",
"fieldname": "show_breadcrumbs",
"fieldtype": "Check",
"label": "Show Breadcrumbs"
},
{
"doctype": "DocField",
"fieldname": "show_toc",
"fieldtype": "Check",
"label": "Show Table of Contents"
},
{
"doctype": "DocField",
"fieldname": "toc",
"fieldtype": "Table",
"label": "Table of Contents",
"options": "Table of Contents"
},
{
"doctype": "DocPerm"
}

View file

@ -2,13 +2,14 @@
{
"creation": "2014-01-29 15:57:42",
"docstatus": 0,
"modified": "2014-02-27 12:51:53",
"modified": "2014-03-03 14:52:19",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"doctype": "DocType",
"document_type": "Master",
"icon": "icon-group",
"module": "Website",
"name": "__common__"
},
@ -21,7 +22,6 @@
"permlevel": 0
},
{
"cancel": 0,
"create": 1,
"delete": 1,
"doctype": "DocPerm",

View file

@ -1 +0,0 @@
from __future__ import unicode_literals

View file

@ -1,122 +0,0 @@
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
// MIT License. See license.txt"
frappe.module_page["Website"] = [
{
title: frappe._("Web Content"),
icon: "icon-copy",
top: true,
items: [
{
label: frappe._("Web Page"),
description: frappe._("Content web page."),
doctype:"Web Page"
},
{
label: frappe._("Website Group"),
description: frappe._("Web Site Forum Page."),
doctype:"Website Group"
},
{
label: frappe._("Blog Post"),
description: frappe._("Single Post (article)."),
doctype:"Blog Post"
},
]
},
{
title: frappe._("Documents"),
icon: "icon-edit",
items: [
{
label: frappe._("Website Slideshow"),
description: frappe._("Embed image slideshows in website pages."),
doctype:"Website Slideshow"
},
{
label: frappe._("Blogger"),
description: frappe._("Profile of a blog writer."),
doctype:"Blogger"
},
{
label: frappe._("Blog Category"),
description: frappe._("Categorize blog posts."),
doctype:"Blog Category"
},
{
label: frappe._("Blog Settings"),
description: frappe._("Write titles and introductions to your blog."),
doctype:"Blog Settings",
route: "Form/Blog Settings"
},
{
label: frappe._("Website Page Permission"),
description: frappe._("Define read, write, admin permissions for a Website Page."),
doctype:"Website Route Permission",
},
]
},
{
title: frappe._("Website Overall Settings"),
icon: "icon-wrench",
right: true,
items: [
{
"route":"sitemap-browser",
"label":frappe._("Sitemap Browser"),
"description":frappe._("View or manage Website Route tree."),
doctype:"Website Settings",
icon: "icon-sitemap"
},
{
"route":"Form/Website Settings",
"label":frappe._("Website Settings"),
"description":frappe._("Setup of top navigation bar, footer and logo."),
doctype:"Website Settings"
},
{
"route":"Form/Style Settings",
"label":frappe._("Style Settings"),
"description":frappe._("Setup of fonts and background."),
doctype:"Style Settings"
},
]
},
{
title: frappe._("Special Page Settings"),
icon: "icon-wrench",
right: true,
items: [
{
"route":"Form/About Us Settings",
"label":frappe._("About Us Settings"),
"description":frappe._("Settings for About Us Page."),
doctype:"About Us Settings"
},
{
"route":"Form/Contact Us Settings",
"label":frappe._("Contact Us Settings"),
"description":frappe._("Settings for Contact Us Page."),
doctype:"Contact Us Settings"
},
]
},
{
title: frappe._("Advanced Scripting"),
icon: "icon-wrench",
right: true,
items: [
{
"route":"Form/Website Script",
"label":frappe._("Website Script"),
"description":frappe._("Javascript to append to the head section of the page."),
doctype:"Website Script"
},
]
}
]
pscript['onload_website-home'] = function(wrapper) {
frappe.views.moduleview.make(wrapper, "Website");
}

View file

@ -1,22 +0,0 @@
[
{
"creation": "2012-02-21 13:23:51",
"docstatus": 0,
"modified": "2013-07-11 14:45:29",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"doctype": "Page",
"icon": "icon-th",
"module": "Website",
"name": "__common__",
"page_name": "website-home",
"standard": "Yes",
"title": "Website Home"
},
{
"doctype": "Page",
"name": "website-home"
}
]

View file

@ -4,6 +4,7 @@
from __future__ import unicode_literals
import frappe
from frappe.utils import strip_html
from frappe.website.utils import scrub_relative_urls
from jinja2.utils import concat
from jinja2 import meta
@ -44,5 +45,7 @@ def render_blocks(context):
if "sidebar" not in out:
out["sidebar"] = scrub_relative_urls(
frappe.get_template("templates/includes/sidebar.html").render(context))
out["title"] = strip_html(out.get("title") or "")
return out

View file

@ -4,15 +4,47 @@
from __future__ import unicode_literals
import frappe, json
from frappe.widgets import reportview
from frappe.utils import cint
@frappe.whitelist()
def get_data(module, doctypes='[]'):
doctypes = json.loads(doctypes)
def get(module):
data = get_data(module)
doctypes = get_doctypes(data)
return {
"reports": get_report_list(module),
"item_count": get_count(doctypes)
"data": data,
"item_count": get_count(doctypes),
"reports": get_report_list(module)
}
def get_data(module):
data = []
module = frappe.scrub(module)
for app in frappe.get_installed_apps():
try:
data += get_config(app, module)
except ImportError, e:
pass
return data
def get_config(app, module):
config = frappe.get_module("{app}.config.{module}".format(app=app, module=module))
return config.get_data() if hasattr(config, "get_data") else config.data
def get_doctypes(data):
doctypes = []
for section in data:
for item in section.get("items", []):
if item.get("type")=="doctype":
doctypes.append(item["name"])
elif item.get("doctype"):
doctypes.append(item["doctype"])
return list(set(doctypes))
def get_count(doctypes):
count = {}
can_read = frappe.user.get_can_read()
@ -29,14 +61,15 @@ def get_doctype_count_from_table(doctype):
count = None
else:
raise
return count
return cint(count)
def get_report_list(module):
"""return list on new style reports for modules"""
return frappe.db.sql("""
select distinct tabReport.name, tabReport.ref_doctype as doctype,
select distinct "report" as type, tabReport.name, tabReport.ref_doctype as doctype,
if((tabReport.report_type='Query Report' or
tabReport.report_type='Script Report'), 1, 0) as is_query_report
tabReport.report_type='Script Report'), 1, 0) as is_query_report,
report_type as description
from `tabReport`, `tabDocType`
where tabDocType.module=%s
and tabDocType.name = tabReport.ref_doctype