caboose-cms 0.7.59 → 0.7.60
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/caboose/model/attribute.js +2 -2
- data/app/assets/javascripts/caboose/model/bound_checkbox.js +8 -9
- data/app/assets/javascripts/caboose/model/bound_checkbox_multiple.js +4 -3
- data/app/assets/javascripts/caboose/model/bound_code.js +2 -1
- data/app/assets/javascripts/caboose/model/bound_color.js +2 -2
- data/app/assets/javascripts/caboose/model/bound_control.js +10 -10
- data/app/assets/javascripts/caboose/model/bound_date.js +1 -1
- data/app/assets/javascripts/caboose/model/bound_date_time.js +1 -1
- data/app/assets/javascripts/caboose/model/bound_richtext.js +2 -2
- data/app/assets/javascripts/caboose/model/bound_select.js +5 -3
- data/app/assets/javascripts/caboose/model/bound_text.js +10 -3
- data/app/assets/javascripts/caboose/model/bound_textarea.js +12 -11
- data/app/assets/javascripts/caboose/model/bound_time.js +2 -1
- data/app/assets/javascripts/caboose/model/model.js +11 -5
- data/app/assets/javascripts/caboose/model/model_binder.js +93 -31
- data/lib/caboose/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ad4bf6009e7d52ac46a3190b3c4889d0e89c076
|
4
|
+
data.tar.gz: cf31d15f32e0ead99aff9cff064c3d29bf80bceb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d75db978103fa75b118f2aafe0e110745efd5a98dfeea8c494d51a751b47f76c83ebe2c5ae029437df9bc5f8cb88b3e1201669c02d75ac6cd04b7409840d975c
|
7
|
+
data.tar.gz: 193149455efe7ea7982c3a19f25e03c3e3a8e9c94570a3cb11a6f60c5c4a341ce81209578353d5182aaaf2f2b0ef86125959b3046f59ec3d5e793c98133350d8
|
@@ -38,7 +38,7 @@ Attribute.prototype = {
|
|
38
38
|
s3: false,
|
39
39
|
|
40
40
|
save: function(after) {
|
41
|
-
if (this.before_update) this.before_update();
|
41
|
+
//if (this.before_update) this.before_update();
|
42
42
|
var this2 = this;
|
43
43
|
$.ajax({
|
44
44
|
url: this.update_url,
|
@@ -53,7 +53,7 @@ Attribute.prototype = {
|
|
53
53
|
this2.value_clean = this2.value;
|
54
54
|
}
|
55
55
|
if (after) after(resp);
|
56
|
-
if (this2.after_update) this2.after_update(this2);
|
56
|
+
//if (this2.after_update) this2.after_update(this2);
|
57
57
|
},
|
58
58
|
error: function() {
|
59
59
|
if (after) after(false);
|
@@ -74,18 +74,17 @@ BoundCheckbox = BoundControl.extend({
|
|
74
74
|
},
|
75
75
|
|
76
76
|
save: function() {
|
77
|
-
|
77
|
+
var that = this;
|
78
78
|
this.attribute.value = $('#'+this.el).prop('checked') ? 1 : 0;
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
if (resp.error) this2.error(resp.error);
|
79
|
+
|
80
|
+
this.binder.save(this.attribute, function(resp) {
|
81
|
+
$('#'+that.el+'_check a').removeClass('loading');
|
82
|
+
if (resp.error) that.error(resp.error);
|
84
83
|
else
|
85
84
|
{
|
86
|
-
if (
|
87
|
-
|
88
|
-
|
85
|
+
if (that.binder.success)
|
86
|
+
that.binder.success(that);
|
87
|
+
that.view();
|
89
88
|
}
|
90
89
|
});
|
91
90
|
},
|
@@ -127,6 +127,7 @@ BoundCheckboxMultiple = BoundControl.extend({
|
|
127
127
|
var data = {};
|
128
128
|
data[this.attribute.name] = [value,(checked ? 1 : 0)];
|
129
129
|
|
130
|
+
|
130
131
|
$.ajax({
|
131
132
|
url: this.attribute.update_url,
|
132
133
|
type: 'put',
|
@@ -139,9 +140,9 @@ BoundCheckboxMultiple = BoundControl.extend({
|
|
139
140
|
that.attribute[thing] = resp.attributes[that.attribute.name][thing];
|
140
141
|
that.attribute.value_clean = that.attribute.value;
|
141
142
|
|
142
|
-
|
143
|
-
if (
|
144
|
-
|
143
|
+
b.active_control = that;
|
144
|
+
if (this2.binder.success)
|
145
|
+
this2.binder.success(that);
|
145
146
|
}
|
146
147
|
else if (resp.error)
|
147
148
|
that.error(resp.error);
|
@@ -88,7 +88,8 @@ BoundCode = BoundControl.extend({
|
|
88
88
|
//this.hide_controls();
|
89
89
|
//this.show_loader();
|
90
90
|
//var this2 = this;
|
91
|
-
//
|
91
|
+
//
|
92
|
+
//this.binder.save(this.attribute, function(resp) {
|
92
93
|
// if (resp.error)
|
93
94
|
// {
|
94
95
|
// this2.hide_loader();
|
@@ -87,9 +87,9 @@ BoundColor = BoundControl.extend({
|
|
87
87
|
return;
|
88
88
|
|
89
89
|
//this.show_loader();
|
90
|
-
var this2 = this;
|
90
|
+
var this2 = this;
|
91
91
|
|
92
|
-
this.
|
92
|
+
this.binder.save(this.attribute, function(resp) {
|
93
93
|
this2.save_attempts = 0;
|
94
94
|
if (resp.error)
|
95
95
|
{
|
@@ -1,17 +1,17 @@
|
|
1
1
|
|
2
2
|
BoundControl = Class.extend({
|
3
3
|
|
4
|
-
el: false,
|
5
|
-
model: false,
|
6
|
-
attribute: false,
|
7
|
-
binder: false,
|
8
|
-
|
9
|
-
init:
|
10
|
-
view:
|
11
|
-
edit:
|
12
|
-
save:
|
4
|
+
el: false, // The DOM element to which the object is bound
|
5
|
+
model: false, // The model to which the control is bound
|
6
|
+
attribute: false, // The attribute of the model
|
7
|
+
binder: false, // The model binder
|
8
|
+
|
9
|
+
init: function(params) {}, // Constructor
|
10
|
+
view: function() {}, // Sets the control in a view state
|
11
|
+
edit: function() {}, // Sets the control in an edit state
|
12
|
+
save: function() {}, // Sends the value in the control to the model to be saved
|
13
13
|
cancel: function() {}, // Cancels the edit
|
14
|
-
error:
|
14
|
+
error: function(str) {}, // Shows an error
|
15
15
|
|
16
16
|
show_loader: function() {
|
17
17
|
var w = $('#'+this.el).outerWidth();
|
@@ -73,8 +73,8 @@ BoundRichText = BoundControl.extend({
|
|
73
73
|
if (this.attribute.value == this.attribute.value_clean)
|
74
74
|
return;
|
75
75
|
|
76
|
-
var this2 = this;
|
77
|
-
this.
|
76
|
+
var this2 = this;
|
77
|
+
this.binder.save(this.attribute, function(resp) {
|
78
78
|
if (resp.error)
|
79
79
|
{
|
80
80
|
alert(resp.error);
|
@@ -9,9 +9,11 @@ BoundSelect = BoundControl.extend({
|
|
9
9
|
message: false,
|
10
10
|
placeholder: false,
|
11
11
|
|
12
|
-
init: function(params) {
|
12
|
+
init: function(params) {
|
13
|
+
//console.log('control.model.id = ' + this.model.id);
|
13
14
|
for (var thing in params)
|
14
15
|
this[thing] = params[thing];
|
16
|
+
//console.log('control.model.id = ' + this.model.id);
|
15
17
|
|
16
18
|
this.el = this.el ? this.el : this.model.name.toLowerCase() + '_' + this.model.id + '_' + this.attribute.name;
|
17
19
|
this.message = this.el + '_message';
|
@@ -92,7 +94,7 @@ BoundSelect = BoundControl.extend({
|
|
92
94
|
if (typeof this2.attribute.quick_add_url == 'string')
|
93
95
|
caboose_modal_url(this2.attribute.quick_add_url);
|
94
96
|
else
|
95
|
-
caboose_modal_url(this2.attribute.quick_add_url(this2.model));
|
97
|
+
caboose_modal_url(this2.attribute.quick_add_url(this2.model()));
|
96
98
|
}
|
97
99
|
else
|
98
100
|
{
|
@@ -181,7 +183,7 @@ BoundSelect = BoundControl.extend({
|
|
181
183
|
this.attribute.text = '-- Empty --';
|
182
184
|
|
183
185
|
var this2 = this;
|
184
|
-
this.
|
186
|
+
this.binder.save(this.attribute, function(resp) {
|
185
187
|
$(this2.attribute.options).each(function(i,opt) {
|
186
188
|
if (opt.value == this2.attribute.value)
|
187
189
|
this2.attribute.text = opt.text;
|
@@ -64,10 +64,10 @@ BoundText = BoundControl.extend({
|
|
64
64
|
if (this.attribute.value == this.attribute.value_clean)
|
65
65
|
return;
|
66
66
|
|
67
|
-
this.show_loader();
|
68
|
-
var this2 = this;
|
67
|
+
this.show_loader();
|
68
|
+
var this2 = this;
|
69
69
|
|
70
|
-
this.
|
70
|
+
this.binder.save(this.attribute, function(resp) {
|
71
71
|
this2.save_attempts = 0;
|
72
72
|
if (resp.error)
|
73
73
|
{
|
@@ -111,6 +111,13 @@ BoundText = BoundControl.extend({
|
|
111
111
|
$('#'+this.el+'_message').slideDown();
|
112
112
|
var this2 = this;
|
113
113
|
setTimeout(function() { $('#'+this2.el+'_message').slideUp(function() { $(this).empty(); }); }, 3000);
|
114
|
+
},
|
115
|
+
|
116
|
+
set_value: function(v) {
|
117
|
+
var that = this;
|
118
|
+
$('#'+this.el).val(v);
|
119
|
+
this.attribute.value = v;
|
120
|
+
this.attribute.value_clean = v;
|
114
121
|
}
|
115
122
|
|
116
123
|
});
|
@@ -77,28 +77,29 @@ BoundTextarea = BoundControl.extend({
|
|
77
77
|
},
|
78
78
|
|
79
79
|
save: function() {
|
80
|
-
|
80
|
+
var that = this;
|
81
|
+
|
81
82
|
this.attribute.value = $('#'+this.el).val();
|
82
83
|
if (this.attribute.value == this.attribute.value_clean)
|
83
84
|
return;
|
84
|
-
|
85
|
+
|
85
86
|
this.hide_controls();
|
86
87
|
this.show_loader();
|
87
|
-
|
88
|
-
this.
|
88
|
+
|
89
|
+
this.binder.save(this.attribute, function(resp) {
|
89
90
|
if (resp.error)
|
90
91
|
{
|
91
|
-
|
92
|
-
|
92
|
+
that.hide_loader();
|
93
|
+
that.error(resp.error);
|
93
94
|
}
|
94
95
|
else
|
95
96
|
{
|
96
|
-
|
97
|
-
$('#'+
|
98
|
-
$('#'+
|
97
|
+
that.show_check(500);
|
98
|
+
$('#'+that.el).val(that.attribute.value);
|
99
|
+
$('#'+that.el).removeClass('mb_dirty');
|
99
100
|
|
100
|
-
if (
|
101
|
-
|
101
|
+
if (that.binder.success)
|
102
|
+
that.binder.success(that);
|
102
103
|
}
|
103
104
|
});
|
104
105
|
},
|
@@ -144,7 +144,8 @@ BoundTime = BoundControl.extend({
|
|
144
144
|
save: function() {
|
145
145
|
this.attribute.value = $('#'+this.el).val();
|
146
146
|
var this2 = this;
|
147
|
-
|
147
|
+
|
148
|
+
this.binder.save(this.attribute, function(resp) {
|
148
149
|
$(this2.attribute.options).each(function(i,opt) {
|
149
150
|
if (opt.value == this2.attribute.value)
|
150
151
|
this2.attribute.text = opt.text;
|
@@ -20,11 +20,12 @@ Model.prototype = {
|
|
20
20
|
options_url: false,
|
21
21
|
options: false,
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
attrib.
|
27
|
-
|
23
|
+
// Moved to model binder
|
24
|
+
//save: function(attrib, after) {
|
25
|
+
// if (!attrib.update_url)
|
26
|
+
// attrib.update_url = this.update_url;
|
27
|
+
// attrib.save(after);
|
28
|
+
//},
|
28
29
|
|
29
30
|
populate_options: function(after, i) {
|
30
31
|
if (i == null || i == undefined)
|
@@ -33,5 +34,10 @@ Model.prototype = {
|
|
33
34
|
after();
|
34
35
|
var this2 = this;
|
35
36
|
this.attributes[i].populate_options(function() { this2.populate_options(after, i+1); });
|
37
|
+
},
|
38
|
+
|
39
|
+
name_and_id: function() {
|
40
|
+
return this.model_name.toLowerCase() + '_' + this.model_id;
|
36
41
|
}
|
42
|
+
|
37
43
|
};
|
@@ -2,11 +2,22 @@
|
|
2
2
|
var all_model_binders = [];
|
3
3
|
var ModelBinder = function(params) {
|
4
4
|
this.init(params);
|
5
|
-
|
5
|
+
ModelBinder.add_to_all_model_binders(this);
|
6
6
|
};
|
7
7
|
|
8
|
-
ModelBinder.
|
9
|
-
|
8
|
+
ModelBinder.add_to_all_model_binders = function(mb) {
|
9
|
+
var exists = false;
|
10
|
+
for (var i=0; i<all_model_binders.length; i++) {
|
11
|
+
var m = all_model_binders[i].model;
|
12
|
+
if (m.name == mb.model.name && parseInt(m.id) == parseInt(mb.model.id))
|
13
|
+
{
|
14
|
+
all_model_binders[i] = mb;
|
15
|
+
exists = true;
|
16
|
+
break;
|
17
|
+
}
|
18
|
+
}
|
19
|
+
if (!exists)
|
20
|
+
all_model_binders[all_model_binders.length] = mb;
|
10
21
|
};
|
11
22
|
|
12
23
|
ModelBinder.remove_from_all_model_binders = function(model_name, id) {
|
@@ -18,6 +29,10 @@ ModelBinder.remove_from_all_model_binders = function(model_name, id) {
|
|
18
29
|
all_model_binders = arr;
|
19
30
|
};
|
20
31
|
|
32
|
+
ModelBinder.tinymce_init = function() {
|
33
|
+
alert('ModelBinder.tinymce_init');
|
34
|
+
};
|
35
|
+
|
21
36
|
ModelBinder.tinymce_control = function(id) {
|
22
37
|
var control = false;
|
23
38
|
$.each(all_model_binders, function(i, mb) {
|
@@ -34,27 +49,47 @@ ModelBinder.tinymce_current_control = function() {
|
|
34
49
|
return ModelBinder.tinymce_control(id);
|
35
50
|
};
|
36
51
|
|
37
|
-
ModelBinder.find_control = function(model_name, model_id, attribute_name) {
|
38
|
-
var
|
39
|
-
|
52
|
+
ModelBinder.find_control = function(model_name, model_id, attribute_name) {
|
53
|
+
for (var i=0; i<all_model_binders.length; i++) {
|
54
|
+
var mb = all_model_binders[i];
|
40
55
|
if (mb.model.name == model_name && mb.model.id == model_id) {
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
56
|
+
for (var j=0; j<mb.controls.length; j++) {
|
57
|
+
var c = mb.controls[j];
|
58
|
+
if (c.attribute.name == attribute_name) {
|
59
|
+
return c;
|
60
|
+
}
|
61
|
+
}
|
62
|
+
}
|
63
|
+
}
|
64
|
+
return false;
|
48
65
|
};
|
49
66
|
|
50
|
-
ModelBinder.
|
51
|
-
|
52
|
-
|
53
|
-
{
|
54
|
-
|
55
|
-
|
56
|
-
}
|
57
|
-
|
67
|
+
//ModelBinder.print_all_model_binders = function() {
|
68
|
+
// console.log("-----------------------------------------------------------------");
|
69
|
+
// console.log("All model binders");
|
70
|
+
// for (var i=0; i<all_model_binders.length; i++) {
|
71
|
+
// var mb = all_model_binders[i];
|
72
|
+
// console.log(mb.model.name + ' | ' + mb.model.id);
|
73
|
+
// }
|
74
|
+
// console.log("-----------------------------------------------------------------");
|
75
|
+
//};
|
76
|
+
|
77
|
+
//ModelBinder.print_all_controls = function() {
|
78
|
+
//
|
79
|
+
// count = 0;
|
80
|
+
// for (var i=0; i<all_model_binders.length; i++) { count += all_model_binders[i].controls.length; }
|
81
|
+
//
|
82
|
+
// console.log("-----------------------------------------------------------------");
|
83
|
+
// console.log("All controls (" + count + ")");
|
84
|
+
// for (var i=0; i<all_model_binders.length; i++) {
|
85
|
+
// var mb = all_model_binders[i];
|
86
|
+
// for (var j=0; j<mb.controls.length; j++) {
|
87
|
+
// var c = mb.controls[j];
|
88
|
+
// console.log(mb.model.name + ' | ' + mb.model.id + ' | ' + c.attribute.name); //c.model.name + ' | ' + c.model.id + ' | ' + c.attribute.name + ' | ' + c.attribute.options_url);
|
89
|
+
// }
|
90
|
+
// }
|
91
|
+
// console.log("-----------------------------------------------------------------");
|
92
|
+
//};
|
58
93
|
|
59
94
|
//==============================================================================
|
60
95
|
|
@@ -90,14 +125,16 @@ ModelBinder.wait_for_options = function(url, after) {
|
|
90
125
|
|
91
126
|
ModelBinder.prototype = {
|
92
127
|
model: false,
|
93
|
-
controls:
|
128
|
+
controls: false,
|
94
129
|
on_load: false,
|
95
130
|
success: false,
|
96
131
|
authenticity_token: false,
|
97
|
-
options:
|
132
|
+
options: false,
|
98
133
|
|
99
134
|
init: function(params) {
|
100
|
-
var that = this;
|
135
|
+
var that = this;
|
136
|
+
that.controls = [];
|
137
|
+
that.options = {};
|
101
138
|
that.model = new Model({
|
102
139
|
name: params['name'],
|
103
140
|
id: params['id'],
|
@@ -111,17 +148,19 @@ ModelBinder.prototype = {
|
|
111
148
|
|
112
149
|
$.each(params['attributes'], function(i, attrib) {
|
113
150
|
that.model.attributes[that.model.attributes.length] = new Attribute(attrib);
|
114
|
-
});
|
151
|
+
});
|
115
152
|
$.each(that.model.attributes, function(i, attrib) {
|
116
153
|
var opts = {
|
117
|
-
model: that.model,
|
118
154
|
attribute: attrib,
|
155
|
+
model: that.model,
|
119
156
|
binder: that
|
120
157
|
};
|
158
|
+
//console.log(that.model.name + ' | ' + that.model.id + ' | ' + attrib.name);
|
121
159
|
var control = false;
|
122
160
|
|
123
161
|
if (attrib.type == 'text') control = new BoundText(opts);
|
124
162
|
else if (attrib.type == 'color') control = new BoundColor(opts);
|
163
|
+
else if (attrib.type == 'date') control = new BoundDate(opts);
|
125
164
|
else if (attrib.type == 'datetime') control = new BoundDateTime(opts);
|
126
165
|
else if (attrib.type == 'date-time') control = new BoundDateTime(opts);
|
127
166
|
else if (attrib.type == 'date_time') control = new BoundDateTime(opts);
|
@@ -137,13 +176,15 @@ ModelBinder.prototype = {
|
|
137
176
|
{
|
138
177
|
control_class = "";
|
139
178
|
$.each(attrib.type.split('-'), function(j, word) { control_class += word.charAt(0).toUpperCase() + word.toLowerCase().slice(1); });
|
140
|
-
control = eval("new Bound" + control_class + "(opts)");
|
141
|
-
|
142
|
-
|
143
|
-
|
179
|
+
control = eval("new Bound" + control_class + "(opts)");
|
180
|
+
//console.log("ModelBinder Error: unsupported attribute type \"" + attrib.type + "\"");
|
181
|
+
}
|
182
|
+
if (control)
|
183
|
+
that.controls.push(control);
|
184
|
+
});
|
144
185
|
|
145
186
|
if (that.on_load)
|
146
|
-
that.on_load();
|
187
|
+
that.on_load();
|
147
188
|
},
|
148
189
|
|
149
190
|
reinit: function(control_id)
|
@@ -174,5 +215,26 @@ ModelBinder.prototype = {
|
|
174
215
|
$(this.controls).each(function(i, control) {
|
175
216
|
control.cancel();
|
176
217
|
});
|
218
|
+
},
|
219
|
+
|
220
|
+
save: function(attrib, after) {
|
221
|
+
if (!attrib.update_url)
|
222
|
+
attrib.update_url = this.model.update_url;
|
223
|
+
if (attrib.before_update) attrib.before_update(this);
|
224
|
+
attrib.save(after);
|
225
|
+
if (attrib.after_update) attrib.after_update(this);
|
226
|
+
},
|
227
|
+
|
228
|
+
repopulate_options_for_control: function(attribute_name)
|
229
|
+
{
|
230
|
+
for (var i=0; i<this.controls.length; i++)
|
231
|
+
{
|
232
|
+
var c = this.controls[i];
|
233
|
+
if (c.attribute.name == attribute_name)
|
234
|
+
{
|
235
|
+
c.attribute.options = false;
|
236
|
+
c.init({});
|
237
|
+
}
|
238
|
+
}
|
177
239
|
}
|
178
240
|
};
|
data/lib/caboose/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: caboose-cms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.60
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- William Barry
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|