From 45d42a96549e8661bb18c5f8d407641d5362240a Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 16 Sep 2011 17:06:57 +0200 Subject: [PATCH] Move validateEventForm function and fix success handling --- apps/calendar/ajax/editevent.php | 4 +- apps/calendar/js/calendar.js | 79 +++++++++++----------- apps/calendar/templates/part.editevent.php | 2 +- apps/calendar/templates/part.newevent.php | 2 +- 4 files changed, 43 insertions(+), 44 deletions(-) diff --git a/apps/calendar/ajax/editevent.php b/apps/calendar/ajax/editevent.php index d8dae7a324b..aef2e6f78b4 100644 --- a/apps/calendar/ajax/editevent.php +++ b/apps/calendar/ajax/editevent.php @@ -24,7 +24,7 @@ if(!OC_USER::isLoggedIn()) { $errarr = OC_Calendar_Object::validateRequest($_POST); if($errarr){ //show validate errors - $errarr["error"] = "true"; + $errarr['status'] = 'error'; echo json_encode($errarr); exit; }else{ @@ -48,6 +48,6 @@ if($errarr){ $calendar = OC_Calendar_Calendar::findCalendar($request['calendar']); OC_Calendar_Object::moveToCalendar($id, $cal); } - echo json_encode(array("success"=>"true")); + echo json_encode(array('status' => 'success')); } ?> diff --git a/apps/calendar/js/calendar.js b/apps/calendar/js/calendar.js index d18a9573742..c0629bab625 100644 --- a/apps/calendar/js/calendar.js +++ b/apps/calendar/js/calendar.js @@ -322,6 +322,45 @@ Calendar={ }); } }, + validateEventForm:function(url){ + var post = $( "#event_form" ).serialize(); + $("#errorbox").html(""); + $.post(url, post, + function(data){ + if(data.status == "error"){ + var output = "Missing fields:
"; + if(data.title == "true"){ + output = output + "Title
"; + } + if(data.cal == "true"){ + output = output + "Calendar
"; + } + if(data.from == "true"){ + output = output + "From Date
"; + } + if(data.fromtime == "true"){ + output = output + "From Time
"; + } + if(data.to == "true"){ + output = output + "To Date
"; + } + if(data.totime == "true"){ + output = output + "To Time
"; + } + if(data.endbeforestart == "true"){ + output = "The event ends before it starts!"; + } + if(data.dberror == "true"){ + output = "There was a database fail!"; + } + $("#errorbox").html(output); + } else + if(data.status == 'success'){ + $('#event').dialog('destroy').remove(); + Calendar.UI.loadEvents(); + } + },"json"); + }, createEventPopup:function(e){ var popup = $(this).data('popup'); if (!popup){ @@ -808,43 +847,3 @@ $(document).ready(function(){ //event vars Calendar.UI.loadEvents(); -function validate_event_form(url){ - var post = $( "#event_form" ).serialize(); - $("#errorbox").html(""); - $.post(url, post, - function(data){ - if(data.error == "true"){ - var output = "Missing fields:
"; - if(data.title == "true"){ - output = output + "Title
"; - } - if(data.cal == "true"){ - output = output + "Calendar
"; - } - if(data.from == "true"){ - output = output + "From Date
"; - } - if(data.fromtime == "true"){ - output = output + "From Time
"; - } - if(data.to == "true"){ - output = output + "To Date
"; - } - if(data.totime == "true"){ - output = output + "To Time
"; - } - if(data.endbeforestart == "true"){ - output = "The event ends before it starts!"; - } - if(data.dberror == "true"){ - output = "There was a database fail!"; - } - $("#errorbox").html(output); - }else{ - window.location.reload(); - } - if(data.success == true){ - location.reload(); - } - },"json"); -} diff --git a/apps/calendar/templates/part.editevent.php b/apps/calendar/templates/part.editevent.php index 8c6053dc88a..859828216b8 100644 --- a/apps/calendar/templates/part.editevent.php +++ b/apps/calendar/templates/part.editevent.php @@ -4,7 +4,7 @@ inc("part.eventform"); ?>
- " onclick="validate_event_form('ajax/editevent.php');"> + " onclick="Calendar.UI.validateEventForm('ajax/editevent.php');"> diff --git a/apps/calendar/templates/part.newevent.php b/apps/calendar/templates/part.newevent.php index 2c8ba7b907d..b1e2a5eab84 100644 --- a/apps/calendar/templates/part.newevent.php +++ b/apps/calendar/templates/part.newevent.php @@ -3,7 +3,7 @@ inc("part.eventform"); ?>
- " onclick="validate_event_form('ajax/newevent.php');"> + " onclick="Calendar.UI.validateEventForm('ajax/newevent.php');"> -- 2.39.5