JavaScript code cleanup

This commit is contained in:
Davide Alberani 2015-03-21 15:45:40 +01:00
parent bd5e73f62b
commit c63124f575
5 changed files with 111 additions and 109 deletions

View file

@ -1,24 +1,24 @@
<div class="container-fluid"> <div class="container-fluid">
<form ng-model="eventdetails" ng-submit="save()"> <form ng-model="eventdetails" ng-submit="save()">
<div class="input-group input-group-lg"> <div class="input-group input-group-lg">
<span class="input-group-addon" id="basic-addon1">Title</span> <span class="input-group-addon" id="basic-addon1">Title</span>
<input type="text" class="form-control" placeholder="Title" aria-describedby="basic-addon-2" value="{{event.title}}" ng-model="event.title" ng-required="1"> <input type="text" class="form-control" placeholder="Title" aria-describedby="basic-addon-2" value="{{event.title}}" ng-model="event.title" ng-required="1">
</div> </div>
<div class="input-group top5"> <div class="input-group top5">
<span class="input-group-addon" id="basic-addon1">Short description</span> <span class="input-group-addon" id="basic-addon1">Short description</span>
<input type="text" class="form-control" placeholder="The event in one sentence" aria-describedby="basic-addon1" value="{{event['short-description']}}" ng-model="event['short-description']"> <input type="text" class="form-control" placeholder="The event in one sentence" aria-describedby="basic-addon1" value="{{event['short-description']}}" ng-model="event['short-description']">
</div> </div>
<div class="input-group top5"> <div class="input-group top5">
<span class="input-group-addon" id="basic-addon1">Begin time</span> <span class="input-group-addon" id="basic-addon1">Begin time</span>
<input type="text" class="form-control" placeholder="Date and time" aria-describedby="basic-addon1" value="{{event['begin-datetime']}}" ng-model="event['begin-datetime']"> <input type="text" class="form-control" placeholder="Date and time" aria-describedby="basic-addon1" value="{{event['begin-datetime']}}" ng-model="event['begin-datetime']">
</div> </div>
<div class="input-group top5"> <div class="input-group top5">
<span class="input-group-addon" id="basic-addon1">End time</span> <span class="input-group-addon" id="basic-addon1">End time</span>
<input type="text" class="form-control" placeholder="Date and time" aria-describedby="basic-addon1" value="{{event['end-datetime']}}" ng-model="event['begin-endtime']"> <input type="text" class="form-control" placeholder="Date and time" aria-describedby="basic-addon1" value="{{event['end-datetime']}}" ng-model="event['begin-endtime']">
</div> </div>
<input type="submit" style="position: absolute; left: -9999px; width: 1px; height: 1px;"/> <input type="submit" style="position: absolute; left: -9999px; width: 1px; height: 1px;"/>
</form> </form>
</div> </div>

View file

@ -1,34 +1,34 @@
<!doctype html> <!doctype html>
<html ng-app="eventManApp"> <html ng-app="eventManApp">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<script src="/static/js/angular.min.js"></script> <script src="/static/js/angular.min.js"></script>
<script src="/static/js/angular-route.js"></script> <script src="/static/js/angular-route.js"></script>
<script src="/static/js/angular-resource.js"></script> <script src="/static/js/angular-resource.js"></script>
<script src="/js/app.js"></script> <script src="/js/app.js"></script>
<script src="/js/services.js"></script> <script src="/js/services.js"></script>
<script src="/js/controllers.js"></script> <script src="/js/controllers.js"></script>
<title>Event Man(ager)</title> <title>Event Man(ager)</title>
<link href="/static/css/bootstrap.min.css" rel="stylesheet"> <link href="/static/css/bootstrap.min.css" rel="stylesheet">
<link href="/static/css/bootstrap-theme.min.css" rel="stylesheet"> <link href="/static/css/bootstrap-theme.min.css" rel="stylesheet">
<link href="/static/css/eventman.css" rel="stylesheet"> <link href="/static/css/eventman.css" rel="stylesheet">
</head> </head>
<body> <body>
<div class="main-header" ng-controller="navigation as n"> <div class="main-header" ng-controller="navigation as n">
<input type="button" id="events-button" ng-click="n.go('/events')" class="btn btn-link" value="Events" /> <input type="button" id="events-button" ng-click="n.go('/events')" class="btn btn-link" value="Events" />
<input type="button" id="new-event-button" ng-click="n.go('/new-event')" class="btn btn-link" value="Add Event" /> <input type="button" id="new-event-button" ng-click="n.go('/new-event')" class="btn btn-link" value="Add Event" />
<input type="button" id="persons-button" ng-click="n.go('/persons')" class="btn btn-link" value="Persons" /> <input type="button" id="persons-button" ng-click="n.go('/persons')" class="btn btn-link" value="Persons" />
<input type="button" id="persons-button" ng-click="n.go('/new-person')" class="btn btn-link" value="Add Persons" /> <input type="button" id="persons-button" ng-click="n.go('/new-person')" class="btn btn-link" value="Add Persons" />
</div> </div>
<div ng-view></div> <div ng-view></div>
<div class="main-footer"> <div class="main-footer">
</div> </div>
<script src="/static/js/jquery-2.1.3.min.js"></script> <script src="/static/js/jquery-2.1.3.min.js"></script>
<script src="/static/js/bootstrap.min.js"></script> <script src="/static/js/bootstrap.min.js"></script>
</body> </body>
</html> </html>

66
angular_app/js/app.js vendored
View file

@ -1,9 +1,10 @@
var eventManApp = angular.module('eventManApp', [ var eventManApp = angular.module('eventManApp', [
'ngRoute', 'ngRoute',
'eventManServices', 'eventManServices',
'eventManControllers' 'eventManControllers'
]); ]);
eventManApp.directive('ngEnter', function () { eventManApp.directive('ngEnter', function () {
return function (scope, element, attrs) { return function (scope, element, attrs) {
element.bind("keydown keypress", function (event) { element.bind("keydown keypress", function (event) {
@ -17,35 +18,36 @@ eventManApp.directive('ngEnter', function () {
}; };
}); });
eventManApp.config(['$routeProvider', eventManApp.config(['$routeProvider',
function($routeProvider) { function($routeProvider) {
$routeProvider. $routeProvider.
when('/persons', { when('/persons', {
templateUrl: 'persons-list.html', templateUrl: 'persons-list.html',
controller: 'PersonsListCtrl' controller: 'PersonsListCtrl'
}). }).
when('/persons/:id', { when('/persons/:id', {
templateUrl: 'person-detail.html', templateUrl: 'person-detail.html',
controller: 'PersonDetailsCtrl' controller: 'PersonDetailsCtrl'
}). }).
when('/events', { when('/events', {
templateUrl: 'events-list.html', templateUrl: 'events-list.html',
controller: 'EventsListCtrl' controller: 'EventsListCtrl'
}). }).
when('/events/:id', { when('/events/:id', {
templateUrl: 'event-detail.html', templateUrl: 'event-detail.html',
controller: 'EventDetailsCtrl' controller: 'EventDetailsCtrl'
}). }).
when('/new-event', { when('/new-event', {
templateUrl: 'event-detail.html', templateUrl: 'event-detail.html',
controller: 'EventDetailsCtrl' controller: 'EventDetailsCtrl'
}). }).
when('/new-person', { when('/new-person', {
templateUrl: 'person-detail.html', templateUrl: 'person-detail.html',
controller: 'PersonDetailsCtrl' controller: 'PersonDetailsCtrl'
}). }).
otherwise({ otherwise({
redirectTo: '/events' redirectTo: '/events'
}); });
}]); }]);

View file

@ -25,13 +25,13 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', 'Event', '$routePa
if ($routeParams.id) { if ($routeParams.id) {
$scope.event = Event.get($routeParams); $scope.event = Event.get($routeParams);
} }
$scope.save = function() { $scope.save = function() {
if ($scope.event.id === undefined) { if ($scope.event.id === undefined) {
Event.save($scope.event); Event.save($scope.event);
} else { } else {
Event.update($scope.event); Event.update($scope.event);
} }
}; };
}] }]
); );

View file

@ -1,32 +1,32 @@
var eventManServices = angular.module('eventManServices', ['ngResource']); var eventManServices = angular.module('eventManServices', ['ngResource']);
eventManServices.factory('Event', ['$resource', eventManServices.factory('Event', ['$resource',
function($resource) { function($resource) {
return $resource('events/:id', {id: '@id'}, { return $resource('events/:id', {id: '@id'}, {
all: { all: {
method: 'GET', method: 'GET',
isArray: true, isArray: true,
transformResponse: function(data, headers) { transformResponse: function(data, headers) {
return angular.fromJson(data).events; return angular.fromJson(data).events;
} }
}, },
update: {method: 'PUT'} update: {method: 'PUT'}
}); });
}] }]
); );
eventManServices.factory('Person', ['$resource', eventManServices.factory('Person', ['$resource',
function($resource) { function($resource) {
return $resource('persons/:id', {id: '@id'}, { return $resource('persons/:id', {id: '@id'}, {
all: { all: {
method: 'GET', method: 'GET',
isArray:true, isArray:true,
transformResponse: function(data, headers) { transformResponse: function(data, headers) {
return angular.fromJson(data).persons; return angular.fromJson(data).persons;
} }
} }
}); });
}] }]
); );