Skip to content

Commit

Permalink
Merge branch 'parsing_schedule' of https://github.com/MathieuSchopfer…
Browse files Browse the repository at this point in the history
…/calendar into MathieuSchopfer-parsing_schedule
  • Loading branch information
georgehrke committed Sep 17, 2016
2 parents e6cb612 + e50f7c7 commit 270db16
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
38 changes: 38 additions & 0 deletions js/app/controllers/editorcontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,44 @@ app.controller('EditorController', ['$scope', 'TimezoneService', 'AutoCompletion
$scope.registerPostHook = function(callback) {
$scope.postEditingHooks.push(callback);
};

$scope.parse_summary = function() {
var summary = $scope.properties.summary.value;

// Parse text to extract schedule from string beginning
var timePattern = "(\\d{1,2}:\\d{2}(?:\\s?[ap]\\.?m\\.?)?)";
var linkPattern = "\\s?[-/]\\s?";
var scheduleExp = new RegExp("^"+timePattern+"(?:"+linkPattern+timePattern+")?\\s", 'i');
var matches = scheduleExp.exec(summary);

if(matches !== null) {

// Strip schedule string from summary
summary = summary.substring(matches.shift().length);

var start = matches[0];
var end = matches[1];

// Convert string to time
var schemes = ["HH:mm", "hh:mm a"];
start = moment(start, schemes);
if(typeof end !== 'undefined') {
end = moment(end, schemes);
}
else {
end = start.clone();
}

// Update event properties
$scope.properties.dtstart.value = moment($scope.properties.dtstart.value.set(
{'hour': start.get('hour'), 'minute': start.get('minute')}));
$scope.properties.dtend.value = moment($scope.properties.dtend.value.set(
{'hour': end.get('hour'), 'minute': end.get('minute')}));
$scope.properties.allDay = false;
$scope.toggledAllDay();
$scope.properties.summary.value = summary;
}
};

$scope.proceed = function() {
$scope.prepareClose();
Expand Down
1 change: 1 addition & 0 deletions templates/editor.popover.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<input
class="events--input h2"
ng-model="properties.summary.value"
ng-blur="parse_summary()"
placeholder="<?php p($l->t('Title of the Event'));?>"
name="title" type="text"
autofocus="autofocus"
Expand Down
1 change: 1 addition & 0 deletions templates/editor.sidebar.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<input
class="advanced--input h2"
ng-model="properties.summary.value"
ng-blur="parse_summary()"
placeholder="<?php p($l->t('Title of the Event'));?>"
name="title" type="text"
autofocus="autofocus"/>
Expand Down

0 comments on commit 270db16

Please sign in to comment.