Skip to content

Commit

Permalink
Merge branch 'fix-issue-7'
Browse files Browse the repository at this point in the history
  • Loading branch information
charlypoly committed Jun 21, 2014
2 parents 673c6cd + e889e78 commit 7e222eb
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 68 deletions.
58 changes: 28 additions & 30 deletions dist/angular-coq.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ angular.module('coq').directive('coqModelAttribute', [
'coqModelForm',
function ($compile, $log, coqModelForm) {
return {
priority: 101,
priority: 999,
require: '?^coqModel',
restrict: 'A',
link: function (scope, element, attrs, coqModelController) {
Expand All @@ -286,7 +286,6 @@ angular.module('coq').directive('coqModelAttribute', [
var inputConfig = coqModelController.coqModel.$attributesDefinition[attrs.coqModelAttribute] || false;
if (inputConfig) {
element.attr(coqModelForm.getInputAttributes(inputConfig));
element.attr('ng-model', coqModelController.coqModelName + '.' + attrs.coqModelAttribute);
}
}
};
Expand All @@ -313,38 +312,37 @@ angular.module('coq').directive('coqModel', [
'$compile',
function ($compile) {
return {
priority: 102,
priority: 1000,
controller: 'coqModelController',
restrict: 'A',
link: {
pre: function (scope, element, attrs, coqModelController) {
coqModelController.init(attrs);
if (element[0].tagName === 'FORM' && !$(element).find('input[coq-model-attribute]').length) {
var paragraph, input, paragraphs = [];
angular.forEach(coqModelController.coqModel.$attributesDefinition, function (_, name) {
paragraph = document.createElement('p');
input = document.createElement('input');
angular.element(input).attr('coq-model-attribute', name);
angular.element(paragraph).append(input);
paragraphs.push(paragraph);
});
if (coqModelController.insertMode === 'replace') {
element.empty();
element.append(paragraphs);
} else {
element[coqModelController.insertMode](paragraphs);
compile: function () {
return {
pre: function (scope, element, attrs, coqModelController) {
coqModelController.init(attrs);
},
post: function (scope, element, attrs, coqModelController) {
if (element[0].tagName === 'FORM' && !$(element).find('input[coq-model-attribute]').length) {
var paragraph, input, paragraphs = [];
angular.forEach(coqModelController.coqModel.$attributesDefinition, function (_, name) {
paragraph = document.createElement('p');
input = document.createElement('input');
angular.element(input).attr('coq-model-attribute', name);
angular.element(input).attr('ng-model', coqModelController.coqModelName + '.' + name);
angular.element(paragraph).append(input);
paragraphs.push(paragraph);
});
if (coqModelController.insertMode === 'replace') {
element.empty();
element.append(paragraphs);
} else {
element[coqModelController.insertMode](paragraphs);
}
$compile(element.contents())(scope);
$compile(element.contents())(scope);
paragraphs = null;
}
$compile(element.contents())(scope);
paragraphs = null;
} else {
element.addClass('coq-clean');
}
},
post: function (scope, iElement) {
if (!$(iElement).hasClass('coq-clean')) {
$compile(iElement.contents())(scope);
}
}
};
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-coq.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions examples/directives.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

app.controller('myController', function($scope, TeamsModel) {
$scope.team = new TeamsModel({ name : 'test', id : 1 });
$scope.team2 = new TeamsModel();
$scope.team2 = new TeamsModel({ name : 'charly' });
});
</script>
</head>
Expand All @@ -38,17 +38,20 @@ <h2>Edit a team</h2>

<form coq-model="team" ng-model="myForm"></form>

{{ team | json }}
team : {{ team | json }}

<hr>

<h2>Create a team</h2>

<form coq-model="team2" ng-model="myForm" ng-submit="team2.save()">
<p>Name : <input coq-model-attribute="name"></p>
<form coq-model="team2" ng-model="myForm2" ng-submit="team2.save()">
<p>Name : <input coq-model-attribute="name" ng-model="team2.name"></p>

<input type="submit">
<a ng-click="team2.save()" href>click me</a>
</form>

team2 : {{ team2 | json }}
</div>
</body>
</html>
4 changes: 2 additions & 2 deletions lib/directives/coq-model-attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

angular.module('coq').directive('coqModelAttribute', function($compile, $log, coqModelForm) {
return {
priority : 101,
priority : 999,
require : '?^coqModel',
restrict : 'A',
link: function(scope, element, attrs, coqModelController) {
Expand All @@ -14,8 +14,8 @@ angular.module('coq').directive('coqModelAttribute', function($compile, $log, co
var inputConfig = coqModelController.coqModel.$attributesDefinition[attrs.coqModelAttribute] || false;
if (inputConfig) {
element.attr(coqModelForm.getInputAttributes(inputConfig));
element.attr('ng-model', coqModelController.coqModelName + '.' + attrs.coqModelAttribute);
}

}
};

Expand Down
57 changes: 27 additions & 30 deletions lib/directives/coq-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,37 @@ angular.module('coq').controller('coqModelController', function($scope, $parse)

angular.module('coq').directive('coqModel', function($compile) {
return {
priority : 102,
priority : 1000,
controller : 'coqModelController',
restrict : 'A',
link : {
pre : function(scope, element, attrs, coqModelController) {

coqModelController.init(attrs);

if (element[0].tagName === 'FORM' && !$(element).find('input[coq-model-attribute]').length) {
var paragraph, input, paragraphs = [];
angular.forEach(coqModelController.coqModel.$attributesDefinition, function(_, name) {
paragraph = document.createElement('p');
input = document.createElement('input');
angular.element(input).attr('coq-model-attribute', name);
angular.element(paragraph).append(input);
paragraphs.push(paragraph);
});
if (coqModelController.insertMode === 'replace') {
element.empty();
element.append(paragraphs);
} else {
element[coqModelController.insertMode](paragraphs);
compile : function() {
return {
pre : function(scope, element, attrs, coqModelController) {
coqModelController.init(attrs);
},
post : function(scope, element, attrs, coqModelController) {
if (element[0].tagName === 'FORM' && !$(element).find('input[coq-model-attribute]').length) {
var paragraph, input, paragraphs = [];
angular.forEach(coqModelController.coqModel.$attributesDefinition, function(_, name) {
paragraph = document.createElement('p');
input = document.createElement('input');
angular.element(input).attr('coq-model-attribute', name);
angular.element(input).attr('ng-model', coqModelController.coqModelName + '.' + name);
angular.element(paragraph).append(input);
paragraphs.push(paragraph);
});
if (coqModelController.insertMode === 'replace') {
element.empty();
element.append(paragraphs);
} else {
element[coqModelController.insertMode](paragraphs);
}
$compile(element.contents())(scope);
$compile(element.contents())(scope);
paragraphs = null;
}
$compile(element.contents())(scope);
paragraphs = null;
} else {
element.addClass('coq-clean');
}
},
post : function (scope, iElement) {
if (!$(iElement).hasClass('coq-clean')) {
$compile(iElement.contents())(scope);
}
}
};
}
};

Expand Down
2 changes: 1 addition & 1 deletion test/spec/directives/coq-model-attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('coq-model-attribute directive', function() {

var input;

element = $compile('<form coq-model="user"><input coq-model-attribute="name"></form>')(scope);
element = $compile('<form coq-model="user"><input coq-model-attribute="name" ng-model="user.name"></form>')(scope);

input = element.find('input');

Expand Down

0 comments on commit 7e222eb

Please sign in to comment.