User settings, alerts on document added

This commit is contained in:
jendib 2013-08-01 22:50:08 +02:00
parent 2e95803424
commit 0f75faeccc
11 changed files with 129 additions and 12 deletions

View File

@ -1,2 +1 @@
- Reordering files (server)
- User settings

View File

@ -35,6 +35,7 @@
<script src="js/controller/Login.js" type="text/javascript"></script>
<script src="js/controller/Tag.js" type="text/javascript"></script>
<script src="js/controller/Navigation.js" type="text/javascript"></script>
<script src="js/controller/Settings.js" type="text/javascript"></script>
<script src="js/service/User.js" type="text/javascript"></script>
<script src="js/service/Tag.js" type="text/javascript"></script>
<script src="js/filter/Newline.js" type="text/javascript"></script>
@ -45,11 +46,19 @@
<body>
<div class="navbar" ng-controller="Navigation">
<div class="navbar-inner">
<a class="brand" href="#">Sismics Docs</a>
<ul class="nav" ng-show="!userInfo.anonymous">
<li ng-class="{active: $uiRoute}" ui-route="/document.*"><a href="#/document">Documents</a></li>
<li ng-class="{active: $uiRoute}" ui-route="/tag.*"><a href="#/tag">Tags</a></li>
</ul>
<div class="container">
<a class="brand" href="#">Sismics Docs</a>
<ul class="nav" ng-show="!userInfo.anonymous">
<li ng-class="{active: $uiRoute}" ui-route="/document.*"><a href="#/document"><span class="icon-book"></span> Documents</a></li>
<li ng-class="{active: $uiRoute}" ui-route="/tag.*"><a href="#/tag"><span class="icon-tag"></span> Tags</a></li>
</ul>
<ul class="nav pull-right" ng-show="!userInfo.anonymous">
<li ng-class="{active: $uiRoute}" ui-route="/settings.*"><a href="#/settings"><span class="icon-cog"></span> Settings</a></li>
<li><a href="#" ng-click="logout($event)"><span class="icon-off"></span> Logout</a></li>
</ul>
</div>
</div>
</div>

View File

@ -3,7 +3,7 @@
/**
* Trackino application.
*/
var App = angular.module('docs', ['ui.state', 'ui.bootstrap', 'ui.route', 'ui.keypress', 'ui.sortable', 'restangular', 'ngSanitize'])
var App = angular.module('docs', ['ui.state', 'ui.bootstrap', 'ui.route', 'ui.keypress', 'ui.validate', 'ui.sortable', 'restangular', 'ngSanitize'])
/**
* Configuring modules.
@ -29,6 +29,15 @@ var App = angular.module('docs', ['ui.state', 'ui.bootstrap', 'ui.route', 'ui.ke
}
}
})
.state('settings', {
url: '/settings',
views: {
'page': {
templateUrl: 'partial/settings.html',
controller: 'Settings'
}
}
})
.state('document', {
url: '/document',
abstract: true,

View File

@ -4,6 +4,16 @@
* Document edition controller.
*/
App.controller('DocumentEdit', function($scope, $q, $http, $state, $stateParams, Restangular, Tag) {
// Alerts
$scope.alerts = [];
/**
* Close an alert.
*/
$scope.closeAlert = function(index) {
$scope.alerts.splice(index, 1);
};
/**
* Returns true if in edit mode (false in add mode).
*/
@ -61,6 +71,7 @@ App.controller('DocumentEdit', function($scope, $q, $http, $state, $stateParams,
$scope.document = {};
$scope.newFiles = [];
$scope.loadDocuments();
$scope.alerts.push({ type: 'success', msg: 'Document successfully added' });
}
}

View File

@ -3,8 +3,8 @@
/**
* Main controller.
*/
App.controller('Main', function($scope, $state, User) {
User.userInfo(true).then(function(data) {
App.controller('Main', function($scope, $rootScope, $state, User) {
User.userInfo().then(function(data) {
if (data.anonymous) {
$state.transitionTo('login');
} else {

View File

@ -3,6 +3,17 @@
/**
* Navigation controller.
*/
App.controller('Navigation', function($scope, $rootScope, User) {
App.controller('Navigation', function($scope, $state, $rootScope, User, Restangular) {
$rootScope.userInfo = User.userInfo();
/**
* User logout.
*/
$scope.logout = function($event) {
User.logout().then(function() {
$rootScope.userInfo = User.userInfo(true);
$state.transitionTo('main');
});
$event.preventDefault();
};
});

View File

@ -0,0 +1,28 @@
'use strict';
/**
* Settings controller.
*/
App.controller('Settings', function($scope, Restangular) {
$scope.editUserAlert = false;
// Alerts
$scope.alerts = [];
/**
* Close an alert.
*/
$scope.closeAlert = function(index) {
$scope.alerts.splice(index, 1);
};
/**
* Edit user.
*/
$scope.editUser = function() {
Restangular.one('user').post('', $scope.user).then(function() {
$scope.user = {};
$scope.alerts.push({ type: 'success', msg: 'Account successfully updated' });
});
};
});

View File

@ -23,6 +23,13 @@ App.factory('User', function(Restangular) {
*/
login: function(user) {
return Restangular.one('user').post('login', user);
},
/**
* Logout the current user.
*/
logout: function() {
return Restangular.one('user').post('logout', {});
}
}
});

View File

@ -39,3 +39,5 @@
<h4>Uploading files...</h4>
<div class="span6"><progress percent="fileProgress" class="progress-info active"></progress></div>
</div>
<alert ng-repeat="alert in alerts" type="alert.type" close="closeAlert($index)">{{ alert.msg }}</alert>

View File

@ -18,7 +18,7 @@
<label class="checkbox">
<input type="checkbox" ng-model="user.remember" /> Remember me
</label>
<button type="submit" class="btn" ng-click="login()">Sign in</button>
<button type="submit" class="btn btn-primary" ng-click="login()"><span class="icon-ok icon-white"></span> Sign in</button>
</div>
</div>
</form>

View File

@ -0,0 +1,41 @@
<div class="container-fluid">
<div class="row-fluid">
<div class="span4 well">
<ul class="nav nav-list">
<li class="nav-header">Personal settings</li>
<li class="active"><a href="#/settings">User account</a></li>
</ul>
</div>
<div class="span8 well">
<h1>User <small>account</small></h1>
<form class="form-horizontal" name="editUserForm" novalidate>
<div class="control-group" ng-class="{ error: !editUserForm.password.$valid, success: editUserForm.password.$valid }">
<label class="control-label" for="inputPassword">Password</label>
<div class="controls">
<input name="password" type="password" id="inputPassword" required
ng-minlength="8" ng-maxlength="50" placeholder="Password" ng-model="user.password" />
<span class="help-inline" ng-show="editUserForm.password.$error.required">Required</span>
<span class="help-inline" ng-show="editUserForm.password.$error.minlength">Too short</span>
<span class="help-inline" ng-show="editUserForm.password.$error.maxlength">Too long</span>
</div>
</div>
<div class="control-group" ng-class="{ error: !editUserForm.passwordconfirm.$valid, success: editUserForm.passwordconfirm.$valid }">
<label class="control-label" for="inputPasswordConfirm">Password (confirm)</label>
<div class="controls">
<input name="passwordconfirm" type="password" id="inputPasswordConfirm" required
ui-validate="'$value == user.password'" ui-validate-watch="'user.password'"
placeholder="Password (confirm)" ng-model="user.passwordconfirm" />
<span class="help-inline" ng-show="editUserForm.passwordconfirm.$error.validator">Password and password confirmation must match</span>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary" ng-click="editUser()" ng-disabled="!editUserForm.$valid">
<span class="icon-pencil icon-white"></span> Edit
</button>
</div>
</form>
<alert ng-repeat="alert in alerts" type="alert.type" close="closeAlert($index)">{{ alert.msg }}</alert>
</div>
</div>
</div>