Permalink
Browse files

Merge branch 'master' of github.com:elpassion/elranks

  • Loading branch information...
2 parents 69987f5 + ac8fa61 commit 03c0e42912df370596bae6e13d633f4d821830b8 @aserafin aserafin committed Jan 3, 2014
@@ -36,9 +36,21 @@ var myAppModule = angular.module('MyApp', ['ui.select2','rails'])
$scope.home = { score: 0 };
$scope.away = { score: 0 };
+ var validatePlayers = function() {
+ return $scope.home.player_id != $scope.away.player_id;
+
+ };
+
$scope.save = function() {
+ if (!validatePlayers()) {
+ alert('check selected players');
+ return false;
+ };
console.log($scope.home, $scope.away);
- new Match({ match: { home: $scope.home, away: $scope.away }}).create().then(function(){ window.location = '/'; });
+ new Match({ match: { home: $scope.home, away: $scope.away }}).create().then(
+ function(){ window.location = '/'; },
+ function(error) { $scope.errors = error; }
+ );
};
Player.query().then(function(data){
@@ -251,3 +251,7 @@ h1 {
+.alert {
+ width: 90%;
+ margin: 1em auto;
+}
@@ -36,10 +36,10 @@ input::-webkit-inner-spin-button {
.hometeam, .awayteam {
margin-top: 35px;
display: block;
- width: 60px;
+
img {
+ max-width: 60px;
display: block;
- border: 1px solid #eee;
}
}
@@ -13,9 +13,9 @@ def confirm
end
def create
- build_resource.save
- build_resource.finish!
-
+ if build_resource.save
+ build_resource.finish!
+ end
create!
end
@@ -1,16 +1,20 @@
.new-match(ng-controller="PlayersCtrl")
.preview.clearfix
.hometeam
- img(ng-src="{{logoUrl(home.team_id)}}" ng-show="home.team_id" width="60" height="37")
+ img(ng-src="{{logoUrl(home.team_id)}}" ng-show="home.team_id")
.score
input(type='text' step="1" min="0" placeholder="0" value="" ng-model="home.score" autofocus)
input(type='text' step="1" min="0" placeholder="0" value="" ng-model="away.score")
.awayteam
- img(ng-src="{{logoUrl(away.team_id)}}" ng-show="away.team_id" width="60" height="37")
+ img(ng-src="{{logoUrl(away.team_id)}}" ng-show="away.team_id")
hr.c-b
+ .alert.alert-danger(ng-show="errors")
+ | Something went wrong. Please check if you entered correct data.
+
+
.teams
.team
@@ -28,16 +32,19 @@
.players
.player
h4 Choose player
- select(name='home' ui-select2="" ng-model="home.player_id" required)
+ select(name='home' ui-select2="" ng-model="home.player_id" required ng-change="updatePlayers()")
option(ng-repeat="player in players" value="{{player.id}}")
| {{player.name}}
.player
h4 Choose player
- select(name='away' ui-select2="" ng-model="away.player_id" required)
+ select(name='away' ui-select2="" ng-model="away.player_id" required ng-change="updatePlayers()")
option(ng-repeat="player in players" value="{{player.id}}")
| {{player.name}}
.actions.clearfix
button.btn.btn-lg.btn-success.save(ng-click="save()") Save match
+
+
+

0 comments on commit 03c0e42

Please sign in to comment.