Blame view
resources/js/tipEditorComponent.js
4.48 KB
e77200db5 Initial commit |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
angular.module('footyroom').component('tipEditor', { template: /* html */ ` <div fr-litelay="$ctrl.isSaving || $ctrl.isLoading"> <div class="modal-body"> <div class="form-group"> <label>Match ID</label> <input class="form-control" type="text" ng-model="$ctrl.tip.matchId" placeholder="Example: 123456789"> <span class="help-block"> You can get match ID from the URL of a match to which this tip belongs. Checkout Live Scores to get a list of upcoming matches and their URLs. </span> </div> <div class="form-group"> <label>Prediction</label> <input class="form-control" type="text" ng-model="$ctrl.tip.prediction" placeholder="Example: Both teams to score - Yes"> </div> <div class="form-group"> <label>Odds</label> <input class="form-control" type="text" ng-model="$ctrl.tip.odds" placeholder="Example: 1.99"> </div> <div class="form-group"> <label>Status</label> <select class="form-control" ng-model="$ctrl.tip.status"> <option value="pending">Pending</option> <option value="correct">Correct</option> <option value="wrong">Wrong</option> <option value="neutral">Neutral</option> </select> <span class="help-block"> All tips start as "Pending", but when it's settled you will have to update its outcome here. </span> </div> <div class="form-group"> <label>Actual Result (optional)</label> <input class="form-control" type="text" ng-model="$ctrl.tip.result" placeholder="Examples: 1 : 2, Yes, Neymar"> <span class="help-block"> This is usually the final score of the game or some other outcome. If this field is left empty final score will be shown automatically. </span> </div> </div> <div class="modal-footer"> <div class="pull-left"> <button ng-click="$ctrl.remove()" ng-if="$ctrl.tip.id" class="btn btn-default">Delete</button> </div> <div class="pull-right"> <button class="btn btn-default" ng-click="$ctrl.dismiss()">Cancel</button> <button class="btn btn-primary" ng-click="$ctrl.save()">Save</button> </div> </div> </div> `, bindings: { id: '@', dismiss: '&', }, controller: [ '$http', function ($http) { const vm = this; vm.$onInit = init; vm.save = save; vm.remove = remove; function init() { if (vm.id) { vm.isLoading = true; $http.get(`/tips/${this.id}.json`).then(function (response) { vm.tip = response.data; vm.isLoading = false; }); } else { vm.tip = { status: 'pending', }; } } function save() { vm.isSaving = true; const persist = vm.tip.id ? $http.put(`/tips/${vm.tip.id}`, vm.tip) : $http.post('/tips', vm.tip); persist .then(() => { window.location.reload(); }) .catch(() => { vm.isSaving = false; }); } function remove() { vm.isSaving = true; $http.delete(`/tips/${this.id}`) .then(() => { window.location.reload(); }) .catch(() => { vm.isSaving = false; }); } }, ], }); |