From 0514a1925bb726cc23ae4b99ed85c4b5451357cc Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Sat, 1 Oct 2011 09:54:52 +0200 Subject: [PATCH] choosable first day of week & choosable days of weekend --- apps/calendar/ajax/daysofweekend.php | 11 ++++ apps/calendar/ajax/firstdayofweek.php | 12 ++++ apps/calendar/ajax/geteventinfo.php | 9 --- apps/calendar/ajax/setdaysofweekend.php | 30 +++++++++ apps/calendar/ajax/setfirstdayofweek.php | 16 +++++ apps/calendar/js/calendar.js | 28 +++++--- apps/calendar/js/settings.js | 34 ++++++++++ apps/calendar/templates/calendar.php | 84 ++++++++++++++++++++++-- apps/calendar/templates/settings.php | 25 ++++++- 9 files changed, 224 insertions(+), 25 deletions(-) create mode 100755 apps/calendar/ajax/daysofweekend.php create mode 100755 apps/calendar/ajax/firstdayofweek.php delete mode 100644 apps/calendar/ajax/geteventinfo.php create mode 100755 apps/calendar/ajax/setdaysofweekend.php create mode 100755 apps/calendar/ajax/setfirstdayofweek.php diff --git a/apps/calendar/ajax/daysofweekend.php b/apps/calendar/ajax/daysofweekend.php new file mode 100755 index 0000000000..606d13b1e1 --- /dev/null +++ b/apps/calendar/ajax/daysofweekend.php @@ -0,0 +1,11 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +require_once('../../../lib/base.php'); +OC_JSON::checkLoggedIn(); +echo OC_Preferences::getValue( OC_User::getUser(), 'calendar', 'weekend', '{"Monday":"false","Tuesday":"false","Wednesday":"false","Thursday":"false","Friday":"false","Saturday":"true","Sunday":"true"}'); +?> diff --git a/apps/calendar/ajax/firstdayofweek.php b/apps/calendar/ajax/firstdayofweek.php new file mode 100755 index 0000000000..eff82cece1 --- /dev/null +++ b/apps/calendar/ajax/firstdayofweek.php @@ -0,0 +1,12 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +require_once('../../../lib/base.php'); +OC_JSON::checkLoggedIn(); +$firstdayofweek = OC_Preferences::getValue( OC_User::getUser(), 'calendar', 'firstdayofweek', "1"); +OC_JSON::encodedPrint(array("firstdayofweek" => $firstdayofweek)); +?> \ No newline at end of file diff --git a/apps/calendar/ajax/geteventinfo.php b/apps/calendar/ajax/geteventinfo.php deleted file mode 100644 index 2e5e713c19..0000000000 --- a/apps/calendar/ajax/geteventinfo.php +++ /dev/null @@ -1,9 +0,0 @@ - - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - -?> diff --git a/apps/calendar/ajax/setdaysofweekend.php b/apps/calendar/ajax/setdaysofweekend.php new file mode 100755 index 0000000000..b5ef5f8573 --- /dev/null +++ b/apps/calendar/ajax/setdaysofweekend.php @@ -0,0 +1,30 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +require_once('../../../lib/base.php'); +OC_JSON::checkLoggedIn(); +$weekenddays = array("Monday"=>"false", "Tuesday"=>"false", "Wednesday"=>"false", "Thursday"=>"false", "Friday"=>"false", "Saturday"=>"false", "Sunday"=>"false"); +for($i = 0;$i < count($_POST["weekend"]); $i++){ + switch ($_POST["weekend"][$i]){ + case "Monday": + case "Tuesday": + case "Wednesday": + case "Thursday": + case "Friday": + case "Saturday": + case "Sunday": + break; + default: + OC_JSON::error(); + exit; + } + $weekenddays[$_POST["weekend"][$i]] = "true"; +} +$setValue = json_encode($weekenddays); +OC_Preferences::setValue(OC_User::getUser(), 'calendar', 'weekend', $setValue); +OC_JSON::success(); +?> diff --git a/apps/calendar/ajax/setfirstdayofweek.php b/apps/calendar/ajax/setfirstdayofweek.php new file mode 100755 index 0000000000..571b95af0e --- /dev/null +++ b/apps/calendar/ajax/setfirstdayofweek.php @@ -0,0 +1,16 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +require_once('../../../lib/base.php'); +OC_JSON::checkLoggedIn(); +if(isset($_POST["firstdayofweek"])){ + OC_Preferences::setValue(OC_User::getUser(), 'calendar', 'firstdayofweek', $_POST["firstdayofweek"]); + OC_JSON::success(); +}else{ + OC_JSON::error(); +} +?> diff --git a/apps/calendar/js/calendar.js b/apps/calendar/js/calendar.js index ce45db22fd..554d1f1b0a 100644 --- a/apps/calendar/js/calendar.js +++ b/apps/calendar/js/calendar.js @@ -8,6 +8,8 @@ Calendar={ space:' ', + firstdayofweek: '', + weekend: '', Date:{ normal_year_cal: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], leap_year_cal: [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], @@ -79,7 +81,7 @@ Calendar={ }, UI:{ - weekdays: ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"], + weekdays: '', formatDayShort:function(day){ if (typeof(day) == 'undefined'){ day = Calendar.Date.current.getDay(); @@ -219,7 +221,7 @@ Calendar={ if (!events) { return; } - var weekday = (date.getDay()+6)%7; + var weekday = (date.getDay()+7-Calendar.firstdayofweek)%7; if( typeof (events["allday"]) != "undefined") { var eventnumber = 1; var eventcontainer = this.current.getEventContainer(week, weekday, "allday"); @@ -496,7 +498,7 @@ Calendar={ cancel:function(button, calendarid){ $(button).closest('tr').prev().show().next().remove(); }, - }, + },/* OneDay:{ forward:function(){ Calendar.Date.forward_day(); @@ -526,7 +528,7 @@ Calendar={ return $(document.createElement('p')) .html(time + event['description']) }, - }, + },*/ OneWeek:{ forward:function(){ Calendar.Date.forward_week(); @@ -545,7 +547,7 @@ Calendar={ var dates = this.generateDates(); var today = new Date(); for(var i = 0; i <= 6; i++){ - $("#oneweekview th." + Calendar.UI.weekdays[i]).html(Calendar.UI.formatDayShort((i+1)%7) + Calendar.space + dates[i].getDate() + Calendar.space + Calendar.UI.formatMonthShort(dates[i].getMonth())); + $("#oneweekview th." + Calendar.UI.weekdays[i]).html(Calendar.UI.formatDayShort((i+Calendar.firstdayofweek)%7) + Calendar.space + dates[i].getDate() + Calendar.space + Calendar.UI.formatMonthShort(dates[i].getMonth())); if(dates[i].getDate() == today.getDate() && dates[i].getMonth() == today.getMonth() && dates[i].getFullYear() == today.getFullYear()){ $("#oneweekview ." + Calendar.UI.weekdays[i]).addClass("thisday"); } @@ -576,14 +578,18 @@ Calendar={ if(dayofweek == 0) { dayofweek = 7; } - date.setDate(date.getDate() - dayofweek + 1); + if(Calendar.firstdayofweek > dayofweek){ + date.setDate(date.getDate() - dayofweek + Calendar.firstdayofweek - 7); + }else{ + date.setDate(date.getDate() - dayofweek + Calendar.firstdayofweek); + } for(var i = 0; i <= 6; i++) { dates[i] = new Date(date) date.setDate(date.getDate() + 1); } return dates; }, - }, + },/* FourWeeks:{ forward:function(){ Calendar.Date.forward_week(); @@ -680,7 +686,7 @@ Calendar={ } return dates; }, - }, + },*/ OneMonth:{ forward:function(){ Calendar.Date.forward_month(); @@ -782,7 +788,11 @@ Calendar={ dayofweek = 7; this.rows++; } - date.setDate(date.getDate() - dayofweek + 1); + if(Calendar.firstdayofweek > dayofweek){ + date.setDate(date.getDate() - dayofweek + Calendar.firstdayofweek - 7); + }else{ + date.setDate(date.getDate() - dayofweek + Calendar.firstdayofweek); + } for(var i = 0; i <= 41; i++) { dates[i] = new Date(date) date.setDate(date.getDate() + 1); diff --git a/apps/calendar/js/settings.js b/apps/calendar/js/settings.js index 7c24fb0963..5d048b83c3 100644 --- a/apps/calendar/js/settings.js +++ b/apps/calendar/js/settings.js @@ -8,4 +8,38 @@ $(document).ready(function(){ }); return false; }); + $("#timezone").chosen(); + $("#firstdayofweek").change( function(){ + var data = $("#firstdayofweek").serialize(); + $.post( OC.filePath('calendar', 'ajax', 'setfirstdayofweek.php'), data, function(data){ + if(data == "error"){ + console.log("saving first day of week failed"); + } + }); + }); + $.getJSON(OC.filePath('calendar', 'ajax', 'firstdayofweek.php'), function(jsondata, status) { + $("#select_" + jsondata.firstdayofweek).attr('selected',true); + $("#firstdayofweek").chosen(); + }); + $.getJSON(OC.filePath('calendar', 'ajax', 'daysofweekend.php'), function(jsondata, status) { + for(day in jsondata){ + if(jsondata[day] == "true"){ + $("#selectweekend_" + day).attr('selected',true); + } + } + $("#weekend").multiselect({ + header: false, + noneSelectedText: $('#weekend').attr('title'), + selectedList: 2, + minWidth:'auto', + }); + }); + $("#weekend").change( function(){ + var data = $("#weekend").serialize(); + $.post( OC.filePath('calendar', 'ajax', 'setdaysofweekend.php'), data, function(data){ + if(data == "error"){ + console.log("saving days of weekend failed"); + } + }); + }); }); diff --git a/apps/calendar/templates/calendar.php b/apps/calendar/templates/calendar.php index a185d3e708..25d92b0c7e 100644 --- a/apps/calendar/templates/calendar.php +++ b/apps/calendar/templates/calendar.php @@ -26,9 +26,82 @@ $hours = array( 22 => '22', 23 => '23', ); -$weekdays = array('monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'); +/* +$hours24 = array( + 'allday' => $l->t('All day'), + 0 => '0', + 1 => '1', + 2 => '2', + 3 => '3', + 4 => '4', + 5 => '5', + 6 => '6', + 7 => '7', + 8 => '8', + 9 => '9', + 10 => '10', + 11 => '11', + 12 => '12', + 13 => '13', + 14 => '14', + 15 => '15', + 16 => '16', + 17 => '17', + 18 => '18', + 19 => '19', + 20 => '20', + 21 => '21', + 22 => '22', + 23 => '23', +); +$hoursampm = array( + 'allday' => $l->t('All day'), + 0 => '12 a.m.', + 1 => '1 a.m.', + 2 => '2 a.m.', + 3 => '3 a.m.', + 4 => '4 a.m.', + 5 => '5 a.m.', + 6 => '6 a.m.', + 7 => '7 a.m.', + 8 => '8 a.m.', + 9 => '9 a.m.', + 10 => '10 a.m.', + 11 => '11 a.m.', + 12 => '12 p.m.', + 13 => '1 p.m.', + 14 => '2 p.m.', + 15 => '3 p.m.', + 16 => '4 p.m.', + 17 => '5 p.m.', + 18 => '6 p.m.', + 19 => '7 p.m.', + 20 => '8 p.m.', + 21 => '9 p.m.', + 22 => '10 p.m.', + 23 => '11 p.m.', +); +*/ +$weekdaynames = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'); +$dayforgenerator = OC_Preferences::getValue( OC_User::getUser(), 'calendar', 'firstdayofweek', "1"); +$weekdays = array(); +for($i = 0;$i <= 6; $i++){ + $weekdays[$i] = $weekdaynames[$dayforgenerator]; + if($dayforgenerator == 6){ + $dayforgenerator = 0; + }else{ + $dayforgenerator++; + } +} +$weekendjson = OC_Preferences::getValue( OC_User::getUser(), 'calendar', 'weekend', '{"Monday":"false","Tuesday":"false","Wednesday":"false","Thursday":"false","Friday":"false","Saturday":"true","Sunday":"true"}'); +$weekend = json_decode($weekendjson, true); +$weekenddays = array("sunday"=>$weekend["Sunday"], "monday"=>$weekend["Monday"], "tuesday"=>$weekend["Tuesday"], "wednesday"=>$weekend["Wednesday"], "thursday"=>$weekend["Thursday"], "friday"=>$weekend["Friday"], "saturday"=>$weekend["Saturday"]); ?>