chr 0.1.4 → 0.1.5
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.
- checksums.yaml +4 -4
- data/Gruntfile.coffee +22 -21
- data/app/assets/javascripts/chr-dist.js +307 -262
- data/app/assets/javascripts/chr.coffee +22 -21
- data/app/assets/javascripts/chr/core/{_chr.coffee → chr.coffee} +0 -0
- data/app/assets/javascripts/chr/core/{_item.coffee → item.coffee} +2 -2
- data/app/assets/javascripts/chr/core/{_listReorder.coffee → list-reorder.coffee} +1 -1
- data/app/assets/javascripts/chr/core/{_listScroll.coffee → list-scroll.coffee} +1 -1
- data/app/assets/javascripts/chr/core/{_listSearch.coffee → list-search.coffee} +0 -0
- data/app/assets/javascripts/chr/core/{_list.coffee → list.coffee} +2 -0
- data/app/assets/javascripts/chr/core/{_module.coffee → module.coffee} +0 -0
- data/app/assets/javascripts/chr/core/{_utils.coffee → utils.coffee} +0 -0
- data/app/assets/javascripts/chr/core/{_view.coffee → view.coffee} +2 -2
- data/app/assets/javascripts/chr/form/{_form.coffee → form.coffee} +0 -0
- data/app/assets/javascripts/chr/form/{_inputCheckbox.coffee → input-checkbox.coffee} +0 -0
- data/app/assets/javascripts/chr/form/{_inputColor.coffee → input-color.coffee} +0 -0
- data/app/assets/javascripts/chr/form/{_inputFile.coffee → input-file.coffee} +0 -0
- data/app/assets/javascripts/chr/form/{_inputHidden.coffee → input-hidden.coffee} +0 -0
- data/app/assets/javascripts/chr/form/{_inputList.coffee → input-list.coffee} +0 -0
- data/app/assets/javascripts/chr/form/{_inputSelect.coffee → input-select.coffee} +0 -0
- data/app/assets/javascripts/chr/form/{_inputString.coffee → input-string.coffee} +0 -0
- data/app/assets/javascripts/chr/form/{_inputText.coffee → input-text.coffee} +0 -0
- data/app/assets/javascripts/chr/form/{_nestedForm.coffee → nested-form.coffee} +0 -0
- data/app/assets/javascripts/chr/store/store-mongosteen.coffee +111 -0
- data/app/assets/javascripts/chr/store/store-rest.coffee +90 -0
- data/app/assets/javascripts/chr/store/store.coffee +274 -0
- data/chr.gemspec +2 -2
- data/lib/chr/version.rb +1 -1
- data/package.json +1 -1
- metadata +26 -25
- data/app/assets/javascripts/chr/store/_store.coffee +0 -104
- data/app/assets/javascripts/chr/store/_storeRails.coffee +0 -167
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e6bbd63bec5db5e3e4f86134f26d13086c88d15
|
4
|
+
data.tar.gz: 041a2c987d9253e3c579fe1f059c3d83a4960763
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82ac289396d965e246640641926cb853c74622cb300b806bfb9ec5b852c63cb126693b2a042da804527353dd2d5c6cf18d20ca29adf352c07fd3a72cbc545982
|
7
|
+
data.tar.gz: edc30ec3c9bba84f3595a8167e44f909276336b3972f552166d63a01b7959f1284ac4e74697b246912f14b7de8bb284415a22c6c0c7e70d2fa9af5fee6a61303
|
data/Gruntfile.coffee
CHANGED
@@ -9,30 +9,31 @@ module.exports = (grunt) ->
|
|
9
9
|
files:
|
10
10
|
'build/chr.js': [
|
11
11
|
#
|
12
|
-
'app/assets/javascripts/chr/core/
|
13
|
-
'app/assets/javascripts/chr/core/
|
14
|
-
'app/assets/javascripts/chr/core/
|
15
|
-
'app/assets/javascripts/chr/core/
|
16
|
-
'app/assets/javascripts/chr/core/
|
17
|
-
'app/assets/javascripts/chr/core/
|
18
|
-
'app/assets/javascripts/chr/core/
|
12
|
+
'app/assets/javascripts/chr/core/item.coffee'
|
13
|
+
'app/assets/javascripts/chr/core/list.coffee'
|
14
|
+
'app/assets/javascripts/chr/core/list-search.coffee'
|
15
|
+
'app/assets/javascripts/chr/core/list-scroll.coffee'
|
16
|
+
'app/assets/javascripts/chr/core/list-reorder.coffee'
|
17
|
+
'app/assets/javascripts/chr/core/view.coffee'
|
18
|
+
'app/assets/javascripts/chr/core/module.coffee'
|
19
19
|
#
|
20
|
-
'app/assets/javascripts/chr/form/
|
21
|
-
'app/assets/javascripts/chr/form/
|
22
|
-
'app/assets/javascripts/chr/form/
|
23
|
-
'app/assets/javascripts/chr/form/
|
24
|
-
'app/assets/javascripts/chr/form/
|
25
|
-
'app/assets/javascripts/chr/form/
|
26
|
-
'app/assets/javascripts/chr/form/
|
27
|
-
'app/assets/javascripts/chr/form/
|
28
|
-
'app/assets/javascripts/chr/form/
|
29
|
-
'app/assets/javascripts/chr/form/
|
20
|
+
'app/assets/javascripts/chr/form/form.coffee'
|
21
|
+
'app/assets/javascripts/chr/form/input-string.coffee'
|
22
|
+
'app/assets/javascripts/chr/form/input-checkbox.coffee'
|
23
|
+
'app/assets/javascripts/chr/form/input-color.coffee'
|
24
|
+
'app/assets/javascripts/chr/form/input-file.coffee'
|
25
|
+
'app/assets/javascripts/chr/form/input-hidden.coffee'
|
26
|
+
'app/assets/javascripts/chr/form/input-list.coffee'
|
27
|
+
'app/assets/javascripts/chr/form/input-select.coffee'
|
28
|
+
'app/assets/javascripts/chr/form/input-text.coffee'
|
29
|
+
'app/assets/javascripts/chr/form/nested-form.coffee'
|
30
30
|
#
|
31
|
-
'app/assets/javascripts/chr/store/
|
32
|
-
'app/assets/javascripts/chr/store/
|
31
|
+
'app/assets/javascripts/chr/store/store.coffee'
|
32
|
+
'app/assets/javascripts/chr/store/store-rest.coffee'
|
33
|
+
'app/assets/javascripts/chr/store/store-mongosteen.coffee'
|
33
34
|
#
|
34
|
-
'app/assets/javascripts/chr/core/
|
35
|
-
'app/assets/javascripts/chr/core/
|
35
|
+
'app/assets/javascripts/chr/core/utils.coffee'
|
36
|
+
'app/assets/javascripts/chr/core/chr.coffee'
|
36
37
|
]
|
37
38
|
|
38
39
|
concat:
|
@@ -2759,9 +2759,9 @@ this.Item = (function() {
|
|
2759
2759
|
};
|
2760
2760
|
|
2761
2761
|
Item.prototype.position = function() {
|
2762
|
-
var
|
2763
|
-
|
2764
|
-
return this.object[
|
2762
|
+
var positionFieldName;
|
2763
|
+
positionFieldName = this.config.arrayStore.sortBy;
|
2764
|
+
return parseFloat(this.object[positionFieldName]);
|
2765
2765
|
};
|
2766
2766
|
|
2767
2767
|
return Item;
|
@@ -2865,7 +2865,7 @@ this.List = (function() {
|
|
2865
2865
|
};
|
2866
2866
|
|
2867
2867
|
function List(module, name, config1, parentList) {
|
2868
|
-
var ref;
|
2868
|
+
var base, ref;
|
2869
2869
|
this.module = module;
|
2870
2870
|
this.name = name;
|
2871
2871
|
this.config = config1;
|
@@ -2917,6 +2917,9 @@ this.List = (function() {
|
|
2917
2917
|
if (this.config.objectStore) {
|
2918
2918
|
this._bindConfigObjectStore();
|
2919
2919
|
}
|
2920
|
+
if (typeof (base = this.config).onListInit === "function") {
|
2921
|
+
base.onListInit(this);
|
2922
|
+
}
|
2920
2923
|
}
|
2921
2924
|
|
2922
2925
|
List.prototype.selectItem = function(href) {
|
@@ -3026,7 +3029,7 @@ this._listBindScroll = function(listEl) {
|
|
3026
3029
|
viewHeight = $container.height();
|
3027
3030
|
if (listHeight < (viewHeight + e.target.scrollTop + 100)) {
|
3028
3031
|
return listEl._loading(function() {
|
3029
|
-
return arrayStore.
|
3032
|
+
return arrayStore.load();
|
3030
3033
|
});
|
3031
3034
|
}
|
3032
3035
|
}
|
@@ -3081,7 +3084,7 @@ this._listBindReorder = function(listEl) {
|
|
3081
3084
|
objectPositionValue = _getObjectNewPosition(e.target);
|
3082
3085
|
objectId = $(e.target).attr('data-id');
|
3083
3086
|
value = {};
|
3084
|
-
value["[" + arrayStore.sortBy] = objectPositionValue;
|
3087
|
+
value["[" + arrayStore.sortBy] = "" + objectPositionValue;
|
3085
3088
|
arrayStore.update(objectId, value, {
|
3086
3089
|
onSuccess: function(object) {},
|
3087
3090
|
onError: function(errors) {}
|
@@ -3257,13 +3260,13 @@ this.View = (function() {
|
|
3257
3260
|
};
|
3258
3261
|
|
3259
3262
|
View.prototype.onSave = function(e) {
|
3260
|
-
var
|
3263
|
+
var serializedFormObj;
|
3261
3264
|
e.preventDefault();
|
3262
|
-
|
3265
|
+
serializedFormObj = this.form.serialize();
|
3263
3266
|
if (this.object) {
|
3264
|
-
return this._updateObject(
|
3267
|
+
return this._updateObject(serializedFormObj);
|
3265
3268
|
} else {
|
3266
|
-
return this._createObject(
|
3269
|
+
return this._createObject(serializedFormObj);
|
3267
3270
|
}
|
3268
3271
|
};
|
3269
3272
|
|
@@ -4610,27 +4613,27 @@ _chrFormInputs['form'] = NestedForm;
|
|
4610
4613
|
this.ObjectStore = (function() {
|
4611
4614
|
function ObjectStore(config) {
|
4612
4615
|
this.config = config != null ? config : {};
|
4613
|
-
this.
|
4616
|
+
this._initialize_database();
|
4614
4617
|
}
|
4615
4618
|
|
4616
|
-
ObjectStore.prototype.
|
4619
|
+
ObjectStore.prototype._update_data_object = function(value, callback) {
|
4620
|
+
return typeof callback === "function" ? callback($.extend(this._data, value)) : void 0;
|
4621
|
+
};
|
4622
|
+
|
4623
|
+
ObjectStore.prototype._fetch_data = function() {
|
4617
4624
|
return this._data = this.config.data;
|
4618
4625
|
};
|
4619
4626
|
|
4620
|
-
ObjectStore.prototype.
|
4621
|
-
return this.
|
4627
|
+
ObjectStore.prototype._initialize_database = function() {
|
4628
|
+
return this._fetch_data();
|
4622
4629
|
};
|
4623
4630
|
|
4624
4631
|
ObjectStore.prototype.get = function() {
|
4625
4632
|
return this._data;
|
4626
4633
|
};
|
4627
4634
|
|
4628
|
-
ObjectStore.prototype._updateDataObject = function(value, callback) {
|
4629
|
-
return typeof callback === "function" ? callback($.extend(this._data, value)) : void 0;
|
4630
|
-
};
|
4631
|
-
|
4632
4635
|
ObjectStore.prototype.update = function(id, value, callback) {
|
4633
|
-
return this.
|
4636
|
+
return this._update_data_object(value, callback);
|
4634
4637
|
};
|
4635
4638
|
|
4636
4639
|
return ObjectStore;
|
@@ -4638,12 +4641,56 @@ this.ObjectStore = (function() {
|
|
4638
4641
|
})();
|
4639
4642
|
|
4640
4643
|
this.ArrayStore = (function() {
|
4641
|
-
ArrayStore
|
4642
|
-
var
|
4644
|
+
function ArrayStore(config) {
|
4645
|
+
var ref, ref1, ref2, ref3, ref4;
|
4646
|
+
this.config = config != null ? config : {};
|
4647
|
+
this._map = {};
|
4648
|
+
this._data = [];
|
4649
|
+
this.sortBy = (ref = this.config.sortBy) != null ? ref : false;
|
4650
|
+
this.sortReverse = (ref1 = this.config.sortReverse) != null ? ref1 : false;
|
4651
|
+
this.reorderable = (ref2 = this.config.reorderable) != null ? ref2 : false;
|
4652
|
+
if (this.sortBy === false) {
|
4653
|
+
this.newItemOnTop = (ref3 = this.config.newItemOnTop) != null ? ref3 : true;
|
4654
|
+
} else {
|
4655
|
+
this.newItemOnTop = (ref4 = this.config.newItemOnTop) != null ? ref4 : false;
|
4656
|
+
}
|
4657
|
+
this._initialize_reorderable();
|
4658
|
+
this._initialize_database();
|
4659
|
+
}
|
4660
|
+
|
4661
|
+
ArrayStore.prototype._initialize_reorderable = function() {
|
4662
|
+
var ref;
|
4663
|
+
if (this.reorderable) {
|
4664
|
+
if (this.reorderable.positionFieldName) {
|
4665
|
+
this.sortBy = this.reorderable.positionFieldName;
|
4666
|
+
return this.sortReverse = (ref = this.reorderable.sortReverse) != null ? ref : false;
|
4667
|
+
} else {
|
4668
|
+
console.log('Wrong reordering configuration, missing positionFieldName parameter.');
|
4669
|
+
return this.reorderable = false;
|
4670
|
+
}
|
4671
|
+
}
|
4672
|
+
};
|
4673
|
+
|
4674
|
+
ArrayStore.prototype._initialize_database = function() {};
|
4675
|
+
|
4676
|
+
ArrayStore.prototype._fetch_data = function() {
|
4677
|
+
var i, len, o, ref;
|
4678
|
+
if (this.config.data) {
|
4679
|
+
ref = this.config.data;
|
4680
|
+
for (i = 0, len = ref.length; i < len; i++) {
|
4681
|
+
o = ref[i];
|
4682
|
+
this._add_data_object(o);
|
4683
|
+
}
|
4684
|
+
}
|
4685
|
+
return $(this).trigger('objects_added');
|
4686
|
+
};
|
4687
|
+
|
4688
|
+
ArrayStore.prototype._sort_data = function() {
|
4689
|
+
var direction, fieldName, sortByMethod;
|
4643
4690
|
if (this.sortBy) {
|
4644
4691
|
fieldName = this.sortBy;
|
4645
4692
|
direction = this.sortReverse ? 1 : -1;
|
4646
|
-
|
4693
|
+
sortByMethod = function(key, a, b, dir) {
|
4647
4694
|
if (a[key] > b[key]) {
|
4648
4695
|
return -1 * dir;
|
4649
4696
|
}
|
@@ -4653,28 +4700,39 @@ this.ArrayStore = (function() {
|
|
4653
4700
|
return 0;
|
4654
4701
|
};
|
4655
4702
|
return this._data = this._data.sort(function(a, b) {
|
4656
|
-
return
|
4703
|
+
return sortByMethod(fieldName, a, b, direction);
|
4657
4704
|
});
|
4658
4705
|
}
|
4659
4706
|
};
|
4660
4707
|
|
4661
|
-
ArrayStore.prototype.
|
4662
|
-
var i, len, o, ref
|
4708
|
+
ArrayStore.prototype._get_data_object_position = function(id) {
|
4709
|
+
var i, ids, len, o, ref;
|
4710
|
+
ids = [];
|
4663
4711
|
ref = this._data;
|
4664
|
-
results = [];
|
4665
4712
|
for (i = 0, len = ref.length; i < len; i++) {
|
4666
4713
|
o = ref[i];
|
4667
|
-
|
4714
|
+
if (o) {
|
4715
|
+
ids.push(o._id);
|
4716
|
+
}
|
4668
4717
|
}
|
4669
|
-
return
|
4718
|
+
return $.inArray(id, ids);
|
4670
4719
|
};
|
4671
4720
|
|
4672
|
-
ArrayStore.prototype.
|
4721
|
+
ArrayStore.prototype._normalize_object_id = function(object) {
|
4722
|
+
if (object.id) {
|
4723
|
+
object._id = object.id;
|
4724
|
+
delete object.id;
|
4725
|
+
}
|
4726
|
+
return object;
|
4727
|
+
};
|
4728
|
+
|
4729
|
+
ArrayStore.prototype._add_data_object = function(object, callback) {
|
4673
4730
|
var position;
|
4731
|
+
object = this._normalize_object_id(object);
|
4674
4732
|
this._map[object._id] = object;
|
4675
4733
|
this._data.push(object);
|
4676
|
-
this.
|
4677
|
-
position = this.
|
4734
|
+
this._sort_data();
|
4735
|
+
position = this._get_data_object_position(object._id);
|
4678
4736
|
return $(this).trigger('object_added', {
|
4679
4737
|
object: object,
|
4680
4738
|
position: position,
|
@@ -4682,36 +4740,24 @@ this.ArrayStore = (function() {
|
|
4682
4740
|
});
|
4683
4741
|
};
|
4684
4742
|
|
4685
|
-
ArrayStore.prototype.
|
4686
|
-
var id, o, ref;
|
4687
|
-
ref = this._map;
|
4688
|
-
for (id in ref) {
|
4689
|
-
o = ref[id];
|
4690
|
-
$(this).trigger('object_removed', {
|
4691
|
-
object_id: id
|
4692
|
-
});
|
4693
|
-
}
|
4694
|
-
this._map = {};
|
4695
|
-
return this._data = [];
|
4696
|
-
};
|
4697
|
-
|
4698
|
-
ArrayStore.prototype._removeDataObject = function(id) {
|
4743
|
+
ArrayStore.prototype._add_data_object_on_top = function(object, callback) {
|
4699
4744
|
var position;
|
4700
|
-
|
4701
|
-
|
4702
|
-
|
4703
|
-
|
4704
|
-
|
4705
|
-
|
4706
|
-
|
4745
|
+
object = this._normalize_object_id(object);
|
4746
|
+
this._map[object._id] = object;
|
4747
|
+
this._data.unshift(object);
|
4748
|
+
position = 0;
|
4749
|
+
return $(this).trigger('object_added', {
|
4750
|
+
object: object,
|
4751
|
+
position: position,
|
4752
|
+
callback: callback
|
4707
4753
|
});
|
4708
4754
|
};
|
4709
4755
|
|
4710
|
-
ArrayStore.prototype.
|
4756
|
+
ArrayStore.prototype._update_data_object = function(id, value, callback) {
|
4711
4757
|
var object, position;
|
4712
4758
|
object = $.extend(this.get(id), value);
|
4713
|
-
this.
|
4714
|
-
position = this.
|
4759
|
+
this._sort_data();
|
4760
|
+
position = this._get_data_object_position(id);
|
4715
4761
|
return $(this).trigger('object_changed', {
|
4716
4762
|
object: object,
|
4717
4763
|
position: position,
|
@@ -4719,27 +4765,41 @@ this.ArrayStore = (function() {
|
|
4719
4765
|
});
|
4720
4766
|
};
|
4721
4767
|
|
4722
|
-
ArrayStore.prototype.
|
4723
|
-
var
|
4724
|
-
|
4725
|
-
|
4726
|
-
|
4727
|
-
o = ref[i];
|
4728
|
-
if (o) {
|
4729
|
-
ids.push(o._id);
|
4730
|
-
}
|
4768
|
+
ArrayStore.prototype._remove_data_object = function(id) {
|
4769
|
+
var position;
|
4770
|
+
position = this._get_data_object_position(id);
|
4771
|
+
if (position >= 0) {
|
4772
|
+
delete this._data[position];
|
4731
4773
|
}
|
4732
|
-
|
4774
|
+
delete this._map[id];
|
4775
|
+
return $(this).trigger('object_removed', {
|
4776
|
+
object_id: id
|
4777
|
+
});
|
4733
4778
|
};
|
4734
4779
|
|
4735
|
-
function
|
4736
|
-
|
4780
|
+
ArrayStore.prototype._reset_data = function() {
|
4781
|
+
var id, o, ref;
|
4782
|
+
ref = this._map;
|
4783
|
+
for (id in ref) {
|
4784
|
+
o = ref[id];
|
4785
|
+
$(this).trigger('object_removed', {
|
4786
|
+
object_id: id
|
4787
|
+
});
|
4788
|
+
}
|
4737
4789
|
this._map = {};
|
4738
|
-
this._data = [];
|
4739
|
-
|
4740
|
-
}
|
4790
|
+
return this._data = [];
|
4791
|
+
};
|
4741
4792
|
|
4742
|
-
ArrayStore.prototype.
|
4793
|
+
ArrayStore.prototype._parse_form_object = function(serializedFormObject) {
|
4794
|
+
var fieldName, key, object, value;
|
4795
|
+
object = {};
|
4796
|
+
for (key in serializedFormObject) {
|
4797
|
+
value = serializedFormObject[key];
|
4798
|
+
fieldName = key.replace('[', '').replace(']', '');
|
4799
|
+
object[fieldName] = value;
|
4800
|
+
}
|
4801
|
+
return object;
|
4802
|
+
};
|
4743
4803
|
|
4744
4804
|
ArrayStore.prototype.off = function(eventType) {
|
4745
4805
|
if (eventType) {
|
@@ -4754,20 +4814,7 @@ this.ArrayStore = (function() {
|
|
4754
4814
|
return callback(e, data);
|
4755
4815
|
});
|
4756
4816
|
if (eventType === 'object_added') {
|
4757
|
-
return this.
|
4758
|
-
}
|
4759
|
-
};
|
4760
|
-
|
4761
|
-
ArrayStore.prototype._fetchData = function() {
|
4762
|
-
var i, len, o, ref, results;
|
4763
|
-
if (this.config.data) {
|
4764
|
-
ref = this.config.data;
|
4765
|
-
results = [];
|
4766
|
-
for (i = 0, len = ref.length; i < len; i++) {
|
4767
|
-
o = ref[i];
|
4768
|
-
results.push(this._addDataObject(o));
|
4769
|
-
}
|
4770
|
-
return results;
|
4817
|
+
return this._fetch_data();
|
4771
4818
|
}
|
4772
4819
|
};
|
4773
4820
|
|
@@ -4775,18 +4822,33 @@ this.ArrayStore = (function() {
|
|
4775
4822
|
return this._map[id];
|
4776
4823
|
};
|
4777
4824
|
|
4778
|
-
ArrayStore.prototype.
|
4779
|
-
|
4825
|
+
ArrayStore.prototype.push = function(serializedFormObject, callbacks) {
|
4826
|
+
var object;
|
4827
|
+
object = this._parse_form_object(serializedFormObject);
|
4828
|
+
if (!object._id) {
|
4829
|
+
object._id = Date.now();
|
4830
|
+
}
|
4831
|
+
if (this.newItemOnTop) {
|
4832
|
+
return this._add_data_object_on_top(object, callbacks.onSuccess);
|
4833
|
+
} else {
|
4834
|
+
return this._add_data_object(object, callbacks.onSuccess);
|
4835
|
+
}
|
4780
4836
|
};
|
4781
4837
|
|
4782
|
-
ArrayStore.prototype.
|
4783
|
-
|
4784
|
-
|
4785
|
-
|
4838
|
+
ArrayStore.prototype.update = function(id, serializedFormObject, callbacks) {
|
4839
|
+
var object;
|
4840
|
+
object = this._parse_form_object(serializedFormObject);
|
4841
|
+
return this._update_data_object(id, object, callbacks.onSuccess);
|
4786
4842
|
};
|
4787
4843
|
|
4788
4844
|
ArrayStore.prototype.remove = function(id) {
|
4789
|
-
return this.
|
4845
|
+
return this._remove_data_object(id);
|
4846
|
+
};
|
4847
|
+
|
4848
|
+
ArrayStore.prototype.reset = function(callback) {
|
4849
|
+
this._sort_data();
|
4850
|
+
$(this).trigger('objects_added');
|
4851
|
+
return typeof callback === "function" ? callback() : void 0;
|
4790
4852
|
};
|
4791
4853
|
|
4792
4854
|
return ArrayStore;
|
@@ -4796,111 +4858,30 @@ this.ArrayStore = (function() {
|
|
4796
4858
|
var extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
4797
4859
|
hasProp = {}.hasOwnProperty;
|
4798
4860
|
|
4799
|
-
this.
|
4800
|
-
extend(
|
4801
|
-
|
4802
|
-
function RailsObjectStore() {
|
4803
|
-
return RailsObjectStore.__super__.constructor.apply(this, arguments);
|
4804
|
-
}
|
4805
|
-
|
4806
|
-
return RailsObjectStore;
|
4807
|
-
|
4808
|
-
})(ObjectStore);
|
4861
|
+
this.RestArrayStore = (function(superClass) {
|
4862
|
+
extend(RestArrayStore, superClass);
|
4809
4863
|
|
4810
|
-
|
4811
|
-
|
4812
|
-
|
4813
|
-
function RailsArrayStore() {
|
4814
|
-
return RailsArrayStore.__super__.constructor.apply(this, arguments);
|
4864
|
+
function RestArrayStore() {
|
4865
|
+
return RestArrayStore.__super__.constructor.apply(this, arguments);
|
4815
4866
|
}
|
4816
4867
|
|
4817
|
-
|
4818
|
-
var ref, ref1, ref2;
|
4819
|
-
this.resetData = false;
|
4820
|
-
this.searchable = (ref = this.config.searchable) != null ? ref : false;
|
4821
|
-
this.pagination = (ref1 = this.config.pagination) != null ? ref1 : true;
|
4822
|
-
this.reorderable = (ref2 = this.config.reorderable) != null ? ref2 : false;
|
4868
|
+
RestArrayStore.prototype._initialize_database = function() {
|
4823
4869
|
this.dataFetchLock = false;
|
4824
|
-
this.
|
4825
|
-
this.searchQuery = '';
|
4826
|
-
if (this.reorderable) {
|
4827
|
-
this.sortBy = this.reorderable.positionFieldName;
|
4828
|
-
this.sortReverse = this.reorderable.sortReverse || false;
|
4829
|
-
}
|
4830
|
-
if (this.config.data) {
|
4831
|
-
return this.pagesCounter = 1;
|
4832
|
-
}
|
4833
|
-
};
|
4834
|
-
|
4835
|
-
RailsArrayStore.prototype._addDataObjectToTheTop = function(object, callback) {
|
4836
|
-
var position;
|
4837
|
-
this._map[object._id] = object;
|
4838
|
-
this._data.unshift(object);
|
4839
|
-
position = 0;
|
4840
|
-
return $(this).trigger('object_added', {
|
4841
|
-
object: object,
|
4842
|
-
position: position,
|
4843
|
-
callback: callback
|
4844
|
-
});
|
4845
|
-
};
|
4846
|
-
|
4847
|
-
RailsArrayStore.prototype._wrapRailsObject = function(object) {
|
4848
|
-
var attr_name, attr_value, data, i, len, value, values;
|
4849
|
-
data = new FormData();
|
4850
|
-
for (attr_name in object) {
|
4851
|
-
attr_value = object[attr_name];
|
4852
|
-
if (attr_name.indexOf('[__LIST__') > -1) {
|
4853
|
-
attr_name = attr_name.replace('__LIST__', '');
|
4854
|
-
values = attr_value.split(',');
|
4855
|
-
for (i = 0, len = values.length; i < len; i++) {
|
4856
|
-
value = values[i];
|
4857
|
-
data.append("" + this.config.resource + attr_name + "[]", value);
|
4858
|
-
}
|
4859
|
-
} else {
|
4860
|
-
if (attr_name.startsWith('__FILE__')) {
|
4861
|
-
attr_name = attr_name.replace('__FILE__', '');
|
4862
|
-
}
|
4863
|
-
data.append("" + this.config.resource + attr_name, attr_value);
|
4864
|
-
}
|
4865
|
-
}
|
4866
|
-
return data;
|
4870
|
+
return this.ajaxConfig = {};
|
4867
4871
|
};
|
4868
4872
|
|
4869
|
-
|
4870
|
-
var
|
4871
|
-
|
4872
|
-
|
4873
|
-
if (url.indexOf('?') > 0) {
|
4874
|
-
url = url + "&" + extraParamString;
|
4875
|
-
} else {
|
4876
|
-
url = url + "?" + extraParamString;
|
4877
|
-
}
|
4878
|
-
}
|
4879
|
-
return url;
|
4880
|
-
};
|
4881
|
-
|
4882
|
-
RailsArrayStore.prototype._delete = function(id, success) {
|
4883
|
-
this.dataFetchLock = true;
|
4884
|
-
return $.ajax({
|
4885
|
-
type: 'DELETE',
|
4886
|
-
url: this._urlWithParams(this.config.path + "/" + id + ".json"),
|
4887
|
-
success: (function(_this) {
|
4888
|
-
return function(data, textStatus, jqXHR) {
|
4889
|
-
_this.dataFetchLock = false;
|
4890
|
-
return typeof success === "function" ? success(data) : void 0;
|
4891
|
-
};
|
4892
|
-
})(this)
|
4893
|
-
});
|
4873
|
+
RestArrayStore.prototype._resource_url = function(type, id) {
|
4874
|
+
var objectPath;
|
4875
|
+
objectPath = id ? "/" + id : '';
|
4876
|
+
return "" + this.config.path + objectPath;
|
4894
4877
|
};
|
4895
4878
|
|
4896
|
-
|
4897
|
-
|
4898
|
-
|
4899
|
-
|
4900
|
-
|
4901
|
-
data:
|
4902
|
-
processData: false,
|
4903
|
-
contentType: false,
|
4879
|
+
RestArrayStore.prototype._ajax = function(type, id, data, success, error) {
|
4880
|
+
var options;
|
4881
|
+
options = $.extend(this.ajaxConfig, {
|
4882
|
+
url: this._resource_url(type, id),
|
4883
|
+
type: type,
|
4884
|
+
data: data,
|
4904
4885
|
success: (function(_this) {
|
4905
4886
|
return function(data, textStatus, jqXHR) {
|
4906
4887
|
_this.dataFetchLock = false;
|
@@ -4914,110 +4895,174 @@ this.RailsArrayStore = (function(superClass) {
|
|
4914
4895
|
};
|
4915
4896
|
})(this)
|
4916
4897
|
});
|
4917
|
-
};
|
4918
|
-
|
4919
|
-
RailsArrayStore.prototype._put = function(id, object, success, error) {
|
4920
4898
|
this.dataFetchLock = true;
|
4921
|
-
return $.ajax(
|
4922
|
-
type: 'PUT',
|
4923
|
-
url: this._urlWithParams(this.config.path + "/" + id + ".json"),
|
4924
|
-
data: this._wrapRailsObject(object),
|
4925
|
-
processData: false,
|
4926
|
-
contentType: false,
|
4927
|
-
success: (function(_this) {
|
4928
|
-
return function(data, textStatus, jqXHR) {
|
4929
|
-
_this.dataFetchLock = false;
|
4930
|
-
return typeof success === "function" ? success(data) : void 0;
|
4931
|
-
};
|
4932
|
-
})(this),
|
4933
|
-
error: (function(_this) {
|
4934
|
-
return function(jqXHR, textStatus, errorThrown) {
|
4935
|
-
_this.dataFetchLock = false;
|
4936
|
-
return typeof error === "function" ? error(jqXHR.responseJSON) : void 0;
|
4937
|
-
};
|
4938
|
-
})(this)
|
4939
|
-
});
|
4899
|
+
return $.ajax(options);
|
4940
4900
|
};
|
4941
4901
|
|
4942
|
-
|
4943
|
-
this.
|
4944
|
-
|
4945
|
-
return function(data) {
|
4902
|
+
RestArrayStore.prototype.load = function(success) {
|
4903
|
+
return this._ajax('GET', null, {}, ((function(_this) {
|
4904
|
+
return function(dataObject) {
|
4946
4905
|
var i, len, o;
|
4947
|
-
if (
|
4948
|
-
|
4949
|
-
|
4950
|
-
o
|
4951
|
-
_this._addDataObject(o);
|
4906
|
+
if (dataObject.length > 0) {
|
4907
|
+
for (i = 0, len = dataObject.length; i < len; i++) {
|
4908
|
+
o = dataObject[i];
|
4909
|
+
_this._add_data_object(o);
|
4952
4910
|
}
|
4953
4911
|
}
|
4954
|
-
_this.dataFetchLock = false;
|
4955
4912
|
if (typeof success === "function") {
|
4956
4913
|
success();
|
4957
4914
|
}
|
4958
4915
|
return $(_this).trigger('objects_added');
|
4959
4916
|
};
|
4960
|
-
})(this));
|
4917
|
+
})(this)));
|
4918
|
+
};
|
4919
|
+
|
4920
|
+
RestArrayStore.prototype.push = function(serializedFormObject, callbacks) {
|
4921
|
+
var obj;
|
4922
|
+
obj = this._parse_form_object(serializedFormObject);
|
4923
|
+
return this._ajax('POST', null, obj, ((function(_this) {
|
4924
|
+
return function(dataObject) {
|
4925
|
+
if (_this.newItemOnTop) {
|
4926
|
+
return _this._add_data_object_on_top(dataObject, callbacks.onSuccess);
|
4927
|
+
} else {
|
4928
|
+
return _this._add_data_object(dataObject, callbacks.onSuccess);
|
4929
|
+
}
|
4930
|
+
};
|
4931
|
+
})(this)), callbacks.onError);
|
4932
|
+
};
|
4933
|
+
|
4934
|
+
RestArrayStore.prototype.update = function(id, serializedFormObject, callbacks) {
|
4935
|
+
var obj;
|
4936
|
+
obj = this._parse_form_object(serializedFormObject);
|
4937
|
+
return this._ajax('PUT', id, obj, ((function(_this) {
|
4938
|
+
return function(dataObject) {
|
4939
|
+
return _this._update_data_object(id, dataObject, callbacks.onSuccess);
|
4940
|
+
};
|
4941
|
+
})(this)), callbacks.onError);
|
4942
|
+
};
|
4943
|
+
|
4944
|
+
RestArrayStore.prototype.remove = function(id) {
|
4945
|
+
return this._ajax('DELETE', id, {}, ((function(_this) {
|
4946
|
+
return function() {
|
4947
|
+
return _this._remove_data_object(id);
|
4948
|
+
};
|
4949
|
+
})(this)));
|
4950
|
+
};
|
4951
|
+
|
4952
|
+
RestArrayStore.prototype.reset = function(callback) {
|
4953
|
+
this._reset_data();
|
4954
|
+
return this.load(callback);
|
4955
|
+
};
|
4956
|
+
|
4957
|
+
return RestArrayStore;
|
4958
|
+
|
4959
|
+
})(ArrayStore);
|
4960
|
+
|
4961
|
+
var extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
4962
|
+
hasProp = {}.hasOwnProperty;
|
4963
|
+
|
4964
|
+
this.MongosteenArrayStore = (function(superClass) {
|
4965
|
+
extend(MongosteenArrayStore, superClass);
|
4966
|
+
|
4967
|
+
function MongosteenArrayStore() {
|
4968
|
+
return MongosteenArrayStore.__super__.constructor.apply(this, arguments);
|
4969
|
+
}
|
4970
|
+
|
4971
|
+
MongosteenArrayStore.prototype._initialize_database = function() {
|
4972
|
+
var ref, ref1;
|
4973
|
+
this.dataFetchLock = false;
|
4974
|
+
this.ajaxConfig = {
|
4975
|
+
processData: false,
|
4976
|
+
contentType: false
|
4977
|
+
};
|
4978
|
+
this.searchable = (ref = this.config.searchable) != null ? ref : false;
|
4979
|
+
this.searchQuery = '';
|
4980
|
+
this.pagination = (ref1 = this.config.pagination) != null ? ref1 : true;
|
4981
|
+
this.pagesCounter = 0;
|
4982
|
+
if (this.config.data) {
|
4983
|
+
return this.pagination = false;
|
4984
|
+
}
|
4985
|
+
};
|
4986
|
+
|
4987
|
+
MongosteenArrayStore.prototype._resource_url = function(type, id) {
|
4988
|
+
var extraParamsString, objectPath, url;
|
4989
|
+
objectPath = id ? "/" + id : '';
|
4990
|
+
url = "" + this.config.path + objectPath + ".json";
|
4991
|
+
if (this.config.urlParams) {
|
4992
|
+
extraParamsString = $.param(this.config.urlParams);
|
4993
|
+
url = url + "?" + extraParamsString;
|
4994
|
+
}
|
4995
|
+
return url;
|
4996
|
+
};
|
4997
|
+
|
4998
|
+
MongosteenArrayStore.prototype._parse_form_object = function(serializedFormObject) {
|
4999
|
+
var attr_name, attr_value, formDataObject, i, len, value, values;
|
5000
|
+
formDataObject = new FormData();
|
5001
|
+
for (attr_name in serializedFormObject) {
|
5002
|
+
attr_value = serializedFormObject[attr_name];
|
5003
|
+
if (attr_name.indexOf('[__LIST__') > -1) {
|
5004
|
+
attr_name = attr_name.replace('__LIST__', '');
|
5005
|
+
values = attr_value.split(',');
|
5006
|
+
for (i = 0, len = values.length; i < len; i++) {
|
5007
|
+
value = values[i];
|
5008
|
+
formDataObject.append("" + this.config.resource + attr_name + "[]", value);
|
5009
|
+
}
|
5010
|
+
} else {
|
5011
|
+
if (attr_name.startsWith('__FILE__')) {
|
5012
|
+
attr_name = attr_name.replace('__FILE__', '');
|
5013
|
+
}
|
5014
|
+
formDataObject.append("" + this.config.resource + attr_name, attr_value);
|
5015
|
+
}
|
5016
|
+
}
|
5017
|
+
return formDataObject;
|
4961
5018
|
};
|
4962
5019
|
|
4963
|
-
|
5020
|
+
MongosteenArrayStore.prototype.load = function(success) {
|
4964
5021
|
var params;
|
4965
5022
|
params = {};
|
4966
5023
|
if (this.pagination) {
|
4967
5024
|
params.page = this.pagesCounter + 1;
|
4968
|
-
params.perPage = _itemsPerPageRequest;
|
5025
|
+
params.perPage = typeof _itemsPerPageRequest !== "undefined" && _itemsPerPageRequest !== null ? _itemsPerPageRequest : 20;
|
4969
5026
|
}
|
4970
|
-
if (this.searchQuery.length > 0) {
|
5027
|
+
if (this.searchable && this.searchQuery.length > 0) {
|
4971
5028
|
params.search = this.searchQuery;
|
4972
5029
|
}
|
4973
|
-
|
5030
|
+
params = $.param(params);
|
5031
|
+
return this._ajax('GET', null, params, ((function(_this) {
|
5032
|
+
return function(dataObject) {
|
5033
|
+
var i, len, o;
|
5034
|
+
if (dataObject.length > 0) {
|
5035
|
+
_this.pagesCounter = _this.pagesCounter + 1;
|
5036
|
+
for (i = 0, len = dataObject.length; i < len; i++) {
|
5037
|
+
o = dataObject[i];
|
5038
|
+
_this._add_data_object(o);
|
5039
|
+
}
|
5040
|
+
}
|
5041
|
+
if (typeof success === "function") {
|
5042
|
+
success();
|
5043
|
+
}
|
5044
|
+
return $(_this).trigger('objects_added');
|
5045
|
+
};
|
5046
|
+
})(this)));
|
4974
5047
|
};
|
4975
5048
|
|
4976
|
-
|
5049
|
+
MongosteenArrayStore.prototype.search = function(searchQuery, callback) {
|
4977
5050
|
this.searchQuery = searchQuery;
|
4978
5051
|
this.pagesCounter = 0;
|
4979
|
-
this.
|
4980
|
-
return this.
|
5052
|
+
this._reset_data();
|
5053
|
+
return this.load(callback);
|
4981
5054
|
};
|
4982
5055
|
|
4983
|
-
|
5056
|
+
MongosteenArrayStore.prototype.reset = function(callback) {
|
4984
5057
|
this.searchQuery = '';
|
4985
5058
|
this.pagesCounter = 0;
|
4986
|
-
this.
|
4987
|
-
return this.
|
5059
|
+
this._reset_data();
|
5060
|
+
return this.load(callback);
|
4988
5061
|
};
|
4989
5062
|
|
4990
|
-
|
4991
|
-
return this._put(id, object, ((function(_this) {
|
4992
|
-
return function(data) {
|
4993
|
-
return _this._updateDataObject(id, data, callbacks.onSuccess);
|
4994
|
-
};
|
4995
|
-
})(this)), callbacks.onError);
|
4996
|
-
};
|
5063
|
+
return MongosteenArrayStore;
|
4997
5064
|
|
4998
|
-
|
4999
|
-
return this._post(object, ((function(_this) {
|
5000
|
-
return function(data) {
|
5001
|
-
if (_this.config.sortBy) {
|
5002
|
-
return _this._addDataObject(data, callbacks.onSuccess);
|
5003
|
-
} else {
|
5004
|
-
return _this._addDataObjectToTheTop(data, callbacks.onSuccess);
|
5005
|
-
}
|
5006
|
-
};
|
5007
|
-
})(this)), callbacks.onError);
|
5008
|
-
};
|
5009
|
-
|
5010
|
-
RailsArrayStore.prototype.remove = function(id) {
|
5011
|
-
return this._delete(id, (function(_this) {
|
5012
|
-
return function(data) {
|
5013
|
-
return _this._removeDataObject(id);
|
5014
|
-
};
|
5015
|
-
})(this));
|
5016
|
-
};
|
5017
|
-
|
5018
|
-
return RailsArrayStore;
|
5019
|
-
|
5020
|
-
})(ArrayStore);
|
5065
|
+
})(RestArrayStore);
|
5021
5066
|
|
5022
5067
|
this._last = function(array) {
|
5023
5068
|
return array[array.length - 1];
|