Skip to content

Commit c075f7f

Browse files
author
lkassianik
committed
Allow safe editing of recurring events
Summary: Ref T8472, Allow safe editing of recurring events Test Plan: Create recurring event, edit event, everything but date-related fields should be editable Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: epriestley, Korvin Maniphest Tasks: T8472 Differential Revision: https://secure.phabricator.com/D13230
1 parent bdef125 commit c075f7f

File tree

2 files changed

+117
-51
lines changed

2 files changed

+117
-51
lines changed

src/applications/calendar/controller/PhabricatorCalendarEventEditController.php

Lines changed: 116 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ public function handleRequest(AphrontRequest $request) {
144144
$description = $event->getDescription();
145145
$is_all_day = $event->getIsAllDay();
146146
$is_recurring = $event->getIsRecurring();
147+
$is_parent = $event->getIsRecurrenceParent();
147148
$frequency = idx($event->getRecurrenceFrequency(), 'rule');
148149
$icon = $event->getIcon();
149150

@@ -190,7 +191,7 @@ public function handleRequest(AphrontRequest $request) {
190191
PhabricatorCalendarEventTransaction::TYPE_NAME)
191192
->setNewValue($name);
192193

193-
if ($this->isCreate()) {
194+
if ($is_parent && $this->isCreate()) {
194195
$xactions[] = id(new PhabricatorCalendarEventTransaction())
195196
->setTransactionType(
196197
PhabricatorCalendarEventTransaction::TYPE_RECURRING)
@@ -209,25 +210,28 @@ public function handleRequest(AphrontRequest $request) {
209210
}
210211
}
211212

212-
$xactions[] = id(new PhabricatorCalendarEventTransaction())
213-
->setTransactionType(
214-
PhabricatorCalendarEventTransaction::TYPE_ALL_DAY)
215-
->setNewValue($is_all_day);
213+
if (($is_parent && $this->isCreate()) || !$is_parent) {
214+
$xactions[] = id(new PhabricatorCalendarEventTransaction())
215+
->setTransactionType(
216+
PhabricatorCalendarEventTransaction::TYPE_ALL_DAY)
217+
->setNewValue($is_all_day);
216218

217-
$xactions[] = id(new PhabricatorCalendarEventTransaction())
218-
->setTransactionType(
219-
PhabricatorCalendarEventTransaction::TYPE_ICON)
220-
->setNewValue($icon);
219+
$xactions[] = id(new PhabricatorCalendarEventTransaction())
220+
->setTransactionType(
221+
PhabricatorCalendarEventTransaction::TYPE_ICON)
222+
->setNewValue($icon);
221223

222-
$xactions[] = id(new PhabricatorCalendarEventTransaction())
223-
->setTransactionType(
224-
PhabricatorCalendarEventTransaction::TYPE_START_DATE)
225-
->setNewValue($start_value);
224+
$xactions[] = id(new PhabricatorCalendarEventTransaction())
225+
->setTransactionType(
226+
PhabricatorCalendarEventTransaction::TYPE_START_DATE)
227+
->setNewValue($start_value);
228+
229+
$xactions[] = id(new PhabricatorCalendarEventTransaction())
230+
->setTransactionType(
231+
PhabricatorCalendarEventTransaction::TYPE_END_DATE)
232+
->setNewValue($end_value);
233+
}
226234

227-
$xactions[] = id(new PhabricatorCalendarEventTransaction())
228-
->setTransactionType(
229-
PhabricatorCalendarEventTransaction::TYPE_END_DATE)
230-
->setNewValue($end_value);
231235

232236
$xactions[] = id(new PhabricatorCalendarEventTransaction())
233237
->setTransactionType(
@@ -296,6 +300,12 @@ public function handleRequest(AphrontRequest $request) {
296300
$recurrence_end_date_control = null;
297301
$recurrence_frequency_select = null;
298302

303+
$all_day_checkbox = null;
304+
$start_control = null;
305+
$end_control = null;
306+
307+
$recurring_date_edit_label = null;
308+
299309
$name = id(new AphrontFormTextControl())
300310
->setLabel(pht('Name'))
301311
->setName('name')
@@ -325,8 +335,9 @@ public function handleRequest(AphrontRequest $request) {
325335
->setValue($recurrence_end_date_value)
326336
->setID($recurrence_end_date_id)
327337
->setIsTimeDisabled(true)
338+
->setIsDisabled($recurrence_end_date_value->isDisabled())
328339
->setAllowNull(true)
329-
->setIsDisabled($recurrence_end_date_value->isDisabled());
340+
->isRequired(false);
330341

331342
$recurrence_frequency_select = id(new AphrontFormSelectControl())
332343
->setName('frequency')
@@ -342,38 +353,90 @@ public function handleRequest(AphrontRequest $request) {
342353
->setDisabled(!$is_recurring);
343354
}
344355

345-
Javelin::initBehavior('event-all-day', array(
346-
'allDayID' => $all_day_id,
347-
'startDateID' => $start_date_id,
348-
'endDateID' => $end_date_id,
349-
));
350-
351-
$all_day_checkbox = id(new AphrontFormCheckboxControl())
352-
->addCheckbox(
353-
'isAllDay',
354-
1,
355-
pht('All Day Event'),
356-
$is_all_day,
357-
$all_day_id);
358-
359-
$start_control = id(new AphrontFormDateControl())
360-
->setUser($viewer)
361-
->setName('start')
362-
->setLabel(pht('Start'))
363-
->setError($error_start_date)
364-
->setValue($start_value)
365-
->setID($start_date_id)
366-
->setIsTimeDisabled($is_all_day)
367-
->setEndDateID($end_date_id);
368-
369-
$end_control = id(new AphrontFormDateControl())
370-
->setUser($viewer)
371-
->setName('end')
372-
->setLabel(pht('End'))
373-
->setError($error_end_date)
374-
->setValue($end_value)
375-
->setID($end_date_id)
376-
->setIsTimeDisabled($is_all_day);
356+
if ($this->isCreate() || (!$is_parent && !$this->isCreate())) {
357+
Javelin::initBehavior('event-all-day', array(
358+
'allDayID' => $all_day_id,
359+
'startDateID' => $start_date_id,
360+
'endDateID' => $end_date_id,
361+
));
362+
363+
$all_day_checkbox = id(new AphrontFormCheckboxControl())
364+
->addCheckbox(
365+
'isAllDay',
366+
1,
367+
pht('All Day Event'),
368+
$is_all_day,
369+
$all_day_id);
370+
371+
$start_control = id(new AphrontFormDateControl())
372+
->setUser($viewer)
373+
->setName('start')
374+
->setLabel(pht('Start'))
375+
->setError($error_start_date)
376+
->setValue($start_value)
377+
->setID($start_date_id)
378+
->setIsTimeDisabled($is_all_day)
379+
->setEndDateID($end_date_id);
380+
381+
$end_control = id(new AphrontFormDateControl())
382+
->setUser($viewer)
383+
->setName('end')
384+
->setLabel(pht('End'))
385+
->setError($error_end_date)
386+
->setValue($end_value)
387+
->setID($end_date_id)
388+
->setIsTimeDisabled($is_all_day);
389+
} else if ($is_parent) {
390+
$recurring_date_edit_label = id(new AphrontFormStaticControl())
391+
->setUser($viewer)
392+
->setValue(pht('Date and time of recurring event cannot be edited.'));
393+
394+
if (!$recurrence_end_date_value->isDisabled()) {
395+
$disabled_recurrence_end_date_value =
396+
$recurrence_end_date_value->getValueAsFormat('M d, Y');
397+
$recurrence_end_date_control = id(new AphrontFormStaticControl())
398+
->setUser($viewer)
399+
->setLabel(pht('Recurrence End Date'))
400+
->setValue($disabled_recurrence_end_date_value)
401+
->setDisabled(true);
402+
}
403+
404+
$recurrence_frequency_select = id(new AphrontFormSelectControl())
405+
->setName('frequency')
406+
->setOptions(array(
407+
'daily' => pht('Daily'),
408+
'weekly' => pht('Weekly'),
409+
'monthly' => pht('Monthly'),
410+
'yearly' => pht('Yearly'),
411+
))
412+
->setValue($frequency)
413+
->setLabel(pht('Recurring Event Frequency'))
414+
->setID($frequency_id)
415+
->setDisabled(true);
416+
417+
$all_day_checkbox = id(new AphrontFormCheckboxControl())
418+
->addCheckbox(
419+
'isAllDay',
420+
1,
421+
pht('All Day Event'),
422+
$is_all_day,
423+
$all_day_id)
424+
->setDisabled(true);
425+
426+
$start_disabled = $start_value->getValueAsFormat('M d, Y, g:i A');
427+
$end_disabled = $end_value->getValueAsFormat('M d, Y, g:i A');
428+
429+
$start_control = id(new AphrontFormStaticControl())
430+
->setUser($viewer)
431+
->setLabel(pht('Start'))
432+
->setValue($start_disabled)
433+
->setDisabled(true);
434+
435+
$end_control = id(new AphrontFormStaticControl())
436+
->setUser($viewer)
437+
->setLabel(pht('End'))
438+
->setValue($end_disabled);
439+
}
377440

378441
$description = id(new AphrontFormTextAreaControl())
379442
->setLabel(pht('Description'))
@@ -427,6 +490,9 @@ public function handleRequest(AphrontRequest $request) {
427490
->setUser($viewer)
428491
->appendChild($name);
429492

493+
if ($recurring_date_edit_label) {
494+
$form->appendControl($recurring_date_edit_label);
495+
}
430496
if ($is_recurring_checkbox) {
431497
$form->appendChild($is_recurring_checkbox);
432498
}

src/applications/calendar/controller/PhabricatorCalendarEventViewController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ private function buildActionView(PhabricatorCalendarEvent $event) {
167167
} else if ($event->getIsRecurrenceException()) {
168168
$edit_label = pht('Edit This Instance');
169169
$edit_uri = "event/edit/{$id}/";
170-
} else if (!$event->getIsRecurrenceParent()) {
170+
} else {
171171
$edit_label = pht('Edit');
172172
$edit_uri = "event/edit/{$id}/";
173173
}

0 commit comments

Comments
 (0)