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.
@@ -18,7 +18,7 @@
18
18
  };
19
19
 
20
20
  _.extend(Luca, {
21
- VERSION: "0.9.0",
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=\'form-horizontal\'>\n <div class=\'control-group\'>\n <label for=\'', input_id ,'\'>\n ', label ,'\n </label>\n <div class=\'controls\'></div>\n </div>\n</div>\n');}return __p.join('');};
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
- return content || "";
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
- return this.collection.models;
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, "populateCheckboxes", "clickHandler", "_updateModel");
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
- return this.collection.bind("reset", this.populateCheckboxes);
2912
- },
2913
- afterRender: function() {
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.collection.trigger("reset");
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.value);
2932
+ checkbox = $(event.target);
2933
+ if (checkbox.prop('checked')) {
2934
+ return this.selectedItems.push(checkbox.val());
2926
2935
  } else {
2927
- if (this.selectedItems.indexOf(checkbox.value) !== -1) {
2928
- this.selectedItems = _.without(this.selectedItems, [checkbox.value]);
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
- populateCheckboxes: function() {
2934
- var controls,
2935
- _this = this;
2936
- controls = $(this.el).find('.controls');
2937
- controls.empty();
2938
- if (!_.isUndefined(this.getModel())) {
2939
- this.selectedItems = this.getModel().get(this.name);
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('field');
2946
- controls.append(Luca.templates["fields/checkbox_array_item"]({
2947
- label: label,
2952
+ input_id = _.uniqueId("" + _this.cid + "_checkbox");
2953
+ inputElement = make("input", {
2954
+ type: "checkbox",
2955
+ name: _this.input_name,
2948
2956
  value: value,
2949
- input_id: input_id,
2950
- input_name: _this.input_name
2951
- }));
2952
- if (_(_this.selectedItems).indexOf(value) !== -1) {
2953
- return _this.$("#" + input_id).attr("checked", "checked");
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
- return $(this.container).append(this.$el);
2965
+ this.trigger("checkboxes:rendered", this.checkboxesRendered = true);
2966
+ return this;
2967
+ },
2968
+ uncheckAll: function() {
2969
+ return this.allFields().prop('checked', false);
2970
+ },
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();
2957
3010
  },
2958
- _updateModel: function() {
2959
- var attributes;
2960
- attributes = {};
2961
- attributes[this.name] = this.selectedItems;
2962
- return this.getModel().set(attributes);
3011
+ setValues: function(items) {
3012
+ return this.setValue(items);
2963
3013
  }
2964
3014
  });
2965
3015