瀏覽代碼

List renderer

- load_last_view
- refresh calendar view on route change
version-14
Faris Ansari 7 年之前
父節點
當前提交
8c291c9b20
共有 4 個檔案被更改,包括 46 行新增8 行删除
  1. +7
    -0
      frappe/public/js/frappe/list/list_renderer.js
  2. +2
    -2
      frappe/public/js/frappe/list/list_sidebar.js
  3. +7
    -0
      frappe/public/js/frappe/list/list_view.js
  4. +30
    -6
      frappe/public/js/frappe/views/calendar/calendar.js

+ 7
- 0
frappe/public/js/frappe/list/list_renderer.js 查看文件

@@ -74,6 +74,13 @@ frappe.views.ListRenderer = Class.extend({
should_refresh: function() {
return this.list_view.current_view !== this.list_view.last_view;
},
load_last_view: function() {
// this function should handle loading the last view of your list_renderer,
// If you have a last view (for e.g last kanban board in Kanban View),
// load it using frappe.set_route and return true
// else return false
return false;
},
set_wrapper: function () {
this.wrapper = this.list_view.wrapper && this.list_view.wrapper.find('.result-list');
},


+ 2
- 2
frappe/public/js/frappe/list/list_sidebar.js 查看文件

@@ -288,7 +288,7 @@ frappe.views.ListSidebar = Class.extend({
let default_link = '';
if (frappe.views.calendar[this.doctype]) {
// has standard calendar view
default_link = `<li><a href="#List/${doctype}/Calendar">${ __("Default") }</a></li>`
default_link = `<li><a href="#List/${doctype}/Calendar/Default">${ __("Default") }</a></li>`
}
const other_links = calendar_views.map(
calendar_view => `<li><a href="#List/${doctype}/Calendar/${calendar_view.name}">
@@ -307,7 +307,7 @@ frappe.views.ListSidebar = Class.extend({
</ul>
</div>
`;
$link_calendar.removeClass('hide');
$link_calendar.html(dropdown_html);
});
},


+ 7
- 0
frappe/public/js/frappe/list/list_view.js 查看文件

@@ -399,6 +399,13 @@ frappe.views.ListView = frappe.ui.BaseList.extend({

if (this.list_renderer.should_refresh()) {
this.setup_list_renderer();

if (this.list_renderer.load_last_view && this.list_renderer.load_last_view()) {
// let the list_renderer load the last view for the current view
// for e.g last kanban board for kanban view
return;
}

this.refresh_surroundings();
this.dirty = true;
}


+ 30
- 6
frappe/public/js/frappe/views/calendar/calendar.js 查看文件

@@ -13,6 +13,21 @@ frappe.views.CalendarView = frappe.views.ListRenderer.extend({
this.calendar = new frappe.views.Calendar(options);
});
},
load_last_view: function() {
const route = frappe.get_route();

if (!route[3]) {
// routed to Calendar view, check last calendar_view
let calendar_view = this.user_settings.last_calendar_view;

if (calendar_view) {
frappe.set_route('List', this.doctype, 'Calendar', calendar_view);
return true;
}
}

return false;
},
set_defaults: function() {
this._super();
this.page_title = this.page_title + ' ' + __('Calendar');
@@ -23,12 +38,22 @@ frappe.views.CalendarView = frappe.views.ListRenderer.extend({
get_header_html: function() {
return null;
},
get_calendar_options: function() {
let calendar_view = this.user_settings.last_calendar_view;

if (!calendar_view) {
calendar_view = frappe.get_route()[3] || 'Default';
should_refresh: function() {
var should_refresh = this._super();
if(!should_refresh) {
this.last_calendar_view = this.current_calendar_view || '';
this.current_calendar_view = this.get_calendar_view();
this.page_title = __(this.get_calendar_view());

should_refresh = this.current_calendar_view !== this.last_calendar_view;
}
return should_refresh;
},
get_calendar_view: function() {
return frappe.get_route()[3];
},
get_calendar_options: function() {
const calendar_view = frappe.get_route()[3] || 'Default';

// save in user_settings
frappe.model.user_settings.save(this.doctype, 'Calendar', {
@@ -164,7 +189,6 @@ frappe.views.Calendar = Class.extend({
args: me.get_args(start, end),
callback: function(r) {
var events = r.message;
console.log(events);
events = me.prepare_events(events);
callback(events);
}


Loading…
取消
儲存