Skip to content

Commit

Permalink
#23: Save timesheets automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
crittermike committed Aug 27, 2015
1 parent e05fef0 commit 0cfa140
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
8 changes: 8 additions & 0 deletions app/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ <h1>OpenAir Reborn Options</h1>
</select>
<p class="description">Choosing "No" will automatically stop a running timer whenever a new one is started.</p>
</div>
<div class="form-input-wrapper">
<label for="autosave">Auto-save timesheet</label>
<select id="autosave" name="autosave" ng-model="autosave">
<option value="1">Yes</option>
<option value="0">No</option>
</select>
<p class="description">Choosing "Yes" will automatically save your timesheet every 15 minutes.</p>
</div>
<!--
<div class="form-input-wrapper">
<label for="persistentTimers">Persistent timers</label>
Expand Down
4 changes: 3 additions & 1 deletion app/scripts/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ app.controller('OptionsController', ['$scope', function($scope) {
chrome.storage.sync.set({
timeFormat : $scope.timeFormat,
multipleTimers : $scope.multipleTimers,
persistentTimers : $scope.persistentTimers
persistentTimers : $scope.persistentTimers,
autosave : $scope.autosave
}, function() {
$scope.status = "Settings saved successfully.";
$scope.$apply();
Expand Down Expand Up @@ -67,6 +68,7 @@ app.controller('OptionsController', ['$scope', function($scope) {
$scope.load('timeFormat', 'hhmm');
$scope.load('multipleTimers', 1);
$scope.load('persistentTimers', 1);
$scope.load('autosave', 0);
};

// And away we go...
Expand Down
26 changes: 25 additions & 1 deletion app/scripts/timeentry.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @file An Angular controller used for managing the custom UI for OpenAir.
*/

app.controller('TimeEntryController', ['$scope', 'OpenAirService', function($scope, OpenAirService) {
app.controller('TimeEntryController', ['$scope', '$timeout', 'OpenAirService', function($scope, $timeout, OpenAirService) {

/**
* Adds time to the list of time entries.
Expand Down Expand Up @@ -311,6 +311,7 @@ app.controller('TimeEntryController', ['$scope', 'OpenAirService', function($sco
$scope.loadSettings = function() {
$scope.loadSetting('timeFormat', 'hhmm');
$scope.loadSetting('multipleTimers', 1);
$scope.loadSetting('autosave', 0);
};

/**
Expand Down Expand Up @@ -451,4 +452,27 @@ app.controller('TimeEntryController', ['$scope', 'OpenAirService', function($sco
}
}
});

/**
* Save the timesheet by programmatically clicking the save button.
*/
$scope.submitTimesheet = function() {
if ($scope.autosave === "1") {
angular.element('#timesheet_savebutton').click();
}
};

// Auto-save the form every 10 minutes of inactivity.
var autosaveTimer;
$scope.resetTimeout = function() {
if (autosaveTimer) {
$timeout.cancel(autosaveTimer);
}
autosaveTimer = $timeout($scope.submitTimesheet, 1000 * 60 * 15);
};

// Reset the timeout if the page is in use.
angular.element('body').mousemove(function(){
$scope.resetTimeout();
});
}]);

0 comments on commit 0cfa140

Please sign in to comment.