/** * Handle input and ouput something * * @param array $args $_REQUEST arguments * * @return void */ function handle($args) { parent::handle($args); if (!common_logged_in()) { // TRANS: Error message displayed when trying to perform an action that requires a logged in user. $this->clientError(_m('Not logged in.')); } if (!empty($this->start)) { $times = EventTimeList::getTimes($this->start, $this->duration); } else { // TRANS: Client error when submitting a form with unexpected information. $this->clientError(_m('Unexpected form submission.')); } if ($this->boolean('ajax')) { header('Content-Type: application/json; charset=utf-8'); print json_encode($times); } else { // TRANS: Client error displayed when using an action in a non-AJAX way. $this->clientError(_m('This action is AJAX only.')); } }
/** * Data elements of the form * * @return void */ function formData() { $this->out->elementStart('fieldset', array('id' => 'new_event_data')); // Passing in the URL of the Ajax action that the .js for this form hits // when selecting event start and end times. JavaScript will try to // use a relative path, unless explicitely told where an action is, // and that's a bit difficult to calculate since the event form is on // so many pages with different paths. It might be worth solving this // globally by putting the base site path in the Identifier-URL meta tag // or something similar, so it would be easy to calculate the exact path // for actions and other things in JavaScripts. -z $this->out->hidden('timelist_action_url', common_local_url('timelist')); $this->out->elementStart('ul', 'form_data'); $this->li(); $this->out->input('event-title', _m('LABEL', 'Title'), null, _m('Title of the event.'), 'title', true); // HTML5 "required" attribute $this->unli(); $this->li(); $today = new DateTime('now'); $today->setTimezone(new DateTimeZone(common_timezone())); $this->out->input('event-startdate', _m('LABEL', 'Start date'), $today->format('m/d/Y'), _m('Date the event starts.'), 'startdate'); $this->unli(); $this->li(); $times = EventTimeList::getTimes($today->format('m/d/Y 12:00') . ' am ' . $today->format('T')); $start = EventTimeList::nearestHalfHour($today->format('c')); $start->setTimezone(new DateTimeZone(common_timezone())); $this->out->dropdown('event-starttime', _m('LABEL', 'Start time'), $times, sprintf(_m("Time the event starts (%s)."), $today->format('T')), false, $start->format('g:ia')); // Need to keep JavaScript TZ in sync with PHP TZ $this->out->hidden('tz', $today->format('T')); $this->out->hidden('now', $today->format('F d, Y H:i:s T')); $this->unli(); $this->li(); $this->out->input('event-enddate', _m('LABEL', 'End date'), $today->format('m/d/Y'), _m('Date the event ends.'), 'enddate'); $this->unli(); $this->li(); $this->out->dropdown('event-endtime', _m('LABEL', 'End time'), EventTimeList::getTimes($start->format('c'), true), _m('Time the event ends.'), false, null); $this->unli(); $this->li(); $this->out->input('event-location', _m('LABEL', 'Where?'), null, _m('Event location.'), 'location'); $this->unli(); $this->li(); $this->out->input('event-url', _m('LABEL', 'URL'), null, _m('URL for more information.'), 'url'); $this->unli(); $this->li(); $this->out->input('event-description', _m('LABEL', 'Description'), null, _m('Description of the event.'), 'description', true); // HTML5 "required" attribute $this->unli(); $this->out->elementEnd('ul'); $toWidget = new ToSelector($this->out, common_current_user(), null); $toWidget->show(); $this->out->elementEnd('fieldset'); }