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">
<form ng-model="eventdetails" ng-submit="save()">
<div class="input-group input-group-lg">
<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">
</div>
<form ng-model="eventdetails" ng-submit="save()">
<div class="input-group input-group-lg">
<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">
</div>
<div class="input-group top5">
<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']">
</div>
<div class="input-group top5">
<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']">
</div>
<div class="input-group top5">
<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']">
</div>
<div class="input-group top5">
<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']">
</div>
<div class="input-group top5">
<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']">
</div>
<input type="submit" style="position: absolute; left: -9999px; width: 1px; height: 1px;"/>
</form>
<div class="input-group top5">
<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']">
</div>
<input type="submit" style="position: absolute; left: -9999px; width: 1px; height: 1px;"/>
</form>
</div>

View file

@ -1,34 +1,34 @@
<!doctype html>
<html ng-app="eventManApp">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="/static/js/angular.min.js"></script>
<script src="/static/js/angular-route.js"></script>
<script src="/static/js/angular-resource.js"></script>
<script src="/js/app.js"></script>
<script src="/js/services.js"></script>
<script src="/js/controllers.js"></script>
<title>Event Man(ager)</title>
<link href="/static/css/bootstrap.min.css" rel="stylesheet">
<link href="/static/css/bootstrap-theme.min.css" rel="stylesheet">
<link href="/static/css/eventman.css" rel="stylesheet">
</head>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="/static/js/angular.min.js"></script>
<script src="/static/js/angular-route.js"></script>
<script src="/static/js/angular-resource.js"></script>
<script src="/js/app.js"></script>
<script src="/js/services.js"></script>
<script src="/js/controllers.js"></script>
<title>Event Man(ager)</title>
<link href="/static/css/bootstrap.min.css" rel="stylesheet">
<link href="/static/css/bootstrap-theme.min.css" rel="stylesheet">
<link href="/static/css/eventman.css" rel="stylesheet">
</head>
<body>
<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="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('/new-person')" class="btn btn-link" value="Add Persons" />
</div>
<body>
<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="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('/new-person')" class="btn btn-link" value="Add Persons" />
</div>
<div ng-view></div>
<div ng-view></div>
<div class="main-footer">
</div>
<script src="/static/js/jquery-2.1.3.min.js"></script>
<script src="/static/js/bootstrap.min.js"></script>
</body>
<div class="main-footer">
</div>
<script src="/static/js/jquery-2.1.3.min.js"></script>
<script src="/static/js/bootstrap.min.js"></script>
</body>
</html>

66
angular_app/js/app.js vendored
View file

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

View file

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

View file

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