Rushabh Mehta | b73fa49 | 2012-02-24 15:07:39 +0530 | [diff] [blame] | 1 | // Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com) |
| 2 | // |
| 3 | // MIT License (MIT) |
| 4 | // |
| 5 | // Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | // copy of this software and associated documentation files (the "Software"), |
| 7 | // to deal in the Software without restriction, including without limitation |
| 8 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 | // and/or sell copies of the Software, and to permit persons to whom the |
| 10 | // Software is furnished to do so, subject to the following conditions: |
| 11 | // |
| 12 | // The above copyright notice and this permission notice shall be included in |
| 13 | // all copies or substantial portions of the Software. |
| 14 | // |
| 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
| 16 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A |
| 17 | // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 18 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
| 19 | // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE |
| 20 | // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 21 | // |
| 22 | |
| 23 | pscript.onload_calendar = function(wrapper) { |
Rushabh Mehta | 5eb3764 | 2013-02-14 17:34:51 +0530 | [diff] [blame] | 24 | wn.ui.make_app_page({ |
| 25 | parent: wrapper, |
| 26 | single_column: true, |
| 27 | title: 'Calendar' |
| 28 | }); |
Rushabh Mehta | b73fa49 | 2012-02-24 15:07:39 +0530 | [diff] [blame] | 29 | |
Rushabh Mehta | 5eb3764 | 2013-02-14 17:34:51 +0530 | [diff] [blame] | 30 | wn.require('lib/js/lib/fullcalendar/fullcalendar.css'); |
| 31 | wn.require('lib/js/lib/fullcalendar/fullcalendar.js'); |
Rushabh Mehta | b73fa49 | 2012-02-24 15:07:39 +0530 | [diff] [blame] | 32 | } |
| 33 | |
Rushabh Mehta | 5eb3764 | 2013-02-14 17:34:51 +0530 | [diff] [blame] | 34 | pscript.update_event = function(event) { |
| 35 | wn.model.remove_from_locals("Event", event.id); |
| 36 | wn.call({ |
| 37 | module: "utilities", |
| 38 | page: "calendar", |
| 39 | method: "update_event", |
| 40 | args: { |
| 41 | "start": wn.datetime.get_datetime_as_string(event.start), |
| 42 | "end": wn.datetime.get_datetime_as_string(event.end), |
| 43 | "name": event.id |
| 44 | }, |
| 45 | callback: function(r) { |
| 46 | if(r.exc) { |
| 47 | show_alert("Unable to update event.") |
Rushabh Mehta | b73fa49 | 2012-02-24 15:07:39 +0530 | [diff] [blame] | 48 | } |
| 49 | } |
Rushabh Mehta | 5eb3764 | 2013-02-14 17:34:51 +0530 | [diff] [blame] | 50 | }); |
Rushabh Mehta | b73fa49 | 2012-02-24 15:07:39 +0530 | [diff] [blame] | 51 | } |
| 52 | |
Rushabh Mehta | b73fa49 | 2012-02-24 15:07:39 +0530 | [diff] [blame] | 53 | |
Rushabh Mehta | 5eb3764 | 2013-02-14 17:34:51 +0530 | [diff] [blame] | 54 | pscript.onshow_calendar = function(wrapper) { |
| 55 | if(!wrapper.setup_complete) { |
| 56 | $('<div id="fullcalendar">').appendTo($(wrapper).find('.layout-main')).fullCalendar({ |
| 57 | header: { |
| 58 | left: 'prev,next today', |
| 59 | center: 'title', |
| 60 | right: 'month,agendaWeek,agendaDay' |
| 61 | }, |
| 62 | editable: true, |
| 63 | events: function(start, end, callback) { |
| 64 | wn.call({ |
| 65 | method: 'utilities.page.calendar.calendar.get_events', |
| 66 | type: "GET", |
| 67 | args: { |
| 68 | start: dateutil.obj_to_str(start), |
| 69 | end: dateutil.obj_to_str(end) |
| 70 | }, |
| 71 | callback: function(r) { |
| 72 | var events = r.message; |
| 73 | $.each(events, function(i, d) { |
| 74 | d.editable = d.owner==user; |
| 75 | d.allDay = false; |
| 76 | }); |
| 77 | callback(events); |
Rushabh Mehta | b73fa49 | 2012-02-24 15:07:39 +0530 | [diff] [blame] | 78 | } |
Rushabh Mehta | 5eb3764 | 2013-02-14 17:34:51 +0530 | [diff] [blame] | 79 | }) |
| 80 | }, |
| 81 | dayClick: function(date, allDay, jsEvent, view) { |
| 82 | // if current date, show popup to create a new event |
| 83 | var ev = wn.model.create('Event') |
| 84 | ev.doc.set('start', date); |
| 85 | ev.doc.set('end', new Date(date)); |
| 86 | ev.doc.set('all_day', 1); |
Rushabh Mehta | b73fa49 | 2012-02-24 15:07:39 +0530 | [diff] [blame] | 87 | |
Rushabh Mehta | 5eb3764 | 2013-02-14 17:34:51 +0530 | [diff] [blame] | 88 | }, |
| 89 | eventClick: function(calEvent, jsEvent, view) { |
| 90 | // edit event description or delete |
| 91 | wn.set_route("Form", "Event", calEvent.id); |
| 92 | }, |
| 93 | eventDrop: function(event, dayDelta, minuteDelta, allDay, revertFunc) { |
| 94 | pscript.update_event(event); |
| 95 | }, |
| 96 | eventResize: function(event, dayDelta, minuteDelta, allDay, revertFunc) { |
| 97 | pscript.update_event(event); |
Rushabh Mehta | b73fa49 | 2012-02-24 15:07:39 +0530 | [diff] [blame] | 98 | } |
Rushabh Mehta | 5eb3764 | 2013-02-14 17:34:51 +0530 | [diff] [blame] | 99 | }); |
Rushabh Mehta | b73fa49 | 2012-02-24 15:07:39 +0530 | [diff] [blame] | 100 | |
Rushabh Mehta | 5eb3764 | 2013-02-14 17:34:51 +0530 | [diff] [blame] | 101 | wrapper.setup_complete = true; |
| 102 | } else { |
| 103 | $("#fullcalendar").fullCalendar("refetchEvents"); |
Rushabh Mehta | b73fa49 | 2012-02-24 15:07:39 +0530 | [diff] [blame] | 104 | } |
| 105 | } |
| 106 | |