summaryrefslogtreecommitdiffstats
path: root/apps/calendar
diff options
context:
space:
mode:
authorBart Visscher <bartv@thisnet.nl>2011-09-08 12:29:29 +0200
committerBart Visscher <bartv@thisnet.nl>2011-09-08 12:29:29 +0200
commit74f6dd5d5a40596c5e900640852d46f79a4925ae (patch)
tree4ff3e5f2b6c8581569f9aa8aed551b37f3edd602 /apps/calendar
parentf3e98878da39ff086a2e194cf0c5c6c78c0df9f6 (diff)
downloadnextcloud-server-74f6dd5d5a40596c5e900640852d46f79a4925ae.tar.gz
nextcloud-server-74f6dd5d5a40596c5e900640852d46f79a4925ae.zip
Add creating calendars with the web interface
Diffstat (limited to 'apps/calendar')
-rw-r--r--apps/calendar/ajax/createcalendar.php39
-rw-r--r--apps/calendar/ajax/editcalendar.php3
-rw-r--r--apps/calendar/ajax/newcalendar.php35
-rw-r--r--apps/calendar/ajax/updatecalendar.php2
-rw-r--r--apps/calendar/js/calendar.js37
-rw-r--r--apps/calendar/templates/part.choosecalendar.php5
-rw-r--r--apps/calendar/templates/part.editcalendar.php9
7 files changed, 118 insertions, 12 deletions
diff --git a/apps/calendar/ajax/createcalendar.php b/apps/calendar/ajax/createcalendar.php
new file mode 100644
index 00000000000..e6e668adfb4
--- /dev/null
+++ b/apps/calendar/ajax/createcalendar.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();
+}
+
+$userid = OC_User::getUser();
+$calendarid = OC_Calendar_Calendar::addCalendar($userid, $_POST['name'], $_POST['description'], 'VEVENT,VTODO,VJOURNAL', null, 0, $_POST['color']);
+OC_Calendar_Calendar::setCalendarActive($calendarid, 1);
+$calendar = OC_Calendar_Calendar::findCalendar($calendarid);
+$tmpl = new OC_Template('calendar', 'part.choosecalendar.rowfields');
+$tmpl->assign('calendar', $calendar);
+echo json_encode( array( "status" => "error", "data" => $tmpl->fetchPage().'' ));
diff --git a/apps/calendar/ajax/editcalendar.php b/apps/calendar/ajax/editcalendar.php
index e32bf458652..707544f4dd7 100644
--- a/apps/calendar/ajax/editcalendar.php
+++ b/apps/calendar/ajax/editcalendar.php
@@ -24,6 +24,7 @@ if(!OC_USER::isLoggedIn()) {
}
$calendar = OC_Calendar_Calendar::findCalendar($_GET['calendarid']);
$tmpl = new OC_Template("calendar", "part.editcalendar");
-$tmpl->assign('calendar',$calendar);
+$tmpl->assign('new', false);
+$tmpl->assign('calendar', $calendar);
$tmpl->printPage();
?>
diff --git a/apps/calendar/ajax/newcalendar.php b/apps/calendar/ajax/newcalendar.php
new file mode 100644
index 00000000000..88cadeaa6c1
--- /dev/null
+++ b/apps/calendar/ajax/newcalendar.php
@@ -0,0 +1,35 @@
+<?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 = array(
+ 'id' => 'new',
+ 'displayname' => 'Test',
+ 'description' => 'Test calendar',
+ 'calendarcolor' => 'black',
+);
+$tmpl = new OC_Template('calendar', 'part.editcalendar');
+$tmpl->assign('new', true);
+$tmpl->assign('calendar', $calendar);
+$tmpl->printPage();
+?>
diff --git a/apps/calendar/ajax/updatecalendar.php b/apps/calendar/ajax/updatecalendar.php
index 2836dda218a..07cc32d5931 100644
--- a/apps/calendar/ajax/updatecalendar.php
+++ b/apps/calendar/ajax/updatecalendar.php
@@ -34,6 +34,6 @@ $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 = new OC_Template('calendar', 'part.choosecalendar.rowfields');
$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 928b1e06282..e7c31cd7c9b 100644
--- a/apps/calendar/js/calendar.js
+++ b/apps/calendar/js/calendar.js
@@ -200,6 +200,10 @@ Calendar={
},
events:[],
loadEvents:function(year){
+ if( typeof (year) == 'undefined') {
+ this.events = [];
+ year = Calendar.Date.current.getFullYear();
+ }
if( typeof (this.events[year]) == "undefined") {
this.events[year] = []
}
@@ -213,7 +217,9 @@ Calendar={
$( "#parsingfail_dialog" ).dialog();
});
} else {
- Calendar.UI.events[year] = newevents[year];
+ if (typeof(newevents[year]) != 'undefined'){
+ Calendar.UI.events[year] = newevents[year];
+ }
$(document).ready(function() {
Calendar.UI.updateView();
});
@@ -677,7 +683,7 @@ $(document).ready(function(){
$('#listview #more_after').click(Calendar.UI.List.renderMoreAfter);
});
//event vars
-Calendar.UI.loadEvents(Calendar.Date.current.getFullYear());
+Calendar.UI.loadEvents();
function oc_cal_switch2today() {
Calendar.Date.current = new Date();
@@ -718,23 +724,40 @@ function oc_cal_calender_activation(checkbox, calendarid)
$.post(oc_webroot + "/apps/calendar/ajax/activation.php", { calendarid: calendarid, active: checkbox.checked?1:0 },
function(data) {
checkbox.checked = data == 1;
- Calendar.UI.loadEvents(Calendar.Date.current.getFullYear());
+ Calendar.UI.loadEvents();
});
}
function oc_cal_editcalendar(object, calendarid){
- $(object).closest('tr').load(oc_webroot + "/apps/calendar/ajax/editcalendar.php?calendarid="+calendarid);
+ var tr = $(document.createElement('tr'))
+ .load(oc_webroot + "/apps/calendar/ajax/editcalendar.php?calendarid="+calendarid);
+ $(object).closest('tr').after(tr).hide();
+}
+function oc_cal_newcalendar(object){
+ var tr = $(document.createElement('tr'))
+ .load(oc_webroot + "/apps/calendar/ajax/newcalendar.php");
+ $(object).closest('tr').after(tr).hide();
}
-function oc_cal_editcalendar_submit(button, calendarid){
+function oc_cal_calendar_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 },
+ var url;
+ if (calendarid == 'new'){
+ url = "ajax/createcalendar.php";
+ }else{
+ url = "ajax/updatecalendar.php";
+ }
+ $.post(url, { id: calendarid, name: displayname, active: active, description: description, color: calendarcolor },
function(data){
if(data.error == "true"){
}else{
- $(button).closest('tr').html(data.data)
+ $(button).closest('tr').prev().html(data.data).show().next().remove();
+ Calendar.UI.loadEvents();
}
}, 'json');
}
+function oc_cal_calendar_cancel(button, calendarid){
+ $(button).closest('tr').prev().show().next().remove();
+}
diff --git a/apps/calendar/templates/part.choosecalendar.php b/apps/calendar/templates/part.choosecalendar.php
index 30866270ac5..07e7573a8ab 100644
--- a/apps/calendar/templates/part.choosecalendar.php
+++ b/apps/calendar/templates/part.choosecalendar.php
@@ -10,6 +10,11 @@ for($i = 0; $i < count($option_calendars); $i++){
echo "</tr>";
}
?>
+<tr>
+ <td colspan="4">
+ <a href="#" onclick="oc_cal_newcalendar(this);"><?php echo $l->t('New Calendar') ?></a>
+ </td>
+</tr>
</table>
<script type="text/javascript">
$( "#choosecalendar_dialog" ).dialog({
diff --git a/apps/calendar/templates/part.editcalendar.php b/apps/calendar/templates/part.editcalendar.php
index d6f4e9f16ff..0bf2a572bec 100644
--- a/apps/calendar/templates/part.editcalendar.php
+++ b/apps/calendar/templates/part.editcalendar.php
@@ -1,4 +1,4 @@
-<td id="editcalendar_dialog" title="<?php echo $l->t("Edit calendar"); ?>" colspan="4">
+<td id="<?php echo $_['new'] ? 'new' : 'edit' ?>calendar_dialog" title="<?php echo $_['new'] ? $l->t("New calendar") : $l->t("Edit calendar"); ?>" colspan="4">
<table width="100%" style="border: 0;">
<tr>
<th><?php echo $l->t('Displayname') ?></th>
@@ -6,15 +6,17 @@
<input id="displayname_<?php echo $_['calendar']['id'] ?>" type="text" value="<?php echo $_['calendar']['displayname'] ?>">
</td>
</tr>
+<?php if (!$_['new']): ?>
<tr>
<td></td>
<td>
- <input id="active_<?php echo $_['calendar']['id'] ?>" type="checkbox"<?php echo ($_['calendar']['active'] ? ' checked="checked"' : '' ) ?>>
+ <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>
+<?php endif; ?>
<tr>
<th><?php echo $l->t('Description') ?></th>
<td>
@@ -28,5 +30,6 @@
</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"); ?>">
+<input style="float: left;" type="button" onclick="oc_cal_calendar_submit(this, <?php echo $_['new'] ? "'new'" : $_['calendar']['id'] ?>);" value="<?php echo $_['new'] ? $l->t("Save") : $l->t("Submit"); ?>">
+<input style="float: left;" type="button" onclick="oc_cal_calendar_cancel(this, <?php echo $_['new'] ? "'new'" : $_['calendar']['id'] ?>);" value="<?php echo $l->t("Cancel"); ?>">
</td>