caboose-cms 0.8.44 → 0.8.45
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/admin_page_edit_content.js +14 -10
- data/app/assets/javascripts/caboose/block_modal_controllers/#Untitled-1# +3 -0
- data/app/assets/javascripts/caboose/block_modal_controllers/block_modal_controller.js +255 -0
- data/app/assets/javascripts/caboose/{modal_controllers/modal_button_controller.js → block_modal_controllers/button_modal_controller.js} +1 -1
- data/app/assets/javascripts/caboose/block_modal_controllers/default_block_modal_controller.js +237 -0
- data/app/assets/javascripts/caboose/{modal_controllers/modal_media_controller.js → block_modal_controllers/media_modal_controller.js} +36 -37
- data/app/assets/javascripts/caboose/block_modal_controllers/richtext_modal_controller.js +94 -0
- data/app/assets/javascripts/caboose/modal_controller.js +129 -0
- data/app/assets/javascripts/caboose/model/bound_richtext.js +5 -0
- data/app/assets/javascripts/caboose/tinymce_init.js +15 -0
- data/app/assets/stylesheets/caboose/admin_block_edit_image.css.scss +0 -9
- data/app/assets/stylesheets/caboose/icomoon_fonts.css +10 -2
- data/app/assets/stylesheets/caboose/modal_inline.css +12 -0
- data/app/controllers/caboose/blocks_controller.rb +29 -34
- data/app/views/caboose/blocks/tinymce.js.erb +1 -0
- data/app/views/caboose/pages/admin_edit_content.html.erb +7 -4
- data/lib/caboose/version.rb +1 -1
- metadata +11 -6
- data/app/assets/javascripts/caboose/modal_controllers/modal_block_controller.js +0 -325
- data/app/assets/javascripts/caboose/modal_controllers/modal_controller.js +0 -217
@@ -0,0 +1 @@
|
|
1
|
+
<%= raw caboose_tinymce %>
|
@@ -4,6 +4,7 @@
|
|
4
4
|
<%= stylesheet_link_tag 'caboose/admin_block_edit_image' %>
|
5
5
|
<%= stylesheet_link_tag "caboose/modal_inline" %>
|
6
6
|
<style type='text/css'>
|
7
|
+
|
7
8
|
#tiny_header {
|
8
9
|
display: block;
|
9
10
|
color: #fff;
|
@@ -60,11 +61,13 @@
|
|
60
61
|
<%= javascript_include_tag "caboose/clipboard" %>
|
61
62
|
<%= javascript_include_tag 'caboose/admin_page_edit_content' %>
|
62
63
|
<%= javascript_include_tag "caboose/class" %>
|
63
|
-
<%= javascript_include_tag "caboose/
|
64
|
-
<%= javascript_include_tag "caboose/
|
65
|
-
<%= javascript_include_tag "caboose/
|
64
|
+
<%= javascript_include_tag "caboose/modal_controller" %>
|
65
|
+
<%= javascript_include_tag "caboose/block_modal_controllers/default_block_modal_controller" %>
|
66
|
+
<%= javascript_include_tag "caboose/block_modal_controllers/block_modal_controller" %>
|
67
|
+
<%= javascript_include_tag "caboose/block_modal_controllers/media_modal_controller" %>
|
68
|
+
<%= javascript_include_tag "caboose/block_modal_controllers/richtext_modal_controller" %>
|
66
69
|
<% @page.block.modal_js_block_names.each do |s| %>
|
67
|
-
<%= javascript_include_tag "caboose/
|
70
|
+
<%= javascript_include_tag "caboose/block_modal_controllers/#{s}_modal_controller" %>
|
68
71
|
<% end %>
|
69
72
|
<script type='text/javascript'>
|
70
73
|
|
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.8.
|
4
|
+
version: 0.8.45
|
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-08-
|
11
|
+
date: 2016-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|
@@ -524,6 +524,12 @@ files:
|
|
524
524
|
- app/assets/javascripts/caboose/application.js
|
525
525
|
- app/assets/javascripts/caboose/authorize.net.js
|
526
526
|
- app/assets/javascripts/caboose/block_media_controller.js
|
527
|
+
- app/assets/javascripts/caboose/block_modal_controllers/#Untitled-1#
|
528
|
+
- app/assets/javascripts/caboose/block_modal_controllers/block_modal_controller.js
|
529
|
+
- app/assets/javascripts/caboose/block_modal_controllers/button_modal_controller.js
|
530
|
+
- app/assets/javascripts/caboose/block_modal_controllers/default_block_modal_controller.js
|
531
|
+
- app/assets/javascripts/caboose/block_modal_controllers/media_modal_controller.js
|
532
|
+
- app/assets/javascripts/caboose/block_modal_controllers/richtext_modal_controller.js
|
527
533
|
- app/assets/javascripts/caboose/card.js
|
528
534
|
- app/assets/javascripts/caboose/cart.js
|
529
535
|
- app/assets/javascripts/caboose/cart_old.js
|
@@ -563,10 +569,7 @@ files:
|
|
563
569
|
- app/assets/javascripts/caboose/main.js
|
564
570
|
- app/assets/javascripts/caboose/media_browser.js
|
565
571
|
- app/assets/javascripts/caboose/modal.js
|
566
|
-
- app/assets/javascripts/caboose/
|
567
|
-
- app/assets/javascripts/caboose/modal_controllers/modal_button_controller.js
|
568
|
-
- app/assets/javascripts/caboose/modal_controllers/modal_controller.js
|
569
|
-
- app/assets/javascripts/caboose/modal_controllers/modal_media_controller.js
|
572
|
+
- app/assets/javascripts/caboose/modal_controller.js
|
570
573
|
- app/assets/javascripts/caboose/modal_integration.js
|
571
574
|
- app/assets/javascripts/caboose/model.form.page.js
|
572
575
|
- app/assets/javascripts/caboose/model.form.user.js
|
@@ -606,6 +609,7 @@ files:
|
|
606
609
|
- app/assets/javascripts/caboose/spectrum.js
|
607
610
|
- app/assets/javascripts/caboose/station.js
|
608
611
|
- app/assets/javascripts/caboose/testing.js
|
612
|
+
- app/assets/javascripts/caboose/tinymce_init.js
|
609
613
|
- app/assets/javascripts/caboose/united_states.js
|
610
614
|
- app/assets/javascripts/caboose/variant_children_controller.js
|
611
615
|
- app/assets/javascripts/chartjs/Chart.min.js
|
@@ -1005,6 +1009,7 @@ files:
|
|
1005
1009
|
- app/views/caboose/blocks/admin_edit_richtextold.html.erb
|
1006
1010
|
- app/views/caboose/blocks/admin_new.html.erb
|
1007
1011
|
- app/views/caboose/blocks/admin_render_second_level.json.erb
|
1012
|
+
- app/views/caboose/blocks/tinymce.js.erb
|
1008
1013
|
- app/views/caboose/calendars/admin_edit.html.erb
|
1009
1014
|
- app/views/caboose/calendars/admin_index.html.erb
|
1010
1015
|
- app/views/caboose/cart/index.html.erb
|
@@ -1,325 +0,0 @@
|
|
1
|
-
|
2
|
-
var ModalBlockController = ModalController.extend({
|
3
|
-
|
4
|
-
block_types: false,
|
5
|
-
|
6
|
-
after_refresh: function()
|
7
|
-
{
|
8
|
-
var that = this;
|
9
|
-
that.update_on_close = false;
|
10
|
-
$.each(that.block.children, function(i, b) {
|
11
|
-
if (b.block_type.field_type == 'image' || b.block_type.field_type == 'file')
|
12
|
-
that.update_on_close = true;
|
13
|
-
});
|
14
|
-
that.print();
|
15
|
-
},
|
16
|
-
|
17
|
-
/*****************************************************************************
|
18
|
-
Printing
|
19
|
-
*****************************************************************************/
|
20
|
-
|
21
|
-
print: function()
|
22
|
-
{
|
23
|
-
var that = this;
|
24
|
-
if (!that.block)
|
25
|
-
{
|
26
|
-
var div = $('<div/>')
|
27
|
-
.append($('<div/>').attr('id', 'modal_crumbtrail' ))
|
28
|
-
.append($('<div/>').attr('id', 'modal_content' ))
|
29
|
-
.append($('<div/>').attr('id', 'modal_message' ))
|
30
|
-
.append($('<div/>').attr('id', 'modal_controls' ));
|
31
|
-
that.modal(div, 800);
|
32
|
-
that.refresh(function() { that.after_refresh() });
|
33
|
-
return;
|
34
|
-
}
|
35
|
-
|
36
|
-
var div = $('<div/>').attr('id', 'modal_content');
|
37
|
-
if (that.block.block_type.field_type != 'block')
|
38
|
-
div.append($('<p/>').append($('<div/>').attr('id', 'block_' + that.block.id + '_value')));
|
39
|
-
else
|
40
|
-
{
|
41
|
-
if (that.block.children.length > 0)
|
42
|
-
{
|
43
|
-
$.each(that.block.children, function(i, b) {
|
44
|
-
if (b.block_type.field_type != 'block' && b.block_type.field_type != 'richtext' && b.block_type.field_type != 'image' && b.block_type.field_type != 'file')
|
45
|
-
div.append($('<div/>').css('margin-bottom', '10px').append($('<div/>').attr('id', 'block_' + b.id + '_value')));
|
46
|
-
else
|
47
|
-
{
|
48
|
-
div.append($('<div/>').css('margin-bottom', '10px').append($('<div/>').attr('id', 'block_' + b.id)));
|
49
|
-
}
|
50
|
-
});
|
51
|
-
}
|
52
|
-
else
|
53
|
-
{
|
54
|
-
div.append($('<p/>').append("This block doesn't have any content yet."));
|
55
|
-
}
|
56
|
-
if (that.block.block_type.allow_child_blocks)
|
57
|
-
{
|
58
|
-
div.append($('<p/>').css('clear', 'both').append($('<a/>').attr('href', '#').html("Add a child block!").click(function(e) {
|
59
|
-
e.preventDefault();
|
60
|
-
that.add_block();
|
61
|
-
})));
|
62
|
-
}
|
63
|
-
}
|
64
|
-
$('#modal_content').replaceWith(div);
|
65
|
-
$('#modal_crumbtrail').empty().append(that.crumbtrail());
|
66
|
-
$('#modal_controls').empty().append(that.controls());
|
67
|
-
|
68
|
-
that.render_blocks();
|
69
|
-
that.set_editable();
|
70
|
-
that.autosize();
|
71
|
-
},
|
72
|
-
|
73
|
-
controls: function()
|
74
|
-
{
|
75
|
-
var that = this;
|
76
|
-
var p = $('<p/>').css('clear', 'both')
|
77
|
-
.append($('<input/>').attr('type', 'button').addClass('btn').val('Close').click(function() { that.close(); if (that.update_on_close) { that.parent_controller.render_blocks(); } })).append(' ');
|
78
|
-
if (!that.block.name)
|
79
|
-
p.append($('<input/>').attr('type', 'button').addClass('btn').val('Delete Block').click(function() { that.delete_block(); })).append(' ');
|
80
|
-
p.append($('<input/>').attr('type', 'button').addClass('btn').val('Move Up' ).click(function() { that.move_up(); })).append(' ');
|
81
|
-
p.append($('<input/>').attr('type', 'button').addClass('btn').val('Move Down' ).click(function() { that.move_down(); })).append(' ');
|
82
|
-
p.append($('<input/>').attr('type', 'button').addClass('btn').val('Advanced' ).attr('id', 'btn_advanced').click(function() { that.print_advanced(); }));
|
83
|
-
return p;
|
84
|
-
},
|
85
|
-
|
86
|
-
print_advanced: function()
|
87
|
-
{
|
88
|
-
var that = this;
|
89
|
-
var b = that.block;
|
90
|
-
|
91
|
-
$('#modal_content').empty()
|
92
|
-
.append($('<p/>').append($('<div/>').attr('id', 'block_' + b.id + '_block_type_id' )))
|
93
|
-
.append($('<p/>').append($('<div/>').attr('id', 'block_' + b.id + '_parent_id' )))
|
94
|
-
.append($('<p/>').append($('<div/>').attr('id', 'block_' + b.id + '_constrain' )))
|
95
|
-
.append($('<p/>').append($('<div/>').attr('id', 'block_' + b.id + '_full_width' )))
|
96
|
-
$('#modal_controls').empty()
|
97
|
-
.append($('<p/>')
|
98
|
-
.append($('<input/>').attr('type', 'button').addClass('btn').val('Close').click(function() { that.close(); if (that.update_on_close) { that.parent_controller.render_blocks(); } })).append(' ')
|
99
|
-
.append($('<input/>').attr('type', 'button').addClass('btn').val('Back' ).click(function() { that.print(); }))
|
100
|
-
);
|
101
|
-
|
102
|
-
var m = new ModelBinder({
|
103
|
-
name: 'Block',
|
104
|
-
id: b.id,
|
105
|
-
update_url: that.block_url(b),
|
106
|
-
authenticity_token: that.authenticity_token,
|
107
|
-
attributes: [
|
108
|
-
{ name: 'block_type_id' , nice_name: 'Block type' , type: 'select' , value: b.block_type_id , text: b.block_type.name , width: 400, fixed_placeholder: true, options_url: '/admin/block-types/options' , after_update: function() { that.parent_controller.render_blocks(); that.block.block_type_id = this.value; }, after_cancel: function() { that.parent_controller.render_blocks(); }, on_load: function() { that.modal.autosize(); }},
|
109
|
-
{ name: 'parent_id' , nice_name: 'Parent ID' , type: 'select' , value: b.parent_id , text: b.parent ? b.parent.title : '' , width: 400, fixed_placeholder: true, options_url: '/admin/pages/' + that.page_id + '/block-options' , after_update: function() { that.parent_controller.render_blocks(); that.block.parent_id = this.value; }, after_cancel: function() { that.parent_controller.render_blocks(); }, on_load: function() { that.modal.autosize(); }},
|
110
|
-
{ name: 'constrain' , nice_name: 'Constrain' , type: 'checkbox' , value: b.constrain ? 1 : 0 , width: 400, fixed_placeholder: true, after_update: function() { that.parent_controller.render_blocks(); that.block.constrain = this.value; }, after_cancel: function() { that.parent_controller.render_blocks(); }, on_load: function() { that.modal.autosize(); }},
|
111
|
-
{ name: 'full_width' , nice_name: 'Full Width' , type: 'checkbox' , value: b.full_width ? 1 : 0 , width: 400, fixed_placeholder: true, after_update: function() { that.parent_controller.render_blocks(); that.block.full_width = this.value; }, after_cancel: function() { that.parent_controller.render_blocks(); }, on_load: function() { that.modal.autosize(); }}
|
112
|
-
]
|
113
|
-
});
|
114
|
-
that.autosize();
|
115
|
-
},
|
116
|
-
|
117
|
-
crumbtrail: function()
|
118
|
-
{
|
119
|
-
var that = this;
|
120
|
-
var crumbs = $('<h2/>').css('margin-top', '0').css('padding-top', '0');
|
121
|
-
$.each(that.block.crumbtrail, function(i, h) {
|
122
|
-
if (i > 0) crumbs.append(' > ');
|
123
|
-
crumbs.append($('<a/>').attr('href', '#').html(h['text']).data('block_id', h['block_id']).click(function(e) {
|
124
|
-
e.preventDefault();
|
125
|
-
that.parent_controller.edit_block(parseInt($(this).data('block_id')));
|
126
|
-
}));
|
127
|
-
});
|
128
|
-
return crumbs;
|
129
|
-
},
|
130
|
-
|
131
|
-
/*****************************************************************************
|
132
|
-
Block Rendering
|
133
|
-
*****************************************************************************/
|
134
|
-
|
135
|
-
render_blocks: function()
|
136
|
-
{
|
137
|
-
var that = this;
|
138
|
-
if (that.block.block_type.field_type != 'block' && that.block.children.length == 0)
|
139
|
-
return;
|
140
|
-
|
141
|
-
$.each(that.block.children, function(i, b) {
|
142
|
-
var ft = b.block_type.field_type;
|
143
|
-
if (ft == 'block' || ft == 'richtext' || ft == 'image' || ft == 'file')
|
144
|
-
{
|
145
|
-
if (!b.rendered_value)
|
146
|
-
{
|
147
|
-
$.ajax({
|
148
|
-
block_id: b.id, // Used in the success function
|
149
|
-
url: that.block_url(b) + '/render',
|
150
|
-
type: 'get',
|
151
|
-
success: function(html) {
|
152
|
-
$('#the_modal #block_' + this.block_id).replaceWith(html);
|
153
|
-
|
154
|
-
var b2 = that.block_with_id(this.block_id);
|
155
|
-
b2.rendered_value = html;
|
156
|
-
that.set_clickable(b2);
|
157
|
-
that.autosize();
|
158
|
-
},
|
159
|
-
});
|
160
|
-
}
|
161
|
-
else
|
162
|
-
$('#the_modal #block_' + b.id).replaceWith(b.rendered_value);
|
163
|
-
}
|
164
|
-
});
|
165
|
-
},
|
166
|
-
|
167
|
-
/****************************************************************************/
|
168
|
-
|
169
|
-
set_clickable: function(b)
|
170
|
-
{
|
171
|
-
var that = this;
|
172
|
-
|
173
|
-
if (!b)
|
174
|
-
{
|
175
|
-
$.each(that.block.children, function(i,b) {
|
176
|
-
that.set_clickable(b);
|
177
|
-
});
|
178
|
-
}
|
179
|
-
|
180
|
-
$('#the_modal #block_' + b.id).attr('onclick','').unbind('click');
|
181
|
-
$('#the_modal #block_' + b.id).click(function(e) {
|
182
|
-
e.stopPropagation();
|
183
|
-
that.parent_controller.edit_block(b.id);
|
184
|
-
});
|
185
|
-
//if (b.allow_child_blocks == true)
|
186
|
-
//{
|
187
|
-
// $('#new_block_' + b.id).replaceWith($('<input/>')
|
188
|
-
// .attr('type', 'button')
|
189
|
-
// .val('New Block')
|
190
|
-
// .click(function(e) { e.stopPropagation(); that.new_block(b.id);
|
191
|
-
// })
|
192
|
-
// );
|
193
|
-
//}
|
194
|
-
var show_mouseover = true;
|
195
|
-
if (b.children && b.children.length > 0)
|
196
|
-
{
|
197
|
-
$.each(b.children, function(i, b2) {
|
198
|
-
if (b2.block_type_id = 34)
|
199
|
-
show_mouseover = false;
|
200
|
-
that.set_clickable(b2);
|
201
|
-
});
|
202
|
-
}
|
203
|
-
if (show_mouseover)
|
204
|
-
{
|
205
|
-
$('#the_modal #block_' + b.id).mouseover(function(el) { $('#the_modal #block_' + b.id).addClass( 'block_over'); });
|
206
|
-
$('#the_modal #block_' + b.id).mouseout(function(el) { $('#the_modal #block_' + b.id).removeClass('block_over'); });
|
207
|
-
}
|
208
|
-
},
|
209
|
-
|
210
|
-
/****************************************************************************/
|
211
|
-
|
212
|
-
set_editable: function()
|
213
|
-
{
|
214
|
-
var that = this;
|
215
|
-
that.set_block_value_editable(that.block);
|
216
|
-
$.each(that.block.children, function(i, b) {
|
217
|
-
that.set_block_value_editable(b);
|
218
|
-
});
|
219
|
-
},
|
220
|
-
|
221
|
-
set_block_value_editable: function(b)
|
222
|
-
{
|
223
|
-
var that = this;
|
224
|
-
var bt = b.block_type;
|
225
|
-
if (bt.field_type == 'block' || bt.field_type == 'richtext')
|
226
|
-
return;
|
227
|
-
var h = {
|
228
|
-
name: 'value',
|
229
|
-
type: bt.field_type,
|
230
|
-
nice_name: bt.description ? bt.description : bt.name,
|
231
|
-
width: bt.width ? bt.width : 780,
|
232
|
-
after_update: function() { that.parent_controller.render_blocks(); },
|
233
|
-
after_cancel: function() { that.parent_controller.render_blocks(); }
|
234
|
-
};
|
235
|
-
h['value'] = b.value
|
236
|
-
if (bt.field_type == 'checkbox') h['value'] = b.value ? 'true' : 'false';
|
237
|
-
//if (bt.field_type == 'image') h['value'] = b.image.tiny_url;
|
238
|
-
//if (bt.field_type == 'file') h['value'] = b.file.url;
|
239
|
-
if (bt.field_type == 'select') h['text'] = b.value;
|
240
|
-
if (bt.height) h['height'] = bt.height;
|
241
|
-
if (bt.fixed_placeholder) h['fixed_placeholder'] = bt.fixed_placeholder;
|
242
|
-
if (bt.options || bt.options_function) h['options_url'] = '/admin/block-types/' + bt.id + '/options';
|
243
|
-
else if (bt.options_url) h['options_url'] = bt.options_url;
|
244
|
-
if (bt.field_type == 'file') h['update_url'] = that.block_url(b) + '/file';
|
245
|
-
if (bt.field_type == 'image')
|
246
|
-
{
|
247
|
-
h['update_url'] = that.block_url(b) + '/image'
|
248
|
-
h['image_refresh_delay'] = 100;
|
249
|
-
}
|
250
|
-
|
251
|
-
m = new ModelBinder({
|
252
|
-
name: 'Block',
|
253
|
-
id: b.id,
|
254
|
-
update_url: that.block_url(b),
|
255
|
-
authenticity_token: that.authenticity_token,
|
256
|
-
attributes: [h]
|
257
|
-
});
|
258
|
-
},
|
259
|
-
|
260
|
-
/****************************************************************************/
|
261
|
-
|
262
|
-
delete_block: function(confirm)
|
263
|
-
{
|
264
|
-
var that = this;
|
265
|
-
if (!confirm)
|
266
|
-
{
|
267
|
-
var p = $('<p/>').addClass('note warning')
|
268
|
-
.append("Are you sure you want to delete the block? This can't be undone.<br />")
|
269
|
-
.append($('<input/>').attr('type','button').val('Yes').click(function() { that.delete_block(true); })).append(' ')
|
270
|
-
.append($('<input/>').attr('type','button').val('No').click(function() { $('#modal_message').empty(); that.autosize(); }));
|
271
|
-
that.autosize(p);
|
272
|
-
return;
|
273
|
-
}
|
274
|
-
that.autosize("<p class='loading'>Deleting block...</p>");
|
275
|
-
$.ajax({
|
276
|
-
url: that.block_url(that.block),
|
277
|
-
type: 'delete',
|
278
|
-
success: function(resp) {
|
279
|
-
if (resp.error) that.autosize("<p class='note error'>" + resp.error + "</p>");
|
280
|
-
if (resp.redirect)
|
281
|
-
{
|
282
|
-
that.close();
|
283
|
-
that.parent_controller.render_blocks();
|
284
|
-
}
|
285
|
-
}
|
286
|
-
});
|
287
|
-
},
|
288
|
-
|
289
|
-
move_up: function()
|
290
|
-
{
|
291
|
-
var that = this;
|
292
|
-
that.autosize("<p class='loading'>Moving up...</p>");
|
293
|
-
$.ajax({
|
294
|
-
url: that.block_url(that.block) + '/move-up',
|
295
|
-
type: 'put',
|
296
|
-
success: function(resp) {
|
297
|
-
if (resp.error) that.autosize("<p class='note error'>" + resp.error + "</p>");
|
298
|
-
if (resp.success)
|
299
|
-
{
|
300
|
-
that.autosize("<p class='note success'>" + resp.success + "</p>");
|
301
|
-
that.parent_controller.render_blocks();
|
302
|
-
}
|
303
|
-
}
|
304
|
-
});
|
305
|
-
},
|
306
|
-
|
307
|
-
move_down: function()
|
308
|
-
{
|
309
|
-
var that = this;
|
310
|
-
that.autosize("<p class='loading'>Moving down...</p>");
|
311
|
-
$.ajax({
|
312
|
-
url: that.block_url(that.block) + '/move-down',
|
313
|
-
type: 'put',
|
314
|
-
success: function(resp) {
|
315
|
-
if (resp.error) that.autosize("<p class='note error'>" + resp.error + "</p>");
|
316
|
-
if (resp.success)
|
317
|
-
{
|
318
|
-
that.autosize("<p class='note success'>" + resp.success + "</p>");
|
319
|
-
that.parent_controller.render_blocks();
|
320
|
-
}
|
321
|
-
}
|
322
|
-
});
|
323
|
-
}
|
324
|
-
|
325
|
-
});
|
@@ -1,217 +0,0 @@
|
|
1
|
-
|
2
|
-
var ModalController = Class.extend({
|
3
|
-
|
4
|
-
page_id: false,
|
5
|
-
block_id: false,
|
6
|
-
block: false,
|
7
|
-
modal_element: false,
|
8
|
-
authenticity_token: false,
|
9
|
-
parent_controller: false,
|
10
|
-
new_block_on_init: false,
|
11
|
-
assets_path: false,
|
12
|
-
|
13
|
-
init: function(params)
|
14
|
-
{
|
15
|
-
var that = this;
|
16
|
-
for (var i in params)
|
17
|
-
that[i] = params[i];
|
18
|
-
that.include_assets();
|
19
|
-
if (that.new_block_on_init == true)
|
20
|
-
that.add_block();
|
21
|
-
else
|
22
|
-
that.print();
|
23
|
-
},
|
24
|
-
|
25
|
-
refresh: function(callback)
|
26
|
-
{
|
27
|
-
var that = this
|
28
|
-
$.ajax({
|
29
|
-
url: '/admin/pages/' + that.page_id + '/blocks/' + that.block_id + '/tree',
|
30
|
-
type: 'get',
|
31
|
-
success: function(arr) {
|
32
|
-
that.block = arr[0];
|
33
|
-
if (callback) callback();
|
34
|
-
}
|
35
|
-
});
|
36
|
-
},
|
37
|
-
|
38
|
-
modal: function(el, width, height, callback)
|
39
|
-
{
|
40
|
-
var that = this;
|
41
|
-
if (!width) width = 400;
|
42
|
-
if (!height) height = $(el).outerHeight(true);
|
43
|
-
that.modal_element = el;
|
44
|
-
el.attr('id', 'the_modal').addClass('modal').css('width', '' + width + 'px');
|
45
|
-
$.colorbox({
|
46
|
-
html: el,
|
47
|
-
initialWidth: width,
|
48
|
-
//initialHeight: height,
|
49
|
-
innerWidth: width,
|
50
|
-
//innerHeight: height,
|
51
|
-
scrolling: false,
|
52
|
-
closeButton: false,
|
53
|
-
opacity: 0.50,
|
54
|
-
onComplete: function() {
|
55
|
-
var arr = ['TopLeft','TopCenter','TopRight','BottomLeft','BottomCenter','BottomRight','MiddleLeft','MiddleRight'];
|
56
|
-
for (var i in arr) $('#cbox' + arr[i]).css('background-color', '#fff !important');
|
57
|
-
$("#cboxClose").hide();
|
58
|
-
if (callback) callback();
|
59
|
-
}
|
60
|
-
});
|
61
|
-
},
|
62
|
-
|
63
|
-
last_size: 0,
|
64
|
-
autosize: function(msg, msg_container, flag)
|
65
|
-
{
|
66
|
-
var that = this;
|
67
|
-
if (!flag)
|
68
|
-
that.last_size = 0;
|
69
|
-
if (!that.modal_element) return;
|
70
|
-
if (msg) $('#' + (msg_container ? msg_container : 'modal_message')).html(msg);
|
71
|
-
var h = $(that.modal_element).outerHeight(true) + 20;
|
72
|
-
if (h > 0 && h > that.last_size)
|
73
|
-
$.colorbox.resize({ innerHeight: '' + h + 'px' });
|
74
|
-
that.last_size = h;
|
75
|
-
|
76
|
-
if (!flag || flag < 2)
|
77
|
-
setTimeout(function() { that.autosize(false, false, flag ? flag + 1 : 1); }, 200);
|
78
|
-
},
|
79
|
-
|
80
|
-
close: function()
|
81
|
-
{
|
82
|
-
$.colorbox.close();
|
83
|
-
},
|
84
|
-
|
85
|
-
block_with_id: function(block_id, b)
|
86
|
-
{
|
87
|
-
var that = this;
|
88
|
-
if (!b) b = that.block;
|
89
|
-
if (b.id == block_id) return b;
|
90
|
-
|
91
|
-
var the_block = false;
|
92
|
-
$.each(b.children, function(i, b2) {
|
93
|
-
the_block = that.block_with_id(block_id, b2);
|
94
|
-
if (the_block)
|
95
|
-
return false;
|
96
|
-
});
|
97
|
-
return the_block;
|
98
|
-
},
|
99
|
-
|
100
|
-
base_url: function(b)
|
101
|
-
{
|
102
|
-
var that = this;
|
103
|
-
if (!b) b = that.block;
|
104
|
-
return '/admin/' + (b.page_id ? 'pages/' + b.page_id : 'posts/' + b.post_id) + '/blocks';
|
105
|
-
},
|
106
|
-
|
107
|
-
block_url: function(b)
|
108
|
-
{
|
109
|
-
var that = this;
|
110
|
-
if (!b) b = that.block;
|
111
|
-
return this.base_url(b) + '/' + b.id;
|
112
|
-
},
|
113
|
-
|
114
|
-
add_block: function(block_type_id)
|
115
|
-
{
|
116
|
-
var that = this;
|
117
|
-
|
118
|
-
that.include_assets([
|
119
|
-
'caboose/icomoon_fonts.css',
|
120
|
-
'caboose/admin_new_block.css'
|
121
|
-
]);
|
122
|
-
|
123
|
-
if (!that.block_type_id)
|
124
|
-
{
|
125
|
-
that.new_block_types = false;
|
126
|
-
$.ajax({
|
127
|
-
url: '/admin/block-types/new-options',
|
128
|
-
type: 'get',
|
129
|
-
success: function(resp) { that.new_block_types = resp; },
|
130
|
-
async: false
|
131
|
-
});
|
132
|
-
|
133
|
-
var icons = $('<div/>').addClass('icons');
|
134
|
-
$.each(that.new_block_types, function(i, h) {
|
135
|
-
if (h.block_types && h.block_types.length > 0)
|
136
|
-
{
|
137
|
-
var cat = h.block_type_category;
|
138
|
-
icons.append($('<h2/>').click(function(e) { $('#cat_' + cat.id + '_container').slideToggle(); }).append(cat.name));
|
139
|
-
var cat_container = $('<div/>').attr('id', 'cat_' + cat.id + '_container');
|
140
|
-
$.each(h.block_types, function(j, bt) {
|
141
|
-
cat_container.append($('<a/>').attr('href', '#')
|
142
|
-
.data('block_type_id', bt.id)
|
143
|
-
.click(function(e) { e.preventDefault(); that.add_block($(this).data('block_type_id')); })
|
144
|
-
.append($('<span/>').addClass('icon icon-' + bt.icon))
|
145
|
-
.append($('<span/>').addClass('name').append(bt.description))
|
146
|
-
);
|
147
|
-
});
|
148
|
-
icons.append(cat_container);
|
149
|
-
}
|
150
|
-
});
|
151
|
-
|
152
|
-
var div = $('<div/>').append($('<form/>').attr('id', 'new_block_form')
|
153
|
-
.submit(function(e) { e.preventDefault(); return false; })
|
154
|
-
.append(icons)
|
155
|
-
);
|
156
|
-
that.modal(div, 800);
|
157
|
-
return;
|
158
|
-
}
|
159
|
-
|
160
|
-
that.autosize("<p class='loading'>Adding block...</p>");
|
161
|
-
var h = {
|
162
|
-
authenticity_token: that.authenticity_token,
|
163
|
-
block_type_id: block_type_id
|
164
|
-
};
|
165
|
-
if (that.before_id ) h['before_id'] = that.before_id;
|
166
|
-
if (that.after_id ) h['after_id' ] = that.after_id;
|
167
|
-
|
168
|
-
$.ajax({
|
169
|
-
url: that.block_url(),
|
170
|
-
type: 'post',
|
171
|
-
data: h,
|
172
|
-
success: function(resp) {
|
173
|
-
if (resp.error) that.autosize("<p class='note error'>" + resp.error + "</p>");
|
174
|
-
if (resp.success) that.parent_controller.edit_block(resp.new_id);
|
175
|
-
}
|
176
|
-
});
|
177
|
-
},
|
178
|
-
|
179
|
-
/*****************************************************************************
|
180
|
-
Asset management
|
181
|
-
*****************************************************************************/
|
182
|
-
|
183
|
-
// To be overridden in each controller
|
184
|
-
assets_to_include: function() { return []; },
|
185
|
-
|
186
|
-
// Called at the beginning of init to include modal assets,
|
187
|
-
// and can be called at anytime with more assets
|
188
|
-
include_assets: function(arr)
|
189
|
-
{
|
190
|
-
var that = this;
|
191
|
-
if (!arr) arr = that.assets_to_include();
|
192
|
-
if (!arr) return;
|
193
|
-
|
194
|
-
if (!that.parent_controller.included_assets || that.parent_controller.included_assets == undefined)
|
195
|
-
that.parent_controller.included_assets = [];
|
196
|
-
if (typeof arr == 'string') arr = [arr];
|
197
|
-
$.each(arr, function(i, url) {
|
198
|
-
if (that.parent_controller.included_assets.indexOf(url) > -1) return;
|
199
|
-
if (url.match(/\.js/))
|
200
|
-
{
|
201
|
-
var el = document.createElement('script');
|
202
|
-
el.setAttribute('type', 'text/javascript');
|
203
|
-
el.setAttribute('src', that.assets_path + url);
|
204
|
-
document.getElementsByTagName('head')[0].appendChild(el)
|
205
|
-
}
|
206
|
-
else if (url.match(/\.css/))
|
207
|
-
{
|
208
|
-
var el = document.createElement('link');
|
209
|
-
el.setAttribute('rel', 'stylesheet');
|
210
|
-
el.setAttribute('type', 'text/css');
|
211
|
-
el.setAttribute('href', that.assets_path + url);
|
212
|
-
document.getElementsByTagName('head')[0].appendChild(el)
|
213
|
-
}
|
214
|
-
that.parent_controller.included_assets.push(url);
|
215
|
-
});
|
216
|
-
}
|
217
|
-
});
|