controller to add new event

This commit is contained in:
Davide Alberani 2015-03-21 15:33:17 +01:00
parent 0db7feb547
commit bd5e73f62b
5 changed files with 51 additions and 10 deletions

View file

@ -1,16 +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}}">
<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">Begin time</span>
<input type="text" class="form-control" placeholder="Date and time" aria-describedby="basic-addon1" value="{{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 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']}}">
<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>

17
angular_app/js/app.js vendored
View file

@ -4,6 +4,19 @@ var eventManApp = angular.module('eventManApp', [
'eventManControllers'
]);
eventManApp.directive('ngEnter', function () {
return function (scope, element, attrs) {
element.bind("keydown keypress", function (event) {
if(event.which === 13) {
scope.$apply(function (){
scope.$eval(attrs.ngEnter);
});
event.preventDefault();
}
});
};
});
eventManApp.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
@ -11,7 +24,7 @@ eventManApp.config(['$routeProvider',
templateUrl: 'persons-list.html',
controller: 'PersonsListCtrl'
}).
when('/persons/:personID', {
when('/persons/:id', {
templateUrl: 'person-detail.html',
controller: 'PersonDetailsCtrl'
}).
@ -19,7 +32,7 @@ eventManApp.config(['$routeProvider',
templateUrl: 'events-list.html',
controller: 'EventsListCtrl'
}).
when('/events/:eventID', {
when('/events/:id', {
templateUrl: 'event-detail.html',
controller: 'EventDetailsCtrl'
}).

View file

@ -22,7 +22,16 @@ eventManControllers.controller('EventsListCtrl', ['$scope', 'Event',
eventManControllers.controller('EventDetailsCtrl', ['$scope', 'Event', '$routeParams',
function ($scope, Event, $routeParams) {
$scope.event = Event.get($routeParams);
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);
}
};
}]
);

View file

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

View file

@ -79,6 +79,16 @@ class EventsHandler(BaseHandler):
return
self.write({'events': MOCKUP_EVENTS.values()})
@gen.coroutine
def post(self, id_=None, **kwargs):
data = self.request.body
print 'aaaaaa', id_, data
@gen.coroutine
def put(self, id_=None, **kwargs):
data = self.request.body
print 'aaaaaaa put', id_, data
def main():
define("port", default=5242, help="run on the given port", type=int)