Skip to content

Commit

Permalink
added docs but no test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Fly committed Feb 15, 2015
1 parent cdd4837 commit b88723b
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 3 deletions.
5 changes: 2 additions & 3 deletions checklist-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ angular.module('checklist-model', [])

var comparator = angular.equals;

if (attrs.hasOwnProperty('checklistComparator'))
{
comparator = $parse(attrs.checklistComparator)(scope.$parent);
if (attrs.hasOwnProperty('checklistComparator')){
comparator = $parse(attrs.checklistComparator)(scope.$parent);
}

// watch UI checked change
Expand Down
25 changes: 25 additions & 0 deletions docs/blocks/filter/ctrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
app.controller('Ctrl6', function($scope) {
$scope.users = [
{id: 1, name: 'Aaron'},
{id: 2, name: 'David'},
{id: 3, name: 'Moses'}
];

$scope.selectedUsers = [];

$scope.compareFn = function(obj1, obj2){
return obj1.id === obj2.id;
};

$scope.checkFirst = function() {
$scope.selectedUsers = $scope.users[0];
};

$scope.checkAll = function() {
$scope.selectedUsers = $scope.users;
};

$scope.uncheckAll = function() {
$scope.selectedUsers = [];
}
});
16 changes: 16 additions & 0 deletions docs/blocks/filter/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
describe('filter', function() {

beforeEach(function() {
browser().navigateTo(mainUrl);
});

var s = '[ng-controller="Ctrl6"] ';
var a = s+' input[type="checkbox"]';

//it('should check of roles are changed to new value before checklist-change is fired', function() {
// element(s+'button[ng-click="checkFirst()"]').click();
// check(a, [1,0,0,0]);
// expect(element(s+'pre').text()).toBe('a');
//});

});
3 changes: 3 additions & 0 deletions docs/blocks/filter/view.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<label ng-repeat="(key, user) in users">
<input type="checkbox" checklist-model="selectedUsers" checklist-value="user" checklist-comparator="compareFn"> {{user.name}}
</label>
30 changes: 30 additions & 0 deletions docs/index.jade
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,36 @@ html(ng-app='app')
h3 js
pre.prettyprint= ctrlShow

.row
.col-xs-12
h2(style="margin-bottom: 0")= 'filter'
- var dir = 'docs/blocks/filter'
- var view = fs.readFileSync(dir+"/view.html").toString().trim()
- var ctrl = fs.readFileSync(dir+"/ctrl.js").toString().trim()
- var ctrlName = ctrl.match(/Ctrl\d/)[0]
- var ctrlShow = 'var app = angular.module("app", ["checklist-model"]);\n' + ctrl

.row(ng-controller=ctrlName)
.col-xs-12.col-sm-6
h3 demo
.well!= view
script!= ctrl
button(ng-click="checkAll()", style="margin-right: 10px") Check all
button(ng-click="uncheckAll()", style="margin-right: 10px") Uncheck all
button(ng-click="checkFirst()") Check first

.col-xs-12.col-sm-6
h3 user.users
pre {{selectedUsers}}

.row
.col-xs-12
h3 html
pre.prettyprint.ng-non-bindable= view

h3 js
pre.prettyprint= ctrlShow

.row
.col-xs-12
h2(style="margin-bottom: 0")= 'event'
Expand Down
80 changes: 80 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,86 @@ <h3>js</h3>
$scope.user.roles.splice(0, $scope.user.roles.length);
$scope.user.roles.push('a');
};
});</pre>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<h2 style="margin-bottom: 0">filter</h2>
</div>
</div>
<div ng-controller="Ctrl6" class="row">
<div class="col-xs-12 col-sm-6">
<h3>demo</h3>
<div class="well"><label ng-repeat="(key, user) in users">
<input type="checkbox" checklist-model="selectedUsers" checklist-value="user" checklist-comparator="compareFn"> {{user.name}}
</label></div>
<script>app.controller('Ctrl6', function($scope) {
$scope.users = [
{id: 1, name: 'Aaron'},
{id: 2, name: 'David'},
{id: 3, name: 'Moses'}
];

$scope.selectedUsers = [];

$scope.compareFn = function(obj1, obj2){
return obj1.id === obj2.id;
};

$scope.checkFirst = function() {
$scope.selectedUsers = $scope.users[0];
};

$scope.checkAll = function() {
$scope.selectedUsers = $scope.users;
};

$scope.uncheckAll = function() {
$scope.selectedUsers = [];
}
});</script>
<button ng-click="checkAll()" style="margin-right: 10px">Check all</button>
<button ng-click="uncheckAll()" style="margin-right: 10px">Uncheck all</button>
<button ng-click="checkFirst()">Check first</button>
</div>
<div class="col-xs-12 col-sm-6">
<h3>user.users</h3>
<pre>{{selectedUsers}}</pre>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<h3>html</h3>
<pre class="prettyprint ng-non-bindable">&lt;label ng-repeat=&quot;(key, user) in users&quot;&gt;
&lt;input type=&quot;checkbox&quot; checklist-model=&quot;selectedUsers&quot; checklist-value=&quot;user&quot; checklist-comparator=&quot;compareFn&quot;&gt; {{user.name}}
&lt;/label&gt;</pre>
<h3>js</h3>
<pre class="prettyprint">var app = angular.module(&quot;app&quot;, [&quot;checklist-model&quot;]);
app.controller('Ctrl6', function($scope) {
$scope.users = [
{id: 1, name: 'Aaron'},
{id: 2, name: 'David'},
{id: 3, name: 'Moses'}
];

$scope.selectedUsers = [];

$scope.compareFn = function(obj1, obj2){
return obj1.id === obj2.id;
};

$scope.checkFirst = function() {
$scope.selectedUsers = $scope.users[0];
};

$scope.checkAll = function() {
$scope.selectedUsers = $scope.users;
};

$scope.uncheckAll = function() {
$scope.selectedUsers = [];
}
});</pre>
</div>
</div>
Expand Down

0 comments on commit b88723b

Please sign in to comment.