From 2815db2b07580a38696d174f7c8d457c86992d8a Mon Sep 17 00:00:00 2001 From: Bart Visscher <bartv@thisnet.nl> Date: Tue, 30 Aug 2011 15:02:34 +0200 Subject: [PATCH] Implement editing of calendar info --- apps/calendar/ajax/editcalendar.php | 29 ++++++++++++++ apps/calendar/ajax/updatecalendar.php | 39 +++++++++++++++++++ apps/calendar/js/calendar.js | 17 ++++++++ apps/calendar/lib/calendar.php | 4 +- .../templates/part.choosecalendar.php | 9 ++--- .../part.choosecalendar.rowfields.php | 4 ++ apps/calendar/templates/part.editcalendar.php | 32 +++++++++++++++ 7 files changed, 126 insertions(+), 8 deletions(-) create mode 100644 apps/calendar/ajax/editcalendar.php create mode 100644 apps/calendar/ajax/updatecalendar.php create mode 100644 apps/calendar/templates/part.choosecalendar.rowfields.php create mode 100644 apps/calendar/templates/part.editcalendar.php diff --git a/apps/calendar/ajax/editcalendar.php b/apps/calendar/ajax/editcalendar.php new file mode 100644 index 0000000000..e32bf45865 --- /dev/null +++ b/apps/calendar/ajax/editcalendar.php @@ -0,0 +1,29 @@ +<?php +/************************************************* + * ownCloud - Calendar Plugin * + * * + * (c) Copyright 2011 Georg Ehrke * + * author: Georg Ehrke * + * email: ownclouddev at georgswebsite dot de * + * homepage: ownclouddev.georgswebsite.de * + * manual: ownclouddev.georgswebsite.de/manual * + * License: GNU AFFERO GENERAL PUBLIC LICENSE * + * * + * If you are not able to view the License, * + * <http://www.gnu.org/licenses/> * + * <http://ownclouddev.georgswebsite.de/license/> * + * please write to the Free Software Foundation. * + * Address: * + * 59 Temple Place, Suite 330, Boston, * + * MA 02111-1307 USA * + *************************************************/ +require_once('../../../lib/base.php'); +$l10n = new OC_L10N('calendar'); +if(!OC_USER::isLoggedIn()) { + die("<script type=\"text/javascript\">document.location = oc_webroot;</script>"); +} +$calendar = OC_Calendar_Calendar::findCalendar($_GET['calendarid']); +$tmpl = new OC_Template("calendar", "part.editcalendar"); +$tmpl->assign('calendar',$calendar); +$tmpl->printPage(); +?> diff --git a/apps/calendar/ajax/updatecalendar.php b/apps/calendar/ajax/updatecalendar.php new file mode 100644 index 0000000000..2836dda218 --- /dev/null +++ b/apps/calendar/ajax/updatecalendar.php @@ -0,0 +1,39 @@ +<?php +/************************************************* + * ownCloud - Calendar Plugin * + * * + * (c) Copyright 2011 Georg Ehrke * + * author: Georg Ehrke * + * email: ownclouddev at georgswebsite dot de * + * homepage: ownclouddev.georgswebsite.de * + * manual: ownclouddev.georgswebsite.de/manual * + * License: GNU AFFERO GENERAL PUBLIC LICENSE * + * * + * If you are not able to view the License, * + * <http://www.gnu.org/licenses/> * + * <http://ownclouddev.georgswebsite.de/license/> * + * please write to the Free Software Foundation. * + * Address: * + * 59 Temple Place, Suite 330, Boston, * + * MA 02111-1307 USA * + *************************************************/ +require_once('../../../lib/base.php'); + +$l10n = new OC_L10N('calendar'); + +// We send json data +header( "Content-Type: application/jsonrequest" ); + +// Check if we are a user +if( !OC_User::isLoggedIn()){ + echo json_encode( array( "status" => "error", "data" => array( "message" => $l->t("Authentication error") ))); + exit(); +} + +$calendarid = $_POST['id']; +OC_Calendar_Calendar::editCalendar($calendarid, $_POST['name'], $_POST['description'], null, null, null, $_POST['color']); +OC_Calendar_Calendar::setCalendarActive($calendarid, $_POST['active']); +$calendar = OC_Calendar_Calendar::findCalendar($calendarid); +$tmpl = new OC_Template('calendar', 'part.calendar.row'); +$tmpl->assign('calendar', $calendar); +echo json_encode( array( "status" => "success", "data" => $tmpl->fetchPage() )); diff --git a/apps/calendar/js/calendar.js b/apps/calendar/js/calendar.js index bfead8f393..d9bad110a6 100755 --- a/apps/calendar/js/calendar.js +++ b/apps/calendar/js/calendar.js @@ -903,3 +903,20 @@ function oc_cal_calender_activation(checkbox, calendarid) checkbox.checked = data == 1; }); } +function oc_cal_editcalendar(object, calendarid){ + $(object).closest('tr').load(oc_webroot + "/apps/calendar/ajax/editcalendar.php?calendarid="+calendarid); +} +function oc_cal_editcalendar_submit(button, calendarid){ + var displayname = $("#displayname_"+calendarid).val(); + var active = $("#active_"+calendarid+":checked").length; + var description = $("#description_"+calendarid).val(); + var calendarcolor = $("#calendarcolor_"+calendarid).val(); + + $.post("ajax/updatecalendar.php", { id: calendarid, name: displayname, active: active, description: description, color: calendarcolor }, + function(data){ + if(data.error == "true"){ + }else{ + $(button).closest('tr').html(data.data) + } + }, 'json'); +} diff --git a/apps/calendar/lib/calendar.php b/apps/calendar/lib/calendar.php index 5a4bed1fbc..c1223b5b3a 100644 --- a/apps/calendar/lib/calendar.php +++ b/apps/calendar/lib/calendar.php @@ -112,14 +112,14 @@ class OC_Calendar_Calendar{ public static function editCalendar($id,$name=null,$description=null,$components=null,$timezone=null,$order=null,$color=null){ // Need these ones for checking uri - $calendar = self::find($id); + $calendar = self::findCalendar($id); // Keep old stuff if(is_null($name)) $name = $calendar['name']; if(is_null($description)) $description = $calendar['description']; if(is_null($components)) $components = $calendar['components']; if(is_null($timezone)) $timezone = $calendar['timezone']; - if(is_null($order)) $order = $calendar['order']; + if(is_null($order)) $order = $calendar['calendarorder']; if(is_null($color)) $color = $calendar['color']; $stmt = OC_DB::prepare( 'UPDATE *PREFIX*calendar_calendars SET displayname=?,description=?,calendarorder=?,calendarcolor=?,timezone=?,components=?,ctag=ctag+1 WHERE id=?' ); diff --git a/apps/calendar/templates/part.choosecalendar.php b/apps/calendar/templates/part.choosecalendar.php index ebda6ddfb9..30866270ac 100644 --- a/apps/calendar/templates/part.choosecalendar.php +++ b/apps/calendar/templates/part.choosecalendar.php @@ -4,16 +4,13 @@ $option_calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser()); for($i = 0; $i < count($option_calendars); $i++){ echo "<tr>"; - echo "<td width=\"20px\"><input id=\"active_" . $option_calendars[$i]["id"] . "\" type=\"checkbox\" onClick=\"oc_cal_calender_activation(this, " . $option_calendars[$i]["id"] . ")\"" . ($option_calendars[$i]["active"] ? ' checked="checked"' : '') . "></td>"; - echo "<td><label for=\"active_" . $option_calendars[$i]["id"] . "\">" . $option_calendars[$i]["displayname"] . "</label></td>"; - echo "<td width=\"20px\"><a style=\"display: block; opacity: 0.214133;\" href=\"#\" title=\"" . $l->t("Download") . "\" class=\"action\"><img src=\"/owncloud/core/img/actions/download.svg\"></a></td><td width=\"20px\"><a style=\"display: block; opacity: 0.214133;\" href=\"#\" title=\"" . $l->t("Rename") . "\" class=\"action\"><img src=\"/owncloud/core/img/actions/rename.svg\"></a></td>"; + $tmpl = new OC_Template('calendar', 'part.choosecalendar.rowfields'); + $tmpl->assign('calendar', $option_calendars[$i]); + $tmpl->printpage(); echo "</tr>"; } ?> </table> -<br /><br /><br /> -<input style="float: left;" type="button" onclick="oc_cal_choosecalendar_submit();" value="<?php echo $l->t("Submit"); ?>"> -</div> <script type="text/javascript"> $( "#choosecalendar_dialog" ).dialog({ width : 500, diff --git a/apps/calendar/templates/part.choosecalendar.rowfields.php b/apps/calendar/templates/part.choosecalendar.rowfields.php new file mode 100644 index 0000000000..ebe1ca0b13 --- /dev/null +++ b/apps/calendar/templates/part.choosecalendar.rowfields.php @@ -0,0 +1,4 @@ +<?php + echo "<td width=\"20px\"><input id=\"active_" . $_['calendar']["id"] . "\" type=\"checkbox\" onClick=\"oc_cal_calender_activation(this, " . $_['calendar']["id"] . ")\"" . ($_['calendar']["active"] ? ' checked="checked"' : '') . "></td>"; + echo "<td><label for=\"active_" . $_['calendar']["id"] . "\">" . $_['calendar']["displayname"] . "</label></td>"; + echo "<td width=\"20px\"><a style=\"display: block; opacity: 0.214133;\" href=\"#\" title=\"" . $l->t("Download") . "\" class=\"action\"><img src=\"/owncloud/core/img/actions/download.svg\"></a></td><td width=\"20px\"><a style=\"display: block; opacity: 0.214133;\" href=\"#\" title=\"" . $l->t("Edit") . "\" class=\"action\" onclick=\"oc_cal_editcalendar(this, " . $_['calendar']["id"] . ");\"><img src=\"/owncloud/core/img/actions/rename.svg\"></a></td>"; diff --git a/apps/calendar/templates/part.editcalendar.php b/apps/calendar/templates/part.editcalendar.php new file mode 100644 index 0000000000..d6f4e9f16f --- /dev/null +++ b/apps/calendar/templates/part.editcalendar.php @@ -0,0 +1,32 @@ +<td id="editcalendar_dialog" title="<?php echo $l->t("Edit calendar"); ?>" colspan="4"> +<table width="100%" style="border: 0;"> +<tr> + <th><?php echo $l->t('Displayname') ?></th> + <td> + <input id="displayname_<?php echo $_['calendar']['id'] ?>" type="text" value="<?php echo $_['calendar']['displayname'] ?>"> + </td> +</tr> +<tr> + <td></td> + <td> + <input id="active_<?php echo $_['calendar']['id'] ?>" type="checkbox"<?php echo ($_['calendar']['active'] ? ' checked="checked"' : '' ) ?>> + <label for="active_<?php echo $_['calendar']['id'] ?>"> + <?php echo $l->t('Active') ?> + </label> + </td> +</tr> +<tr> + <th><?php echo $l->t('Description') ?></th> + <td> + <textarea id="description_<?php echo $_['calendar']['id'] ?>"><?php echo $_['calendar']['description'] ?></textarea> + </td> +</tr> +<tr> + <th><?php echo $l->t('Calendar color') ?></th> + <td> + <input id="calendarcolor_<?php echo $_['calendar']['id'] ?>" type="text" value="<?php echo $_['calendar']['calendarcolor'] ?>"> + </td> +</tr> +</table> +<input style="float: left;" type="button" onclick="oc_cal_editcalendar_submit(this, <?php echo $_['calendar']['id'] ?>);" value="<?php echo $l->t("Submit"); ?>"> +</td> -- GitLab