Created
January 17, 2014 13:46
-
-
Save pixelastic/8473584 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.controller('controllerSearchClientCreateCataloguePromotions', function ($scope, $http) { | |
var defaultCode = {code:''}; | |
$scope.defaultPromoCode = defaultCode; | |
// Default values | |
$scope.promoCodes = [{code:''}, {code:''}, {code:''}]; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="block block-search-client-create-promotions" data-ng-controller="controllerSearchClientCreateCataloguePromotions"> | |
<div class="form-horizontal" data-kiss-list-builder="promoCodes"> | |
<div class="control-group" data-ng-repeat="promoCode in promoCodes"> | |
<label class="control-label" for="promoCodeValue">Code promo {{$index+1}}</label> | |
<div class="controls"> | |
<input type="text" name="promoCodeValue" data-ng-model="promoCode.code" /> | |
<span class="display-field">{{promoCode.code}}</span> | |
<a class="delete delete-promo-code" data-list-index="{{$index}}"><i class="icon-minus-sign"></i>Supprimer.</a> | |
</div> | |
</div> | |
<div class="actions"> | |
<a class="add add-promo-code" data-list-add="{{defaultPromoCode}}"><i class="icon-plus-sign"></i>Ajouter code promo.</a> | |
<a class="add add-sponsor">Ajouter code parrain</a> | |
</div> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// To be applied on a repeated list. Adds "add new element" and "remove | |
// element" behavior. | |
app.directive('kissListBuilder', function() { | |
return { | |
template : '', | |
link: function(scope, element, attributes) { | |
var scopeKeyName = attributes.kissListBuilder; | |
if (!scope[scopeKeyName]) return false; | |
var parentList = scope[scopeKeyName]; | |
// Click on .add elements adds new item to list | |
element.find('.add').on('click', function() { | |
var element = angular.element(this); | |
var itemToAdd = angular.fromJson(element.attr('data-list-add')); | |
parentList.push(itemToAdd); | |
return false; | |
}); | |
// Click on .delete elements remove binded item from list | |
element.find('.remove').on('click', function() { | |
var element = angular.element(this); | |
var index = element.attr('data-list-index'); | |
console.log(index); | |
parentList.splice(index, 1); | |
return false; | |
}); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment