Browse Source

[views] cleaned up, added ganttview

version-14
Rushabh Mehta 12 years ago
parent
commit
4baee9a10a
15 changed files with 515 additions and 307 deletions
  1. +2
    -2
      core/doctype/event/event_calendar.js
  2. +1
    -1
      public/build.json
  3. +2
    -6
      public/js/legacy/webpage/loaders.js
  4. +2
    -9
      public/js/legacy/widgets/form/form.js
  5. +11
    -4
      public/js/lib/jQuery.Gantt/css/style.css
  6. +254
    -135
      public/js/lib/jQuery.Gantt/js/jquery.fn.gantt.js
  7. +13
    -20
      public/js/wn/router.js
  8. +14
    -29
      public/js/wn/views/calendar.js
  9. +34
    -3
      public/js/wn/views/container.js
  10. +21
    -32
      public/js/wn/views/doclistview.js
  11. +45
    -39
      public/js/wn/views/formview.js
  12. +109
    -0
      public/js/wn/views/ganttview.js
  13. +1
    -0
      public/js/wn/views/listview.js
  14. +0
    -25
      public/js/wn/views/load_reportview.js
  15. +6
    -2
      public/js/wn/views/reportview.js

+ 2
- 2
core/doctype/event/event_calendar.js View File

@@ -1,4 +1,4 @@
wn.views.calendar["Event"] = wn.views.Calendar.extend({
wn.views.calendar["Event"] = {
field_map: {
"start": "starts_on",
"end": "ends_on",
@@ -12,4 +12,4 @@ wn.views.calendar["Event"] = wn.views.Calendar.extend({
"Private": "info"
},
get_events_method: "core.doctype.event.event.get_events"
})
}

+ 1
- 1
public/build.json View File

@@ -109,9 +109,9 @@
"lib/public/js/wn/views/moduleview.js",
"lib/public/js/wn/views/listview.js",
"lib/public/js/wn/views/formview.js",
"lib/public/js/wn/views/load_reportview.js",
"lib/public/js/wn/views/reportview.js",
"lib/public/js/wn/views/calendar.js",
"lib/public/js/wn/views/ganttview.js",
"lib/public/js/wn/views/query_report.js",
"lib/public/js/wn/views/grid_report.js",
"lib/public/js/wn/views/communication.js",


+ 2
- 6
public/js/legacy/webpage/loaders.js View File

@@ -40,12 +40,8 @@ var load_doc = loaddoc;

function new_doc(doctype, in_form) {
wn.model.with_doctype(doctype, function() {
if(!in_form && locals.DocType[doctype].in_dialog) {
var new_name = wn.model.make_new_doc_and_get_name(doctype);
_f.edit_record(doctype, new_name);
} else {
wn.views.formview.create(doctype);
}
var new_name = wn.model.make_new_doc_and_get_name(doctype);
wn.set_route("Form", doctype, new_name);
})
}
var newdoc = new_doc;


+ 2
- 9
public/js/legacy/widgets/form/form.js View File

@@ -392,10 +392,8 @@ _f.Frm.prototype.refresh = function(docname) {
scroll(0, 0);
this.docname = docname;
}
if(!this.meta.istable) {
cur_frm = this;
this.parent.cur_frm = this;
}

cur_frm = this;
if(this.docname) { // document to show

@@ -613,11 +611,6 @@ _f.Frm.prototype.edit_doc = function() {
this.refresh();
}

_f.Frm.prototype.show_doc = function(dn) {
this.refresh(dn);
}


_f.Frm.prototype.runscript = function(scriptname, callingfield, onrefresh) {
var me = this;
if(this.docname) {


+ 11
- 4
public/js/lib/jQuery.Gantt/css/style.css View File

@@ -33,6 +33,12 @@

/* === LEFT PANEL === */

.fn-gantt * {
-webkit-box-sizing: content-box;
-moz-box-sizing: content-box;
box-sizing: content-box;
}

.fn-gantt .leftPanel {
float: left;
width: 225px;
@@ -42,11 +48,12 @@
z-index: 20;
}

.fn-gantt .row {
.fn-gantt .row, .row .fn-gantt .row {
float: left;
height: 24px;
line-height: 24px;
margin-left: -24px;
margin-right: 0px;
}

.fn-gantt .leftPanel .fn-label {
@@ -84,7 +91,7 @@
}

.fn-gantt .spacer {
margin: -2px 0 1px 0;
margin: -2px 0 1px 0 !important;
border-bottom: none;
background-color: #f6f6f6;
}
@@ -108,11 +115,11 @@
.fn-gantt .day, .fn-gantt .date {
overflow: visible;
width: 24px;
line-height: 24px;
line-height: 23px;
text-align: center;
border-left: 1px solid #DDD;
border-bottom: 1px solid #DDD;
margin: -1px 0 0 -1px;
margin: 0 0 0 -1px !important;
font-size: 11px;
color: #484a4d;
text-shadow: 0 1px 0 rgba(255,255,255,0.75);


+ 254
- 135
public/js/lib/jQuery.Gantt/js/jquery.fn.gantt.js
File diff suppressed because it is too large
View File


+ 13
- 20
public/js/wn/router.js View File

@@ -3,6 +3,8 @@
// re-route map (for rename)
wn.re_route = {};
wn.route_titles = {};
wn.view_factory = {};
wn.view_factories = [];

wn.route = function() {
if(wn.re_route[window.location.hash]) {
@@ -24,28 +26,19 @@ wn.route = function() {

wn._cur_route = window.location.hash;

route = wn.get_route();
route = wn.get_route();
switch (route[0]) {
case "List":
wn.views.doclistview.show(route[1]);
break;
case "Form":
if(route.length>3) {
route[2] = route.splice(2).join('/');
}
wn.views.formview.show(route[1], route[2]);
break;
case "Report":
wn.views.reportview.show();
break;
case "Calendar":
wn.views.calendar.show();
break;
default:
wn.views.pageview.show(route[0]);
if(route[0] && wn.views[route[0] + "Factory"]) {
// has a view generator, generate!
if(!wn.view_factory[route[0]])
wn.view_factory[route[0]] = new wn.views[route[0] + "Factory"]();
wn.view_factory[route[0]].show();
} else {
// show page
wn.views.pageview.show(route[0]);
}

if(wn.route_titles[window.location.hash]) {
document.title = wn.route_titles[window.location.hash];
}


+ 14
- 29
public/js/wn/views/calendar.js View File

@@ -3,27 +3,21 @@

wn.provide("wn.views.calendar");

wn.views.calendar = {
show: function() {
var page_name = wn.get_route_str();
if(wn.pages[page_name]) {
wn.container.change_to(wn.pages[page_name]);
} else {
var route = wn.get_route();
if(route[1]) {
var doctype = route[1];
wn.model.with_doctype(doctype, function() {
var calendar_class = wn.views.calendar[doctype] || wn.views.Calendar;
new calendar_class({
doctype: doctype
});
})
} else {
wn.set_route('404');
}
}
wn.views.CalendarFactory = wn.views.Factory.extend({
make: function(route) {
var me = this;
wn.model.with_doctype(route[1], function() {
var options = {
doctype: route[1],
page: me.make_page()
};
$.extend(options, wn.views.calendar[route[1]] || {});
new wn.views.Calendar(options);
});
}
}
});


wn.views.Calendar = Class.extend({
init: function(options) {
@@ -37,18 +31,9 @@ wn.views.Calendar = Class.extend({
this.make();
},
make_page: function() {
var page_name = wn.get_route_str();
this.page = wn.container.add_page(page_name);
wn.ui.make_app_page({
parent:this.page,
single_column:true
});
wn.container.change_to(page_name);

var module = locals.DocType[this.doctype].module;
this.page.appframe.set_title(wn._("Calendar") + " - " + wn._(this.doctype));
this.page.appframe.add_module_icon(module==="Core" ? "Calendar" : module)

this.page.appframe.set_views_for(this.doctype, "calendar");
},
make: function() {


+ 34
- 3
public/js/wn/views/container.js View File

@@ -48,7 +48,7 @@ wn.views.Container = Class.extend({
// if sent the div, get the table
var page = label;
} else {
var page = wn.pages[label];
var page = wn.pages[label];
}
if(!page) {
console.log(wn._('Page not found')+ ': ' + label);
@@ -72,7 +72,38 @@ wn.views.Container = Class.extend({
this.page._route = window.location.hash;
$(this.page).trigger('show');
scroll(0,0);
scroll(0,0);
return this.page;
}
});
});

wn.views.Factory = Class.extend({
init: function(opts) {
$.extend(this, opts);
},
show: function() {
var page_name = wn.get_route_str(),
me = this;
if(wn.pages[page_name]) {
wn.container.change_to(wn.pages[page_name]);
} else {
var route = wn.get_route();
if(route[1]) {
me.make(route);
} else {
wn.set_route('404');
}
}
},
make_page: function(double_column) {
var page_name = wn.get_route_str(),
page = wn.container.add_page(page_name);

wn.ui.make_app_page({
parent: page,
single_column: !double_column
});
wn.container.change_to(page_name);
return page;
}
})

+ 21
- 32
public/js/wn/views/doclistview.js View File

@@ -4,24 +4,17 @@
wn.provide('wn.views.doclistview');
wn.provide('wn.doclistviews');

wn.views.doclistview.show = function(doctype) {
var route = wn.get_route();
var page_name = "List/" + route[1];
if(wn.pages[page_name]) {
wn.container.change_to(wn.pages[page_name]);
if(wn.container.page.doclistview && wn.container.page.doclistview.dirty)
wn.container.page.doclistview.run();
} else {
if(route[1]) {
wn.model.with_doctype(route[1], function(r) {
if(r && r['403']) {
return;
}
new wn.views.DocListView(route[1]);
wn.views.ListFactory = wn.views.Factory.extend({
make: function(route) {
var me = this;
wn.model.with_doctype(route[1], function() {
new wn.views.DocListView({
doctype: route[1],
page: me.make_page(true)
});
}
});
}
}
});

$(document).on("save", function(event, doc) {
var list_page = "List/" + doc.doctype;
@@ -32,30 +25,28 @@ $(document).on("save", function(event, doc) {
})

wn.views.DocListView = wn.ui.Listing.extend({
init: function(doctype) {
this.doctype = doctype;
this.label = wn._(doctype);
init: function(opts) {
$.extend(this, opts)
this.label = wn._(this.doctype);
this.dirty = true;
this.label = (this.label.toLowerCase().substr(-4) == 'list') ?
wn._(this.label) : (wn._(this.label) + ' ' + wn._('List'));
this.make_page();
this.setup();
var me = this;
$(this.page).on("show", function() {
me.dirty && me.run();
});
},
make_page: function() {
var me = this;
var page_name = "List/" + this.doctype;
var page = wn.container.add_page(page_name);
wn.container.change_to(page_name);
page.doclistview = this;
this.$page = $(page).css({"min-height": "400px"});
this.page.doclistview = this;
this.$page = $(this.page).css({"min-height": "400px"});

wn.dom.set_style(".show-docstatus div { font-size: 90%; }");
wn.ui.make_app_page({
parent: page
})
$('<div class="wnlist-area" style="margin-bottom: 25px;">\
<div class="help">'+wn._('Loading')+'...</div></div>')
.appendTo(this.$page.find(".layout-main-section"));
@@ -71,13 +62,11 @@ wn.views.DocListView = wn.ui.Listing.extend({
</div>')
.appendTo(this.$page.find(".layout-side-section"));
this.appframe = page.appframe;
this.appframe = this.page.appframe;
var module = locals.DocType[this.doctype].module;
this.appframe.set_title(wn._(this.doctype) + " " + wn._("List"));
this.appframe.add_home_breadcrumb();
this.appframe.add_module_icon(module);
this.appframe.add_breadcrumb("icon-list");
this.appframe.set_views_for(this.doctype, "list");
},


+ 45
- 39
public/js/wn/views/formview.js View File

@@ -3,46 +3,52 @@

wn.provide('wn.views.formview');

wn.views.formview = {
show: function(dt, dn) {
// renamed (on save)?
if(wn.model.new_names[dn])
dn = wn.model.new_names[dn];
wn.views.formview.make(dt, dn, true);
wn.views.FormFactory = wn.views.Factory.extend({
make: function(route) {
var me = this,
dt = route[1];

if(!wn.views.formview[dt]) {
me.page = wn.container.add_page("Form/" + dt);
wn.views.formview[dt] = me.page;
wn.model.with_doctype(dt, function() {
me.page.frm = new _f.Frm(dt, me.page, true);
me.show_doc(route);
});
} else {
me.show_doc(route);
}
},
make: function(dt, dn, show) {
// show doctype
wn.model.with_doctype(dt, function() {
wn.model.with_doc(dt, dn, function(dn, r) {
if(r && r['403']) return; // not permitted
if(!(locals[dt] && locals[dt][dn])) {
// doc not found, but starts with New,
// make a new doc and set it
if(dn && dn.substr(0,4)=="New ") {
var new_name = wn.model.make_new_doc_and_get_name(dt);
wn.views.formview.show(dt, new_name);
return;
} else {
wn.set_route('404');
}
return;
}
if(!wn.views.formview[dt]) {
wn.views.formview[dt] = wn.container.add_page('Form - ' + dt);
wn.views.formview[dt].frm = new _f.Frm(dt, wn.views.formview[dt], true);
}
if(show) {
wn.container.change_to('Form - ' + dt);
wn.views.formview[dt].frm.refresh(dn);
show_doc: function(route) {
var dt = route[1],
dn = route[2],
me = this;

if(wn.model.new_names[dn]) {
dn = wn.model.new_names[dn];
wn.set_route("Form", dt, dn);
return;
}

wn.model.with_doc(dt, dn, function(dn, r) {

if(r && r['403']) return; // not permitted
if(!(locals[dt] && locals[dt][dn])) {
// doc not found, but starts with New,
// make a new doc and set it
if(dn && dn.substr(0,4)=="New ") {
var new_name = wn.model.make_new_doc_and_get_name(dt);
wn.set_route("Form", dt, new_name)
} else {
wn.set_route('404');
}
});
return;
}

wn.container.change_to("Form/" + dt);
me.page.frm.refresh(dn);
});
},
create: function(dt) {
var new_name = wn.model.make_new_doc_and_get_name(dt);
wn.set_route('Form', dt, new_name);
}
}
});

+ 109
- 0
public/js/wn/views/ganttview.js View File

@@ -0,0 +1,109 @@
wn.provide("wn.views.calendar");

wn.views.GanttFactory = wn.views.Factory.extend({
make: function(route) {
var me = this;
wn.model.with_doctype(route[1], function() {
var options = {
doctype: route[1],
page: me.make_page()
};
$.extend(options, wn.views.calendar[route[1]] || {});

new wn.views.Gantt(options);
});
}
});

wn.views.Gantt = Class.extend({
init: function(opts) {
$.extend(this, opts);

wn.require('lib/js/lib/jQuery.Gantt/css/style.css');
wn.require('lib/js/lib/jQuery.Gantt/js/jquery.fn.gantt.js');
this.make_page();
this.make_chart();
},
make_page: function() {
var module = locals.DocType[this.doctype].module;
this.page.appframe.set_title(wn._("Gantt Chart") + " - " + wn._(this.doctype));
this.page.appframe.add_module_icon(module)
this.page.appframe.set_views_for(this.doctype, "gantt");
},
make_chart: function() {
var parent = $(this.page)
.find(".layout-main")
.empty()
.css('min-height', '300px')
.html('<div class="alert">Loading...</div>');
var me = this;
wn.call({
method: this.get_events_method,
type: "GET",
args: {
doctype: this.doctype,
start: "2013-01-01",
end: "2014-01-01"
},
callback: function(r) {
$(parent).empty();
if(!r.message.length) {
$(parent).html('<div class="alert">No Tasks Yet.</div>');
} else {
var gantt_area = $('<div class="gantt">').appendTo(parent);
gantt_area.gantt({
source: me.get_source(r),
navigate: "scroll",
scale: "weeks",
minScale: "day",
maxScale: "months",
onItemClick: function(data) {
wn.set_route('Form', me.doctype, data.name);
},
onAddClick: function(dt, rowId) {
newdoc(me.doctype);
}
});
}
}
})
},
get_source: function(r) {
var source = [],
me = this;
// projects
$.each(r.message, function(i,v) {

// standardize values
$.each(me.field_map, function(target, source) {
v[target] = v[source];
});

if(v.start && v.end) {
source.push({
name: v.project || " ",
desc: v.subject,
values: [{
name: v.title,
desc: v.status,
from: '/Date("'+v.start+'")/',
to: '/Date("'+v.end+'")/',
customClass: {
'danger':'ganttRed',
'warning':'ganttOrange',
'info':'ganttBlue',
'success':'ganttGreen',
'':'ganttGray'
}[me.style_map[v.status]],
dataObj: v
}]
})
}
});
return source
}
});

+ 1
- 0
public/js/wn/views/listview.js View File

@@ -20,6 +20,7 @@ wn.views.ListView = Class.extend({
this.settings = wn.listview_settings[this.doctype] || {};
this.set_fields();
this.set_columns();
this.id_list = [];
if(this.settings.group_by)
this.group_by = this.settings.group_by;


+ 0
- 25
public/js/wn/views/load_reportview.js View File

@@ -1,25 +0,0 @@
// Copyright 2013 Web Notes Technologies Pvt Ltd
// License: MIT. See license.txt

// Routing Rules
// --------------
// `Report` shows list of all pages from which you can start a report + all saved reports
// (module wise)
// `Report/[doctype]` shows report for that doctype
// `Report/[doctype]/[report_name]` loads report with that name

wn.views.reportview = {
show: function(dt) {
var page_name = wn.get_route_str();
if(wn.pages[page_name]) {
wn.container.change_to(wn.pages[page_name]);
} else {
var route = wn.get_route();
if(route[1]) {
new wn.views.ReportViewPage(route[1], route[2]);
} else {
wn.set_route('404');
}
}
}
}

+ 6
- 2
public/js/wn/views/reportview.js View File

@@ -1,6 +1,12 @@
// Copyright 2013 Web Notes Technologies Pvt Ltd
// License: MIT. See license.txt

wn.views.ReportFactory = wn.views.Factory.extend({
make: function(route) {
new wn.views.ReportViewPage(route[1], route[2]);
}
});

wn.views.ReportViewPage = Class.extend({
init: function(doctype, docname) {
if(!wn.model.can_get_report(doctype)) {
@@ -38,9 +44,7 @@ wn.views.ReportViewPage = Class.extend({
make_report_view: function() {
var module = locals.DocType[this.doctype].module;
this.page.appframe.set_title(wn._(this.doctype));
this.page.appframe.add_home_breadcrumb()
this.page.appframe.add_module_icon(module)
this.page.appframe.add_breadcrumb("icon-table");
this.page.appframe.set_views_for(this.doctype, "report");

this.page.reportview = new wn.views.ReportView({


Loading…
Cancel
Save