@@ -74,6 +74,13 @@ frappe.views.ListRenderer = Class.extend({ | |||||
should_refresh: function() { | should_refresh: function() { | ||||
return this.list_view.current_view !== this.list_view.last_view; | 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 () { | set_wrapper: function () { | ||||
this.wrapper = this.list_view.wrapper && this.list_view.wrapper.find('.result-list'); | this.wrapper = this.list_view.wrapper && this.list_view.wrapper.find('.result-list'); | ||||
}, | }, | ||||
@@ -288,7 +288,7 @@ frappe.views.ListSidebar = Class.extend({ | |||||
let default_link = ''; | let default_link = ''; | ||||
if (frappe.views.calendar[this.doctype]) { | if (frappe.views.calendar[this.doctype]) { | ||||
// has standard calendar view | // 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( | const other_links = calendar_views.map( | ||||
calendar_view => `<li><a href="#List/${doctype}/Calendar/${calendar_view.name}"> | calendar_view => `<li><a href="#List/${doctype}/Calendar/${calendar_view.name}"> | ||||
@@ -307,7 +307,7 @@ frappe.views.ListSidebar = Class.extend({ | |||||
</ul> | </ul> | ||||
</div> | </div> | ||||
`; | `; | ||||
$link_calendar.removeClass('hide'); | |||||
$link_calendar.html(dropdown_html); | $link_calendar.html(dropdown_html); | ||||
}); | }); | ||||
}, | }, | ||||
@@ -399,6 +399,13 @@ frappe.views.ListView = frappe.ui.BaseList.extend({ | |||||
if (this.list_renderer.should_refresh()) { | if (this.list_renderer.should_refresh()) { | ||||
this.setup_list_renderer(); | 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.refresh_surroundings(); | ||||
this.dirty = true; | this.dirty = true; | ||||
} | } | ||||
@@ -13,6 +13,21 @@ frappe.views.CalendarView = frappe.views.ListRenderer.extend({ | |||||
this.calendar = new frappe.views.Calendar(options); | 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() { | set_defaults: function() { | ||||
this._super(); | this._super(); | ||||
this.page_title = this.page_title + ' ' + __('Calendar'); | this.page_title = this.page_title + ' ' + __('Calendar'); | ||||
@@ -23,12 +38,22 @@ frappe.views.CalendarView = frappe.views.ListRenderer.extend({ | |||||
get_header_html: function() { | get_header_html: function() { | ||||
return null; | 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 | // save in user_settings | ||||
frappe.model.user_settings.save(this.doctype, 'Calendar', { | frappe.model.user_settings.save(this.doctype, 'Calendar', { | ||||
@@ -164,7 +189,6 @@ frappe.views.Calendar = Class.extend({ | |||||
args: me.get_args(start, end), | args: me.get_args(start, end), | ||||
callback: function(r) { | callback: function(r) { | ||||
var events = r.message; | var events = r.message; | ||||
console.log(events); | |||||
events = me.prepare_events(events); | events = me.prepare_events(events); | ||||
callback(events); | callback(events); | ||||
} | } | ||||