forked from mirrors/easyappointments
Added calendar selection when the user enables the google calendar synchronization for a provider.
This commit is contained in:
parent
05416823f6
commit
de29ef1ef4
10 changed files with 188 additions and 60 deletions
Binary file not shown.
|
@ -332,9 +332,9 @@ class Backend_api extends CI_Controller {
|
||||||
*/
|
*/
|
||||||
public function ajax_disable_provider_sync() {
|
public function ajax_disable_provider_sync() {
|
||||||
try {
|
try {
|
||||||
if (!isset($_POST['provider_id'])) {
|
if (!isset($_POST['provider_id']))
|
||||||
throw new Exception('Provider id not specified.');
|
throw new Exception('Provider id not specified.');
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->privileges[PRIV_USERS]['edit'] == FALSE
|
if ($this->privileges[PRIV_USERS]['edit'] == FALSE
|
||||||
&& $this->session->userdata('user_id') != $_POST['provider_id']) {
|
&& $this->session->userdata('user_id') != $_POST['provider_id']) {
|
||||||
|
@ -1087,15 +1087,51 @@ class Backend_api extends CI_Controller {
|
||||||
$this->load->library('google_sync');
|
$this->load->library('google_sync');
|
||||||
$this->load->model('providers_model');
|
$this->load->model('providers_model');
|
||||||
|
|
||||||
$calendars = $this->google_sync->get_google_calendars($_POST['provider_id']);
|
if (!isset($_POST['provider_id']))
|
||||||
echo json_encode($calendars);
|
throw new Exception('Provider id is required in order to fetch the google calendars.');
|
||||||
|
|
||||||
|
// Check if selected provider has sync enabled.
|
||||||
|
$google_sync = $this->providers_model->get_setting('google_sync', $_POST['provider_id']);
|
||||||
|
if ($google_sync) {
|
||||||
|
$google_token = json_decode($this->providers_model->get_setting('google_token', $_POST['provider_id']));
|
||||||
|
$this->google_sync->refresh_token($google_token->refresh_token);
|
||||||
|
$calendars = $this->google_sync->get_google_calendars();
|
||||||
|
echo json_encode($calendars);
|
||||||
|
} else {
|
||||||
|
echo json_encode(AJAX_FAILURE);
|
||||||
|
}
|
||||||
} catch(Exception $exc) {
|
} catch(Exception $exc) {
|
||||||
echo json_encode(array(
|
echo json_encode(array(
|
||||||
'exceptions' => array(exceptionToJavaScript($exc))
|
'exceptions' => array(exceptionToJavaScript($exc))
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Select a specific google calendar for a provider.
|
||||||
|
*
|
||||||
|
* All the appointments will be synced with this particular calendar.
|
||||||
|
*
|
||||||
|
* @param numeric $_POST['provider_id'] Provider record id.
|
||||||
|
* @param string $_POST['calendar_id'] Google calendar's id.
|
||||||
|
*/
|
||||||
|
public function ajax_select_google_calendar() {
|
||||||
|
try {
|
||||||
|
if ($this->privileges[PRIV_USERS]['edit'] == FALSE
|
||||||
|
&& $this->session->userdata('user_id') != $_POST['provider_id']) {
|
||||||
|
throw new Exception('You do not have the required privileges for this task.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->load->model('providers_model');
|
||||||
|
$result = $this->providers_model->set_setting('google_calendar', $_POST['calendar_id'], $_POST['provider_id']);
|
||||||
|
echo json_encode(($result) ? AJAX_SUCCESS : AJAX_FAILURE);
|
||||||
|
|
||||||
|
} catch (Exception $exc) {
|
||||||
|
echo json_encode(array(
|
||||||
|
'exceptions' => array(exceptionToJavaScript($exc))
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* End of file backend_api.php */
|
/* End of file backend_api.php */
|
||||||
|
|
|
@ -53,18 +53,15 @@ class Google extends CI_Controller {
|
||||||
|
|
||||||
if (isset($_SESSION['oauth_provider_id'])) {
|
if (isset($_SESSION['oauth_provider_id'])) {
|
||||||
$this->load->model('providers_model');
|
$this->load->model('providers_model');
|
||||||
|
|
||||||
$this->providers_model->set_setting('google_sync', TRUE,
|
$this->providers_model->set_setting('google_sync', TRUE,
|
||||||
$_SESSION['oauth_provider_id']);
|
$_SESSION['oauth_provider_id']);
|
||||||
$this->providers_model->set_setting('google_token', $token,
|
$this->providers_model->set_setting('google_token', $token,
|
||||||
$_SESSION['oauth_provider_id']);
|
$_SESSION['oauth_provider_id']);
|
||||||
$this->providers_model->set_setting('google_calendar', 'primary',
|
$this->providers_model->set_setting('google_calendar', 'primary',
|
||||||
$_SESSION['oath_provider_id']);
|
$_SESSION['oauth_provider_id']);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
echo '<h1>Sync provider id not specified!</h1>';
|
echo '<h1>Sync provider id not specified!</h1>';
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
echo '<h1>Authorization Failed!</h1>';
|
echo '<h1>Authorization Failed!</h1>';
|
||||||
}
|
}
|
||||||
|
|
|
@ -264,3 +264,6 @@ $lang['hour'] = 'Hour';
|
||||||
$lang['minute'] = 'Minute';
|
$lang['minute'] = 'Minute';
|
||||||
$lang['google_sync_completed'] = 'Google synchronization completed successfully!';
|
$lang['google_sync_completed'] = 'Google synchronization completed successfully!';
|
||||||
$lang['google_sync_failed'] = 'Google synchronization failed: Could not establish server connection.';
|
$lang['google_sync_failed'] = 'Google synchronization failed: Could not establish server connection.';
|
||||||
|
$lang['select_google_calendar'] = 'Select Google Calendar';
|
||||||
|
$lang['select_google_calendar_prompt'] = 'Select the calendar that you want to sync your appointments. If you do not want to select a specific calendar the default one will be used.';
|
||||||
|
$lang['google_calendar_selected'] = 'Google calendar has been successfully selected!';
|
|
@ -264,3 +264,6 @@ $lang['hour'] = 'Uhr';
|
||||||
$lang['minute'] = 'Minute';
|
$lang['minute'] = 'Minute';
|
||||||
$lang['google_sync_completed'] = 'Google Synchronisation erfolgreich beendet!';
|
$lang['google_sync_completed'] = 'Google Synchronisation erfolgreich beendet!';
|
||||||
$lang['google_sync_failed'] = 'Google Synchronisation fehlgeschlagen: Serververbindung konnte nicht hergestellt werden.';
|
$lang['google_sync_failed'] = 'Google Synchronisation fehlgeschlagen: Serververbindung konnte nicht hergestellt werden.';
|
||||||
|
$lang['select_google_calendar'] = 'Wählen Sie Google Kalender';
|
||||||
|
$lang['select_google_calendar_prompt'] = 'Wählen Sie den Kalender, den Sie Ihre Termine synchronisieren möchten. Wenn Sie nicht wollen, um einen bestimmten Kalender wählen den Standard, verwendet.';
|
||||||
|
$lang['google_calendar_selected'] = 'Google-Kalender ausgewählt wurde erfolgreich!';
|
|
@ -264,3 +264,6 @@ $lang['hour'] = 'Ώρα';
|
||||||
$lang['minute'] = 'Λεπτά';
|
$lang['minute'] = 'Λεπτά';
|
||||||
$lang['google_sync_completed'] = 'Ο συγχρονισμός με την Google ολοκληρώθηκε επιτυχώς!';
|
$lang['google_sync_completed'] = 'Ο συγχρονισμός με την Google ολοκληρώθηκε επιτυχώς!';
|
||||||
$lang['google_sync_failed'] = 'Ο συγχρονισμός με την Google απέτυχε: Δεν μπόρεσε να πραγματοποιηθεί σύνδεση με τον server.';
|
$lang['google_sync_failed'] = 'Ο συγχρονισμός με την Google απέτυχε: Δεν μπόρεσε να πραγματοποιηθεί σύνδεση με τον server.';
|
||||||
|
$lang['select_google_calendar'] = 'Επιλογή Ημερολογίου της Google';
|
||||||
|
$lang['select_google_calendar_prompt'] = 'Επιλέξτε το ημερολόγιο στο οποίο θέλετε να συγχρονίζεται τα ραντεβού σας. Εάν δεν θελήσετε να επιλέξετε ένα συγκεκριμένο ημερολόγιο θα χρησιμοποιηθεί το προεπιλεγμένο.';
|
||||||
|
$lang['google_calendar_selected'] = 'Το ημερολόγιο της Google επιλέχθηκε επιτυχώς!';
|
|
@ -301,11 +301,19 @@ class Google_Sync {
|
||||||
* The given user's token must already exist in db in order to get access to his
|
* The given user's token must already exist in db in order to get access to his
|
||||||
* Google Calendar account.
|
* Google Calendar account.
|
||||||
*
|
*
|
||||||
* @param numeric $provider_id The provider's record id.
|
* @param string $google_token The user's token will be used to grant access to google calendar.
|
||||||
* @return array Returns an array with the available calendars.
|
* @return array Returns an array with the available calendars.
|
||||||
*/
|
*/
|
||||||
public function get_google_calendars($provider_id) {
|
public function get_google_calendars() {
|
||||||
|
$calendarList = $this->service->calendarList->listCalendarList();
|
||||||
|
$calendars = array();
|
||||||
|
foreach ($calendarList->items as $google_calendar) {
|
||||||
|
$calendars[] = array(
|
||||||
|
'id' => $google_calendar->id,
|
||||||
|
'summary' => $google_calendar->summary
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return $calendars;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -315,7 +315,6 @@
|
||||||
<button type="button" class="close" data-dismiss="modal"
|
<button type="button" class="close" data-dismiss="modal"
|
||||||
aria-hidden="true">×</button>
|
aria-hidden="true">×</button>
|
||||||
<h3><?php echo $this->lang->line('new_unavailable_title'); ?></h3>
|
<h3><?php echo $this->lang->line('new_unavailable_title'); ?></h3>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
|
@ -364,3 +363,35 @@
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
// --------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// SELECT GOOGLE CALENDAR
|
||||||
|
//
|
||||||
|
// --------------------------------------------------------------------
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div id="select-google-calendar" class="modal hide fade">
|
||||||
|
<div class="modal-header">
|
||||||
|
<button type="button" class="close" data-dismiss="modal"
|
||||||
|
aria-hidden="true">×</button>
|
||||||
|
<h3><?php echo $this->lang->line('select_google_calendar'); ?></h3>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal-body">
|
||||||
|
<p>
|
||||||
|
<?php echo $this->lang->line('select_google_calendar_prompt'); ?>
|
||||||
|
</p>
|
||||||
|
<select id="google-calendar"></select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button id="select-calendar" class="btn btn-primary">
|
||||||
|
<?php echo $this->lang->line('select'); ?>
|
||||||
|
</button>
|
||||||
|
<button id="close-calendar" class="btn">
|
||||||
|
<?php echo $this->lang->line('close'); ?>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
|
@ -708,8 +708,29 @@ var BackendCalendar = {
|
||||||
$('#google-sync').prop('disabled', false);
|
$('#google-sync').prop('disabled', false);
|
||||||
$('#select-filter-item option:selected').attr('google-sync', 'true');
|
$('#select-filter-item option:selected').attr('google-sync', 'true');
|
||||||
|
|
||||||
// Display the calendar selection dialog.
|
// Display the calendar selection dialog. First we will get a list
|
||||||
|
// of the available user's calendars and then we will display a selection
|
||||||
|
// modal so the user can select the sync calendar.
|
||||||
|
var postUrl = GlobalVariables.baseUrl + 'backend_api/ajax_get_google_calendars';
|
||||||
|
var postData = {
|
||||||
|
'provider_id': $('#select-filter-item').val()
|
||||||
|
};
|
||||||
|
$.post(postUrl, postData, function(response) {
|
||||||
|
///////////////////////////////////////////////////////////////////
|
||||||
|
console.log('Get Available Google Calendars Response', response);
|
||||||
|
///////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
if (!GeneralFunctions.handleAjaxExceptions(response)) return;
|
||||||
|
|
||||||
|
$('#google-calendar').empty();
|
||||||
|
$.each(response, function() {
|
||||||
|
var option = '<option value="' + this.id + '">' + this.summary + '</option>';
|
||||||
|
$('#google-calendar').append(option);
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#select-google-calendar').modal('show');
|
||||||
|
|
||||||
|
}, 'json');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 100);
|
}, 100);
|
||||||
|
@ -922,6 +943,32 @@ var BackendCalendar = {
|
||||||
$('#manage-appointment').find('#customer-id, #first-name, #last-name, #email, '
|
$('#manage-appointment').find('#customer-id, #first-name, #last-name, #email, '
|
||||||
+ '#phone-number, #address, #city, #zip-code, #customer-notes').val('');
|
+ '#phone-number, #address, #city, #zip-code, #customer-notes').val('');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event: Select Google Calendar "Click"
|
||||||
|
*/
|
||||||
|
$('#select-calendar').click(function() {
|
||||||
|
var postUrl = GlobalVariables.baseUrl + 'backend_api/ajax_select_google_calendar';
|
||||||
|
var postData = {
|
||||||
|
'provider_id': $('#select-filter-item').val(),
|
||||||
|
'calendar_id': $('#google-calendar').val()
|
||||||
|
};
|
||||||
|
$.post(postUrl, postData, function(response){
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
console.log('Select Google Calendar Response', response);
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
if (!GeneralFunctions.handleAjaxExceptions(response)) return;
|
||||||
|
Backend.displayNotification(EALang['google_calendar_selected']);
|
||||||
|
$('#select-google-calendar').modal('hide');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event: Close Google Calendar "Click"
|
||||||
|
*/
|
||||||
|
$('#close-calendar').click(function() {
|
||||||
|
$('#select-google-calendar').modal('hide');
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1630,14 +1677,14 @@ var BackendCalendar = {
|
||||||
console.log('Drop Unavailable Event Response:', response);
|
console.log('Drop Unavailable Event Response:', response);
|
||||||
|
|
||||||
if (response.exceptions) {
|
if (response.exceptions) {
|
||||||
reponse.exceptions = GeneralFunctions.parseExceptions(response.exceptions);
|
response.exceptions = GeneralFunctions.parseExceptions(response.exceptions);
|
||||||
GeneralFunctions.displayMessageBox(GeneralFunctions.EXCEPTIONS_TITLE, GeneralFunctions.EXCEPTIONS_MESSAGE);
|
GeneralFunctions.displayMessageBox(GeneralFunctions.EXCEPTIONS_TITLE, GeneralFunctions.EXCEPTIONS_MESSAGE);
|
||||||
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.exceptions));
|
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.exceptions));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.warnings) {
|
if (response.warnings) {
|
||||||
reponse.warnings = GeneralFunctions.parseExceptions(response.warnings);
|
response.warnings = GeneralFunctions.parseExceptions(response.warnings);
|
||||||
GeneralFunctions.displayMessageBox(GeneralFunctions.WARNINGS_TITLE, GeneralFunctions.WARNINGS_MESSAGE);
|
GeneralFunctions.displayMessageBox(GeneralFunctions.WARNINGS_TITLE, GeneralFunctions.WARNINGS_MESSAGE);
|
||||||
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.warnings));
|
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.warnings));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue