luca 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +4 -1
- data/assets/javascripts/sandbox/application.coffee +1 -1
- data/assets/javascripts/sandbox/templates/main.luca +1 -0
- data/assets/stylesheets/sandbox/sandbox.scss +34 -2
- data/lib/luca/rails/version.rb +1 -1
- data/spec/components/fields/checkbox_array_spec.coffee +6 -40
- data/spec/core/view_spec.coffee +1 -1
- data/src/components/collection_view.coffee +7 -4
- data/src/components/fields/checkbox_array.coffee +65 -26
- data/src/framework.coffee +1 -1
- data/src/templates/fields/checkbox_array.luca +4 -5
- data/vendor/assets/javascripts/luca-ui-base.js +2 -2
- data/vendor/assets/javascripts/luca-ui-spec.js +105 -91
- data/vendor/assets/javascripts/luca-ui.js +95 -45
- data/vendor/assets/javascripts/luca-ui.min.js +3 -3
- metadata +2 -2
data/CHANGELOG
CHANGED
@@ -2,7 +2,6 @@ Sandbox.Application = Luca.Application.extend
|
|
2
2
|
name: 'sandbox_application'
|
3
3
|
el: '#viewport'
|
4
4
|
fluid: true
|
5
|
-
|
6
5
|
topNav:'top_navigation'
|
7
6
|
|
8
7
|
useKeyRouter: true
|
@@ -16,6 +15,7 @@ Sandbox.Application = Luca.Application.extend
|
|
16
15
|
name: 'pages'
|
17
16
|
components:[
|
18
17
|
name: "main"
|
18
|
+
ctype: "panel"
|
19
19
|
bodyTemplate: 'main'
|
20
20
|
,
|
21
21
|
name :"class_browser"
|
@@ -20,6 +20,7 @@
|
|
20
20
|
.span4
|
21
21
|
%h3 Component Driven Design
|
22
22
|
%p Luca is a collection of common components needed to build large single page applications. Twitter's Bootstrap is responsible for all of the styling, and Backbone.js is responsible for everything else.
|
23
|
+
%p Luca encourages a style of application design centered around building isolated components, and using framework helpers to glue them together in a very readable, declarative style.
|
23
24
|
|
24
25
|
.span4
|
25
26
|
%h3 Interchangeable
|
@@ -1,2 +1,34 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
#sample-component-wrapper {
|
2
|
+
border: 1px solid rgba(0,0,0,1);
|
3
|
+
box-shadow: 1px 1px 0px 0px rgba(0,0,0,0.5);
|
4
|
+
padding: 5px;
|
5
|
+
height: 420px;
|
6
|
+
h1 {
|
7
|
+
width: 100%;
|
8
|
+
text-align: center;
|
9
|
+
padding-top: 8px;
|
10
|
+
}
|
11
|
+
|
12
|
+
#sample-component {
|
13
|
+
height: 100%;
|
14
|
+
}
|
15
|
+
|
16
|
+
#form-vew, #collection-view, #toolbar {
|
17
|
+
margin: 4px 0px;
|
18
|
+
}
|
19
|
+
#form-view {
|
20
|
+
background-color: rgba(200,0,0,0.5);
|
21
|
+
border: 1px solid rgba(200,0,0,1);
|
22
|
+
height: 18%;
|
23
|
+
}
|
24
|
+
#collection-view {
|
25
|
+
background-color: rgba(0,200,0,0.5);
|
26
|
+
border: 1px solid rgba(0,200,0,1);
|
27
|
+
height: 50%;
|
28
|
+
}
|
29
|
+
#toolbar {
|
30
|
+
background-color: rgba(0,0,200,0.5);
|
31
|
+
border: 1px solid rgba(0,0,200,1);
|
32
|
+
height: 18%;
|
33
|
+
}
|
34
|
+
}
|
data/lib/luca/rails/version.rb
CHANGED
@@ -1,46 +1,12 @@
|
|
1
1
|
describe 'The Checkbox Array Field', ->
|
2
|
-
|
3
2
|
beforeEach ->
|
4
|
-
@
|
5
|
-
|
6
|
-
|
7
|
-
@formView = new Luca.components.FormView
|
8
|
-
components:[
|
9
|
-
ctype: "checkbox_array"
|
10
|
-
name: 'item_ids'
|
11
|
-
collection: collection
|
12
|
-
]
|
3
|
+
@collection = new Luca.Collection([id:"1",name:"jon"])
|
4
|
+
@field = new Luca.fields.CheckboxArray(collection: @collection)
|
13
5
|
|
14
|
-
|
15
|
-
@formView.loadModel(@model)
|
16
|
-
|
17
|
-
collection.reset([
|
18
|
-
id: "1", name: "Item1"
|
19
|
-
,
|
20
|
-
id: "2", name: "Item2"
|
21
|
-
,
|
22
|
-
id: "3", name: "Item3"
|
23
|
-
])
|
24
|
-
|
25
|
-
@field = @formView.getFields()[0]
|
26
|
-
|
27
|
-
it "should create a checkbox array field", ->
|
28
|
-
expect(@formView.currentModel()).toEqual(@model)
|
29
|
-
expect(@field.selectedItems).toEqual(["1"])
|
6
|
+
$('body').append("<div id='jasmine-helper' style='display:none' />")
|
30
7
|
|
31
|
-
|
32
|
-
expect(@field.$el.html()).toContain("Item1")
|
33
|
-
expect(@field.$el.html()).toContain("Item2")
|
34
|
-
expect(@field.$el.html()).toContain("Item3")
|
8
|
+
$('#jasmine-helper').html( @field.render().el )
|
35
9
|
|
36
|
-
it "should
|
37
|
-
expect(@field
|
38
|
-
expect(@field.$el.find("input[value='2']")[0].checked).toBeFalsy()
|
39
|
-
expect(@field.$el.find("input[value='3']")[0].checked).toBeFalsy()
|
40
|
-
|
41
|
-
it "should update the form model's attribute to be an array of selected items on click", ->
|
42
|
-
checkbox = $(@field.$el.find("input[value='2']")[0])
|
43
|
-
checkbox.prop("checked", true)
|
44
|
-
checkbox.click()
|
10
|
+
it "should render checkboxes", ->
|
11
|
+
expect( @field.checkboxesRendered ).toEqual true
|
45
12
|
|
46
|
-
expect(@field.getModel().get('item_ids')).toEqual(["1", "2"])
|
data/spec/core/view_spec.coffee
CHANGED
@@ -25,7 +25,7 @@ _.def("Luca.components.CollectionView").extends("Luca.components.Panel").with
|
|
25
25
|
unless @collection?
|
26
26
|
throw "Collection Views must specify a collection"
|
27
27
|
|
28
|
-
unless @itemTemplate? || @itemRenderer?
|
28
|
+
unless @itemTemplate? || @itemRenderer? || @itemProperty?
|
29
29
|
throw "Collection Views must specify an item template or item renderer function"
|
30
30
|
|
31
31
|
Luca.components.Panel::initialize.apply(@, arguments)
|
@@ -38,7 +38,6 @@ _.def("Luca.components.CollectionView").extends("Luca.components.Panel").with
|
|
38
38
|
attributesForItem: (item)->
|
39
39
|
_.extend {}, class: @itemClassName, "data-index": item.index
|
40
40
|
|
41
|
-
# expects an item object, which contains the
|
42
41
|
contentForItem: (item={})->
|
43
42
|
if @itemTemplate? and templateFn = Luca.template(@itemTemplate)
|
44
43
|
content = templateFn.call(@, item)
|
@@ -46,7 +45,8 @@ _.def("Luca.components.CollectionView").extends("Luca.components.Panel").with
|
|
46
45
|
if @itemRenderer? and _.isFunction( @itemRenderer )
|
47
46
|
content = @itemRenderer.call(@, item)
|
48
47
|
|
49
|
-
|
48
|
+
if @itemProperty
|
49
|
+
content = if _.isFunction(@itemProperty) then @itemProperty() else (item.model.get(@itemProperty) || item.model[ @itemProperty ])
|
50
50
|
|
51
51
|
makeItem: (model, index)->
|
52
52
|
item = if @prepareItem? then @prepareItem.call(@, model, index) else (model:model, index: index)
|
@@ -54,7 +54,10 @@ _.def("Luca.components.CollectionView").extends("Luca.components.Panel").with
|
|
54
54
|
make(@itemTagName, @attributesForItem(item), @contentForItem(item))
|
55
55
|
|
56
56
|
getModels: ()->
|
57
|
-
@collection
|
57
|
+
if @collection?.query and (@filter || @filterOptions)
|
58
|
+
@collection.query(@filter, @filterOptions)
|
59
|
+
else
|
60
|
+
@collection.models
|
58
61
|
|
59
62
|
refresh: ()->
|
60
63
|
panel = @
|
@@ -1,14 +1,19 @@
|
|
1
|
+
make = Luca.View::make
|
2
|
+
|
1
3
|
_.def('Luca.fields.CheckboxArray').extends('Luca.core.Field').with
|
4
|
+
version: 2
|
2
5
|
|
3
6
|
template: "fields/checkbox_array"
|
4
7
|
|
5
8
|
events:
|
6
9
|
"click input" : "clickHandler"
|
7
10
|
|
11
|
+
selectedItems: []
|
12
|
+
|
8
13
|
initialize: (@options={})->
|
9
14
|
_.extend @, @options
|
10
15
|
_.extend @, Luca.modules.Deferrable
|
11
|
-
_.bindAll @, "
|
16
|
+
_.bindAll @, "renderCheckboxes", "clickHandler", "checkSelected"
|
12
17
|
|
13
18
|
Luca.core.Field::initialize.apply @, arguments
|
14
19
|
|
@@ -17,7 +22,6 @@ _.def('Luca.fields.CheckboxArray').extends('Luca.core.Field').with
|
|
17
22
|
@label ||= @name
|
18
23
|
@valueField ||= "id"
|
19
24
|
@displayField ||= "name"
|
20
|
-
@selectedItems = []
|
21
25
|
|
22
26
|
afterInitialize: (@options={})->
|
23
27
|
try
|
@@ -25,41 +29,76 @@ _.def('Luca.fields.CheckboxArray').extends('Luca.core.Field').with
|
|
25
29
|
catch e
|
26
30
|
console.log "Error Configuring Collection", @, e.message
|
27
31
|
|
28
|
-
|
32
|
+
cbArray = @
|
29
33
|
|
30
|
-
|
31
|
-
|
32
|
-
@populateCheckboxes()
|
34
|
+
if @collection.length > 0
|
35
|
+
@renderCheckboxes()
|
33
36
|
else
|
34
|
-
@
|
37
|
+
@defer("renderCheckboxes").until(@collection,"reset")
|
35
38
|
|
36
39
|
clickHandler: (event)->
|
37
|
-
checkbox = event.target
|
38
|
-
|
39
|
-
|
40
|
+
checkbox = $(event.target)
|
41
|
+
|
42
|
+
if checkbox.prop('checked')
|
43
|
+
@selectedItems.push( checkbox.val() )
|
40
44
|
else
|
41
|
-
if @selectedItems.
|
42
|
-
@selectedItems = _
|
45
|
+
if _( @selectedItems ).include( checkbox.val() )
|
46
|
+
@selectedItems = _( @selectedItems ).without( checkbox.val() )
|
43
47
|
|
44
|
-
|
48
|
+
controls: ()->
|
49
|
+
@$('.controls')
|
45
50
|
|
46
|
-
|
47
|
-
controls
|
48
|
-
|
49
|
-
unless _.isUndefined(@getModel())
|
50
|
-
@selectedItems = @getModel().get(@name)
|
51
|
+
renderCheckboxes: ()->
|
52
|
+
@controls().empty()
|
53
|
+
@selectedItems = []
|
51
54
|
|
52
55
|
@collection.each (model)=>
|
53
56
|
value = model.get(@valueField)
|
54
57
|
label = model.get(@displayField)
|
55
|
-
input_id = _.uniqueId(
|
56
|
-
|
58
|
+
input_id = _.uniqueId("#{ @cid }_checkbox")
|
59
|
+
|
60
|
+
inputElement = make("input",type:"checkbox",name:@input_name,value:value,id: input_id)
|
61
|
+
element = make("label", {for:input_id}, inputElement)
|
62
|
+
|
63
|
+
$( element ).append(" #{ label }")
|
64
|
+
@controls().append( element )
|
65
|
+
|
66
|
+
@trigger("checkboxes:rendered", @checkboxesRendered = true)
|
67
|
+
@
|
68
|
+
|
69
|
+
uncheckAll: ()->
|
70
|
+
@allFields().prop('checked', false)
|
57
71
|
|
58
|
-
|
72
|
+
allFields: ()->
|
73
|
+
@controls().find("input[type='checkbox']")
|
74
|
+
|
75
|
+
checkSelected: (items)->
|
76
|
+
@selectedItems = items if items?
|
77
|
+
|
78
|
+
@uncheckAll()
|
79
|
+
|
80
|
+
for value in @selectedItems
|
81
|
+
checkbox = @controls().find("input[value='#{ value }']")
|
82
|
+
checkbox.prop('checked', true)
|
83
|
+
|
84
|
+
@selectedItems
|
85
|
+
|
86
|
+
getValue: ()->
|
87
|
+
@$(field).val() for field in @allFields() when @$(field).prop('checked')
|
88
|
+
|
89
|
+
setValue: (items)->
|
90
|
+
@selectedItems = items
|
91
|
+
|
92
|
+
if @checkboxesRendered is true
|
93
|
+
@checkSelected(items)
|
94
|
+
else
|
95
|
+
cbArray = @
|
96
|
+
@defer ()->
|
97
|
+
cbArray.checkSelected(items)
|
98
|
+
.until("checkboxes:rendered")
|
59
99
|
|
60
|
-
|
100
|
+
getValues: ()->
|
101
|
+
@getValue()
|
61
102
|
|
62
|
-
|
63
|
-
|
64
|
-
attributes[@name] = @selectedItems
|
65
|
-
@getModel().set(attributes)
|
103
|
+
setValues: (items)->
|
104
|
+
@setValue(items)
|
data/src/framework.coffee
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
.
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
.controls
|
1
|
+
.control-group
|
2
|
+
%label{:for=>"<%= input_id %>"}
|
3
|
+
<%= label %>
|
4
|
+
.controls
|
@@ -18,7 +18,7 @@
|
|
18
18
|
};
|
19
19
|
|
20
20
|
_.extend(Luca, {
|
21
|
-
VERSION: "0.9.
|
21
|
+
VERSION: "0.9.1",
|
22
22
|
core: {},
|
23
23
|
containers: {},
|
24
24
|
components: {},
|
@@ -1427,7 +1427,7 @@
|
|
1427
1427
|
}).call(this);
|
1428
1428
|
(function() {
|
1429
1429
|
Luca.templates || (Luca.templates = {});
|
1430
|
-
Luca.templates["fields/checkbox_array"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<div class=\'
|
1430
|
+
Luca.templates["fields/checkbox_array"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<div class=\'control-group\'>\n <label for=\'', input_id ,'\'>\n ', label ,'\n </label>\n <div class=\'controls\'></div>\n</div>\n');}return __p.join('');};
|
1431
1431
|
}).call(this);
|
1432
1432
|
(function() {
|
1433
1433
|
Luca.templates || (Luca.templates = {});
|
@@ -18,7 +18,7 @@
|
|
18
18
|
};
|
19
19
|
|
20
20
|
_.extend(Luca, {
|
21
|
-
VERSION: "0.9.
|
21
|
+
VERSION: "0.9.1",
|
22
22
|
core: {},
|
23
23
|
containers: {},
|
24
24
|
components: {},
|
@@ -1427,7 +1427,7 @@
|
|
1427
1427
|
}).call(this);
|
1428
1428
|
(function() {
|
1429
1429
|
Luca.templates || (Luca.templates = {});
|
1430
|
-
Luca.templates["fields/checkbox_array"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<div class=\'
|
1430
|
+
Luca.templates["fields/checkbox_array"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<div class=\'control-group\'>\n <label for=\'', input_id ,'\'>\n ', label ,'\n </label>\n <div class=\'controls\'></div>\n</div>\n');}return __p.join('');};
|
1431
1431
|
}).call(this);
|
1432
1432
|
(function() {
|
1433
1433
|
Luca.templates || (Luca.templates = {});
|
@@ -2736,7 +2736,7 @@
|
|
2736
2736
|
if (this.collection == null) {
|
2737
2737
|
throw "Collection Views must specify a collection";
|
2738
2738
|
}
|
2739
|
-
if (!((this.itemTemplate != null) || (this.itemRenderer != null))) {
|
2739
|
+
if (!((this.itemTemplate != null) || (this.itemRenderer != null) || (this.itemProperty != null))) {
|
2740
2740
|
throw "Collection Views must specify an item template or item renderer function";
|
2741
2741
|
}
|
2742
2742
|
Luca.components.Panel.prototype.initialize.apply(this, arguments);
|
@@ -2761,7 +2761,9 @@
|
|
2761
2761
|
if ((this.itemRenderer != null) && _.isFunction(this.itemRenderer)) {
|
2762
2762
|
content = this.itemRenderer.call(this, item);
|
2763
2763
|
}
|
2764
|
-
|
2764
|
+
if (this.itemProperty) {
|
2765
|
+
return content = _.isFunction(this.itemProperty) ? this.itemProperty() : item.model.get(this.itemProperty) || item.model[this.itemProperty];
|
2766
|
+
}
|
2765
2767
|
},
|
2766
2768
|
makeItem: function(model, index) {
|
2767
2769
|
var item;
|
@@ -2772,7 +2774,12 @@
|
|
2772
2774
|
return make(this.itemTagName, this.attributesForItem(item), this.contentForItem(item));
|
2773
2775
|
},
|
2774
2776
|
getModels: function() {
|
2775
|
-
|
2777
|
+
var _ref;
|
2778
|
+
if (((_ref = this.collection) != null ? _ref.query : void 0) && (this.filter || this.filterOptions)) {
|
2779
|
+
return this.collection.query(this.filter, this.filterOptions);
|
2780
|
+
} else {
|
2781
|
+
return this.collection.models;
|
2782
|
+
}
|
2776
2783
|
},
|
2777
2784
|
refresh: function() {
|
2778
2785
|
var panel;
|
@@ -2882,84 +2889,127 @@
|
|
2882
2889
|
|
2883
2890
|
}).call(this);
|
2884
2891
|
(function() {
|
2892
|
+
var make;
|
2893
|
+
|
2894
|
+
make = Luca.View.prototype.make;
|
2885
2895
|
|
2886
2896
|
_.def('Luca.fields.CheckboxArray')["extends"]('Luca.core.Field')["with"]({
|
2897
|
+
version: 2,
|
2887
2898
|
template: "fields/checkbox_array",
|
2888
2899
|
events: {
|
2889
2900
|
"click input": "clickHandler"
|
2890
2901
|
},
|
2902
|
+
selectedItems: [],
|
2891
2903
|
initialize: function(options) {
|
2892
2904
|
this.options = options != null ? options : {};
|
2893
2905
|
_.extend(this, this.options);
|
2894
2906
|
_.extend(this, Luca.modules.Deferrable);
|
2895
|
-
_.bindAll(this, "
|
2907
|
+
_.bindAll(this, "renderCheckboxes", "clickHandler", "checkSelected");
|
2896
2908
|
Luca.core.Field.prototype.initialize.apply(this, arguments);
|
2897
2909
|
this.input_id || (this.input_id = _.uniqueId('field'));
|
2898
2910
|
this.input_name || (this.input_name = this.name);
|
2899
2911
|
this.label || (this.label = this.name);
|
2900
2912
|
this.valueField || (this.valueField = "id");
|
2901
|
-
this.displayField || (this.displayField = "name");
|
2902
|
-
return this.selectedItems = [];
|
2913
|
+
return this.displayField || (this.displayField = "name");
|
2903
2914
|
},
|
2904
2915
|
afterInitialize: function(options) {
|
2916
|
+
var cbArray;
|
2905
2917
|
this.options = options != null ? options : {};
|
2906
2918
|
try {
|
2907
2919
|
this.configure_collection();
|
2908
2920
|
} catch (e) {
|
2909
2921
|
console.log("Error Configuring Collection", this, e.message);
|
2910
2922
|
}
|
2911
|
-
|
2912
|
-
|
2913
|
-
|
2914
|
-
var _ref;
|
2915
|
-
if (((_ref = this.collection) != null ? _ref.length : void 0) > 0) {
|
2916
|
-
return this.populateCheckboxes();
|
2923
|
+
cbArray = this;
|
2924
|
+
if (this.collection.length > 0) {
|
2925
|
+
return this.renderCheckboxes();
|
2917
2926
|
} else {
|
2918
|
-
return this.
|
2927
|
+
return this.defer("renderCheckboxes").until(this.collection, "reset");
|
2919
2928
|
}
|
2920
2929
|
},
|
2921
2930
|
clickHandler: function(event) {
|
2922
2931
|
var checkbox;
|
2923
|
-
checkbox = event.target;
|
2924
|
-
if (checkbox.checked) {
|
2925
|
-
this.selectedItems.push(checkbox.
|
2932
|
+
checkbox = $(event.target);
|
2933
|
+
if (checkbox.prop('checked')) {
|
2934
|
+
return this.selectedItems.push(checkbox.val());
|
2926
2935
|
} else {
|
2927
|
-
if (this.selectedItems.
|
2928
|
-
this.selectedItems = _
|
2936
|
+
if (_(this.selectedItems).include(checkbox.val())) {
|
2937
|
+
return this.selectedItems = _(this.selectedItems).without(checkbox.val());
|
2929
2938
|
}
|
2930
2939
|
}
|
2931
|
-
return this._updateModel();
|
2932
2940
|
},
|
2933
|
-
|
2934
|
-
|
2935
|
-
|
2936
|
-
|
2937
|
-
|
2938
|
-
|
2939
|
-
|
2940
|
-
}
|
2941
|
+
controls: function() {
|
2942
|
+
return this.$('.controls');
|
2943
|
+
},
|
2944
|
+
renderCheckboxes: function() {
|
2945
|
+
var _this = this;
|
2946
|
+
this.controls().empty();
|
2947
|
+
this.selectedItems = [];
|
2941
2948
|
this.collection.each(function(model) {
|
2942
|
-
var input_id, label, value;
|
2949
|
+
var element, inputElement, input_id, label, value;
|
2943
2950
|
value = model.get(_this.valueField);
|
2944
2951
|
label = model.get(_this.displayField);
|
2945
|
-
input_id = _.uniqueId(
|
2946
|
-
|
2947
|
-
|
2952
|
+
input_id = _.uniqueId("" + _this.cid + "_checkbox");
|
2953
|
+
inputElement = make("input", {
|
2954
|
+
type: "checkbox",
|
2955
|
+
name: _this.input_name,
|
2948
2956
|
value: value,
|
2949
|
-
|
2950
|
-
|
2951
|
-
|
2952
|
-
|
2953
|
-
|
2954
|
-
|
2957
|
+
id: input_id
|
2958
|
+
});
|
2959
|
+
element = make("label", {
|
2960
|
+
"for": input_id
|
2961
|
+
}, inputElement);
|
2962
|
+
$(element).append(" " + label);
|
2963
|
+
return _this.controls().append(element);
|
2955
2964
|
});
|
2956
|
-
|
2965
|
+
this.trigger("checkboxes:rendered", this.checkboxesRendered = true);
|
2966
|
+
return this;
|
2967
|
+
},
|
2968
|
+
uncheckAll: function() {
|
2969
|
+
return this.allFields().prop('checked', false);
|
2957
2970
|
},
|
2958
|
-
|
2959
|
-
|
2960
|
-
|
2961
|
-
|
2962
|
-
|
2971
|
+
allFields: function() {
|
2972
|
+
return this.controls().find("input[type='checkbox']");
|
2973
|
+
},
|
2974
|
+
checkSelected: function(items) {
|
2975
|
+
var checkbox, value, _i, _len, _ref;
|
2976
|
+
if (items != null) this.selectedItems = items;
|
2977
|
+
this.uncheckAll();
|
2978
|
+
_ref = this.selectedItems;
|
2979
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
2980
|
+
value = _ref[_i];
|
2981
|
+
checkbox = this.controls().find("input[value='" + value + "']");
|
2982
|
+
checkbox.prop('checked', true);
|
2983
|
+
}
|
2984
|
+
return this.selectedItems;
|
2985
|
+
},
|
2986
|
+
getValue: function() {
|
2987
|
+
var field, _i, _len, _ref, _results;
|
2988
|
+
_ref = this.allFields();
|
2989
|
+
_results = [];
|
2990
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
2991
|
+
field = _ref[_i];
|
2992
|
+
if (this.$(field).prop('checked')) _results.push(this.$(field).val());
|
2993
|
+
}
|
2994
|
+
return _results;
|
2995
|
+
},
|
2996
|
+
setValue: function(items) {
|
2997
|
+
var cbArray;
|
2998
|
+
this.selectedItems = items;
|
2999
|
+
if (this.checkboxesRendered === true) {
|
3000
|
+
return this.checkSelected(items);
|
3001
|
+
} else {
|
3002
|
+
cbArray = this;
|
3003
|
+
return this.defer(function() {
|
3004
|
+
return cbArray.checkSelected(items);
|
3005
|
+
}).until("checkboxes:rendered");
|
3006
|
+
}
|
3007
|
+
},
|
3008
|
+
getValues: function() {
|
3009
|
+
return this.getValue();
|
3010
|
+
},
|
3011
|
+
setValues: function(items) {
|
3012
|
+
return this.setValue(items);
|
2963
3013
|
}
|
2964
3014
|
});
|
2965
3015
|
|
@@ -4082,56 +4132,20 @@
|
|
4082
4132
|
|
4083
4133
|
describe('The Checkbox Array Field', function() {
|
4084
4134
|
beforeEach(function() {
|
4085
|
-
|
4086
|
-
this.model = new Backbone.Model({
|
4087
|
-
item_ids: ["1"]
|
4088
|
-
});
|
4089
|
-
collection = new Luca.Collection;
|
4090
|
-
this.formView = new Luca.components.FormView({
|
4091
|
-
components: [
|
4092
|
-
{
|
4093
|
-
ctype: "checkbox_array",
|
4094
|
-
name: 'item_ids',
|
4095
|
-
collection: collection
|
4096
|
-
}
|
4097
|
-
]
|
4098
|
-
});
|
4099
|
-
this.formView.render();
|
4100
|
-
this.formView.loadModel(this.model);
|
4101
|
-
collection.reset([
|
4135
|
+
this.collection = new Luca.Collection([
|
4102
4136
|
{
|
4103
4137
|
id: "1",
|
4104
|
-
name: "
|
4105
|
-
}, {
|
4106
|
-
id: "2",
|
4107
|
-
name: "Item2"
|
4108
|
-
}, {
|
4109
|
-
id: "3",
|
4110
|
-
name: "Item3"
|
4138
|
+
name: "jon"
|
4111
4139
|
}
|
4112
4140
|
]);
|
4113
|
-
|
4114
|
-
|
4115
|
-
|
4116
|
-
|
4117
|
-
return
|
4118
|
-
});
|
4119
|
-
it("should render the list of checkboxes", function() {
|
4120
|
-
expect(this.field.$el.html()).toContain("Item1");
|
4121
|
-
expect(this.field.$el.html()).toContain("Item2");
|
4122
|
-
return expect(this.field.$el.html()).toContain("Item3");
|
4123
|
-
});
|
4124
|
-
it("should check off each checkbox in the collection that is selected", function() {
|
4125
|
-
expect(this.field.$el.find("input[value='1']")[0].checked).toBeTruthy();
|
4126
|
-
expect(this.field.$el.find("input[value='2']")[0].checked).toBeFalsy();
|
4127
|
-
return expect(this.field.$el.find("input[value='3']")[0].checked).toBeFalsy();
|
4141
|
+
this.field = new Luca.fields.CheckboxArray({
|
4142
|
+
collection: this.collection
|
4143
|
+
});
|
4144
|
+
$('body').append("<div id='jasmine-helper' style='display:none' />");
|
4145
|
+
return $('#jasmine-helper').html(this.field.render().el);
|
4128
4146
|
});
|
4129
|
-
return it("should
|
4130
|
-
|
4131
|
-
checkbox = $(this.field.$el.find("input[value='2']")[0]);
|
4132
|
-
checkbox.prop("checked", true);
|
4133
|
-
checkbox.click();
|
4134
|
-
return expect(this.field.getModel().get('item_ids')).toEqual(["1", "2"]);
|
4147
|
+
return it("should render checkboxes", function() {
|
4148
|
+
return expect(this.field.checkboxesRendered).toEqual(true);
|
4135
4149
|
});
|
4136
4150
|
});
|
4137
4151
|
|
@@ -5022,7 +5036,7 @@
|
|
5022
5036
|
beforeEach(function() {
|
5023
5037
|
this.fetchSpy = sinon.spy();
|
5024
5038
|
this.customSpy = sinon.spy();
|
5025
|
-
this.collection = new Luca.Collection({
|
5039
|
+
this.collection = new Luca.Collection([], {
|
5026
5040
|
url: "/models",
|
5027
5041
|
fetch: this.fetchSpy,
|
5028
5042
|
custom: this.customSpy,
|