diff options
author | Georg Ehrke <dev@georgswebsite.de> | 2012-04-13 16:42:10 -0400 |
---|---|---|
committer | Georg Ehrke <dev@georgswebsite.de> | 2012-04-13 16:42:10 -0400 |
commit | 77a9e343aae4fc19a1e6fbf71b73e171640ac02a (patch) | |
tree | 3d110503a333595b1d7c233ae903dcc79e5f664e /apps/calendar | |
parent | 613e15035e3f02a212c9f3ec11ae98fc3ef682c8 (diff) | |
parent | b9f9228a22944184803a8835282862e468812c1d (diff) | |
download | nextcloud-server-77a9e343aae4fc19a1e6fbf71b73e171640ac02a.tar.gz nextcloud-server-77a9e343aae4fc19a1e6fbf71b73e171640ac02a.zip |
Merge branch 'master' into sabredav_1.6
Diffstat (limited to 'apps/calendar')
-rw-r--r-- | apps/calendar/ajax/categories/rescan.php | 42 | ||||
-rw-r--r-- | apps/calendar/ajax/event/edit.form.php | 20 | ||||
-rw-r--r-- | apps/calendar/ajax/event/new.form.php | 3 | ||||
-rw-r--r-- | apps/calendar/index.php | 4 | ||||
-rw-r--r-- | apps/calendar/js/calendar.js | 15 | ||||
-rw-r--r-- | apps/calendar/lib/app.php | 51 | ||||
-rw-r--r-- | apps/calendar/lib/calendar.php | 4 | ||||
-rw-r--r-- | apps/calendar/lib/object.php | 31 | ||||
-rwxr-xr-x | apps/calendar/templates/calendar.php | 1 | ||||
-rw-r--r-- | apps/calendar/templates/part.eventform.php | 8 |
10 files changed, 122 insertions, 57 deletions
diff --git a/apps/calendar/ajax/categories/rescan.php b/apps/calendar/ajax/categories/rescan.php new file mode 100644 index 00000000000..0fd878ed8f9 --- /dev/null +++ b/apps/calendar/ajax/categories/rescan.php @@ -0,0 +1,42 @@ +<?php +/** + * Copyright (c) 2012 Thomas Tanghus <thomas@tanghus.net> + * 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(); +OC_JSON::checkAppEnabled('calendar'); + +foreach ($_POST as $key=>$element) { + debug('_POST: '.$key.'=>'.print_r($element, true)); +} + +function bailOut($msg) { + OC_JSON::error(array('data' => array('message' => $msg))); + OC_Log::write('calendar','ajax/categories/rescan.php: '.$msg, OC_Log::DEBUG); + exit(); +} +function debug($msg) { + OC_Log::write('calendar','ajax/categories/rescan.php: '.$msg, OC_Log::DEBUG); +} + +$calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser()); +if(count($calendars) == 0) { + bailOut(OC_Calendar_App::$l10n->t('No calendars found.')); +} +$events = array(); +foreach($calendars as $calendar) { + $calendar_events = OC_Calendar_Object::all($calendar['id']); + $events = $events + $calendar_events; +} +if(count($events) == 0) { + bailOut(OC_Calendar_App::$l10n->t('No events found.')); +} + +OC_Calendar_App::scanCategories($events); +$categories = OC_Calendar_App::getCategoryOptions(); + +OC_JSON::success(array('data' => array('categories'=>$categories))); diff --git a/apps/calendar/ajax/event/edit.form.php b/apps/calendar/ajax/event/edit.form.php index 7371577dcfe..7cbf3a87cfc 100644 --- a/apps/calendar/ajax/event/edit.form.php +++ b/apps/calendar/ajax/event/edit.form.php @@ -41,13 +41,8 @@ switch($dtstart->getDateType()) { $summary = $vevent->getAsString('SUMMARY'); $location = $vevent->getAsString('LOCATION'); -$categories = $vevent->getAsArray('CATEGORIES'); +$categories = $vevent->getAsString('CATEGORIES'); $description = $vevent->getAsString('DESCRIPTION'); -foreach($categories as $category){ - if (!in_array($category, $category_options)){ - array_unshift($category_options, $category); - } -} $last_modified = $vevent->__get('LAST-MODIFIED'); if ($last_modified){ $lastmodified = $last_modified->getDateTime()->format('U'); @@ -189,7 +184,6 @@ if($data['repeating'] == 1){ } $calendar_options = OC_Calendar_Calendar::allCalendars(OC_User::getUser()); -$category_options = OC_Calendar_App::getCategoryOptions(); $repeat_options = OC_Calendar_App::getRepeatOptions(); $repeat_end_options = OC_Calendar_App::getEndOptions(); $repeat_month_options = OC_Calendar_App::getMonthOptions(); @@ -205,7 +199,6 @@ $tmpl = new OC_Template('calendar', 'part.editevent'); $tmpl->assign('id', $id); $tmpl->assign('lastmodified', $lastmodified); $tmpl->assign('calendar_options', $calendar_options); -$tmpl->assign('category_options', $category_options); $tmpl->assign('repeat_options', $repeat_options); $tmpl->assign('repeat_month_options', $repeat_month_options); $tmpl->assign('repeat_weekly_options', $repeat_weekly_options); @@ -242,7 +235,14 @@ if($repeat['repeat'] != 'doesnotrepeat'){ $tmpl->assign('repeat_bymonthday', $repeat['bymonthday']); $tmpl->assign('repeat_bymonth', $repeat['bymonth']); $tmpl->assign('repeat_byweekno', $repeat['byweekno']); +} else { + $tmpl->assign('repeat_month', 'monthday'); + $tmpl->assign('repeat_weekdays', array()); + $tmpl->assign('repeat_interval', 1); + $tmpl->assign('repeat_end', 'never'); + $tmpl->assign('repeat_count', '10'); + $tmpl->assign('repeat_weekofmonth', 'auto'); + $tmpl->assign('repeat_date', ''); + $tmpl->assign('repeat_year', 'bydate'); } $tmpl->printpage(); - -?>
\ No newline at end of file diff --git a/apps/calendar/ajax/event/new.form.php b/apps/calendar/ajax/event/new.form.php index c19928a727e..838002a3a09 100644 --- a/apps/calendar/ajax/event/new.form.php +++ b/apps/calendar/ajax/event/new.form.php @@ -32,7 +32,6 @@ $start->setTimezone(new DateTimeZone($timezone)); $end->setTimezone(new DateTimeZone($timezone)); $calendar_options = OC_Calendar_Calendar::allCalendars(OC_User::getUser()); -$category_options = OC_Calendar_App::getCategoryOptions(); $repeat_options = OC_Calendar_App::getRepeatOptions(); $repeat_end_options = OC_Calendar_App::getEndOptions(); $repeat_month_options = OC_Calendar_App::getMonthOptions(); @@ -46,7 +45,6 @@ $repeat_bymonthday_options = OC_Calendar_App::getByMonthDayOptions(); $tmpl = new OC_Template('calendar', 'part.newevent'); $tmpl->assign('calendar_options', $calendar_options); -$tmpl->assign('category_options', $category_options); $tmpl->assign('repeat_options', $repeat_options); $tmpl->assign('repeat_month_options', $repeat_month_options); $tmpl->assign('repeat_weekly_options', $repeat_weekly_options); @@ -73,4 +71,3 @@ $tmpl->assign('repeat_weekofmonth', 'auto'); $tmpl->assign('repeat_date', ''); $tmpl->assign('repeat_year', 'bydate'); $tmpl->printpage(); -?> diff --git a/apps/calendar/index.php b/apps/calendar/index.php index c00a4098f7a..f964a13ef79 100644 --- a/apps/calendar/index.php +++ b/apps/calendar/index.php @@ -22,6 +22,7 @@ foreach($calendars as $calendar){ $eventSources[] = OC_Calendar_Calendar::getEventSourceInfo($calendar); } OC_Hook::emit('OC_Calendar', 'getSources', array('sources' => &$eventSources)); +$categories = OC_Calendar_App::getCategoryOptions(); //Fix currentview for fullcalendar if(OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'currentview', 'month') == "oneweekview"){ @@ -45,9 +46,12 @@ OC_Util::addScript('calendar', 'calendar'); OC_Util::addStyle('calendar', 'style'); OC_Util::addScript('', 'jquery.multiselect'); OC_Util::addStyle('', 'jquery.multiselect'); +OC_Util::addScript('contacts','jquery.multi-autocomplete'); +OC_Util::addScript('','oc-vcategories'); OC_App::setActiveNavigationEntry('calendar_index'); $tmpl = new OC_Template('calendar', 'calendar', 'user'); $tmpl->assign('eventSources', $eventSources); +$tmpl->assign('categories', $categories); if(array_key_exists('showevent', $_GET)){ $tmpl->assign('showevent', $_GET['showevent']); } diff --git a/apps/calendar/js/calendar.js b/apps/calendar/js/calendar.js index 907d94edb02..858990fb89d 100644 --- a/apps/calendar/js/calendar.js +++ b/apps/calendar/js/calendar.js @@ -32,13 +32,7 @@ Calendar={ $('#totime').timepicker({ showPeriodLabels: false }); - $('#category').multiselect({ - header: false, - noneSelectedText: $('#category').attr('title'), - selectedList: 2, - minWidth:'auto', - classes: 'category', - }); + $('#category').multiple_autocomplete({source: categories}); Calendar.UI.repeat('init'); $('#end').change(function(){ Calendar.UI.repeat('end'); @@ -370,6 +364,11 @@ Calendar={ } $('#'+id).addClass('active'); }, + categoriesChanged:function(newcategories){ + categories = $.map(newcategories, function(v) {return v;}); + console.log('Calendar categories changed to: ' + categories); + $('#category').multiple_autocomplete('option', 'source', categories); + }, Calendar:{ overview:function(){ if($('#choosecalendar_dialog').dialog('isOpen') == true){ @@ -730,6 +729,8 @@ $(document).ready(function(){ loading: Calendar.UI.loading, eventSources: eventSources }); + OCCategories.changed = Calendar.UI.categoriesChanged; + OCCategories.app = 'calendar'; $('#oneweekview_radio').click(function(){ $('#calendar_holder').fullCalendar('changeView', 'agendaWeek'); }); diff --git a/apps/calendar/lib/app.php b/apps/calendar/lib/app.php index 6e92cf67c5c..22c1133e006 100644 --- a/apps/calendar/lib/app.php +++ b/apps/calendar/lib/app.php @@ -12,6 +12,7 @@ OC_Calendar_App::$l10n = new OC_L10N('calendar'); class OC_Calendar_App{ public static $l10n; + protected static $categories = null; public static function getCalendar($id){ $calendar = OC_Calendar_Calendar::find( $id ); @@ -54,7 +55,7 @@ class OC_Calendar_App{ } } - public static function getCategoryOptions() + protected static function getDefaultCategories() { return array( self::$l10n->t('Birthday'), @@ -75,6 +76,54 @@ class OC_Calendar_App{ ); } + protected static function getVCategories() { + if (is_null(self::$categories)) { + self::$categories = new OC_VCategories('calendar', null, self::getDefaultCategories()); + } + return self::$categories; + } + + public static function getCategoryOptions() + { + $categories = self::getVCategories()->categories(); + return $categories; + } + + /** + * scan events for categories. + * @param $events VEVENTs to scan. null to check all events for the current user. + */ + public static function scanCategories($events = null) { + if (is_null($events)) { + $calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser()); + if(count($calendars) > 0) { + $events = array(); + foreach($calendars as $calendar) { + $calendar_events = OC_Calendar_Object::all($calendar['id']); + $events = $events + $calendar_events; + } + } + } + if(is_array($events) && count($events) > 0) { + $vcategories = self::getVCategories(); + $vcategories->delete($vcategories->categories()); + foreach($events as $event) { + $vobject = OC_VObject::parse($event['calendardata']); + if(!is_null($vobject)) { + $vcategories->loadFromVObject($vobject->VEVENT, true); + } + } + } + } + + /** + * check VEvent for new categories. + * @see OC_VCategories::loadFromVObject + */ + public static function loadCategoriesFromVCalendar(OC_VObject $calendar) { + self::getVCategories()->loadFromVObject($calendar->VEVENT, true); + } + public static function getRepeatOptions(){ return OC_Calendar_Object::getRepeatOptions(self::$l10n); } diff --git a/apps/calendar/lib/calendar.php b/apps/calendar/lib/calendar.php index 7eeb004d181..321f4c73ba0 100644 --- a/apps/calendar/lib/calendar.php +++ b/apps/calendar/lib/calendar.php @@ -44,10 +44,8 @@ class OC_Calendar_Calendar{ /** * @brief Returns the list of calendars for a specific user. * @param string $uid User ID - * @param boolean $active + * @param boolean $active Only return calendars with this $active state, default(=null) is don't care * @return array - * - * TODO: what is active for? */ public static function allCalendars($uid, $active=null){ $values = array($uid); diff --git a/apps/calendar/lib/object.php b/apps/calendar/lib/object.php index a471aa84034..9b6554a3e25 100644 --- a/apps/calendar/lib/object.php +++ b/apps/calendar/lib/object.php @@ -93,6 +93,7 @@ class OC_Calendar_Object{ */ public static function add($id,$data){ $object = OC_VObject::parse($data); + OC_Calendar_App::loadCategoriesFromVCalendar($object); list($type,$startdate,$enddate,$summary,$repeating,$uid) = self::extractData($object); if(is_null($uid)){ @@ -139,6 +140,7 @@ class OC_Calendar_Object{ $oldobject = self::find($id); $object = OC_VObject::parse($data); + OC_Calendar_App::loadCategoriesFromVCalendar($object); list($type,$startdate,$enddate,$summary,$repeating,$uid) = self::extractData($object); $stmt = OC_DB::prepare( 'UPDATE *PREFIX*calendar_objects SET objecttype=?,startdate=?,enddate=?,repeating=?,summary=?,calendardata=?, lastmodified = ? WHERE id = ?' ); @@ -320,27 +322,6 @@ class OC_Calendar_Object{ return $dtend; } - public static function getCategoryOptions($l10n) - { - return array( - $l10n->t('Birthday'), - $l10n->t('Business'), - $l10n->t('Call'), - $l10n->t('Clients'), - $l10n->t('Deliverer'), - $l10n->t('Holidays'), - $l10n->t('Ideas'), - $l10n->t('Journey'), - $l10n->t('Jubilee'), - $l10n->t('Meeting'), - $l10n->t('Other'), - $l10n->t('Personal'), - $l10n->t('Projects'), - $l10n->t('Questions'), - $l10n->t('Work'), - ); - } - public static function getRepeatOptions($l10n) { return array( @@ -457,10 +438,6 @@ class OC_Calendar_Object{ $errnum++; } - if(isset($request['categories']) && !is_array($request['categories'])){ - $errors['categories'] = $l10n->t('Not an array'); - } - $fromday = substr($request['from'], 0, 2); $frommonth = substr($request['from'], 3, 2); $fromyear = substr($request['from'], 6, 4); @@ -628,7 +605,7 @@ class OC_Calendar_Object{ { $title = $request["title"]; $location = $request["location"]; - $categories = isset($request["categories"]) ? $request["categories"] : array(); + $categories = $request["categories"]; $allday = isset($request["allday"]); $from = $request["from"]; $to = $request["to"]; @@ -802,7 +779,7 @@ class OC_Calendar_Object{ $vevent->setString('LOCATION', $location); $vevent->setString('DESCRIPTION', $description); - $vevent->setString('CATEGORIES', join(',', $categories)); + $vevent->setString('CATEGORIES', $categories); /*if($repeat == "true"){ $vevent->RRULE = $repeat; diff --git a/apps/calendar/templates/calendar.php b/apps/calendar/templates/calendar.php index 63c3b500296..ba9423a66f1 100755 --- a/apps/calendar/templates/calendar.php +++ b/apps/calendar/templates/calendar.php @@ -1,6 +1,7 @@ <script type='text/javascript'> var defaultView = '<?php echo OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'currentview', 'month') ?>'; var eventSources = <?php echo json_encode($_['eventSources']) ?>; + var categories = <?php echo json_encode($_['categories']); ?>; var dayNames = <?php echo json_encode($l->tA(array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'))) ?>; var dayNamesShort = <?php echo json_encode($l->tA(array('Sun.', 'Mon.', 'Tue.', 'Wed.', 'Thu.', 'Fri.', 'Sat.'))) ?>; var monthNames = <?php echo json_encode($l->tA(array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'))) ?>; diff --git a/apps/calendar/templates/part.eventform.php b/apps/calendar/templates/part.eventform.php index 8a8f420f846..3830c273a73 100644 --- a/apps/calendar/templates/part.eventform.php +++ b/apps/calendar/templates/part.eventform.php @@ -10,12 +10,8 @@ <tr> <th width="75px"><?php echo $l->t("Category");?>:</th> <td> - <select id="category" name="categories[]" multiple="multiple" title="<?php echo $l->t("Select category") ?>"> - <?php - if (!isset($_['categories'])) {$_['categories'] = array();} - echo html_select_options($_['category_options'], $_['categories'], array('combine'=>true)); - ?> - </select> + <input id="category" name="categories" type="text" placeholder="<?php echo $l->t('Separate categories with commas'); ?>" value="<?php echo isset($_['categories']) ? htmlspecialchars($_['categories']) : '' ?>"> + <a class="action edit" onclick="$(this).tipsy('hide');OCCategories.edit();" title="<?php echo $l->t('Edit categories'); ?>"><img alt="<?php echo $l->t('Edit categories'); ?>" src="<?php echo image_path('core','actions/rename.svg')?>" class="svg action" style="width: 16px; height: 16px;"></a> </td> <?php if(count($_['calendar_options']) > 1) { ?> <th width="75px"> <?php echo $l->t("Calendar");?>:</th> |