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.
Files changed (21) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/caboose/admin_page_edit_content.js +14 -10
  3. data/app/assets/javascripts/caboose/block_modal_controllers/#Untitled-1# +3 -0
  4. data/app/assets/javascripts/caboose/block_modal_controllers/block_modal_controller.js +255 -0
  5. data/app/assets/javascripts/caboose/{modal_controllers/modal_button_controller.js → block_modal_controllers/button_modal_controller.js} +1 -1
  6. data/app/assets/javascripts/caboose/block_modal_controllers/default_block_modal_controller.js +237 -0
  7. data/app/assets/javascripts/caboose/{modal_controllers/modal_media_controller.js → block_modal_controllers/media_modal_controller.js} +36 -37
  8. data/app/assets/javascripts/caboose/block_modal_controllers/richtext_modal_controller.js +94 -0
  9. data/app/assets/javascripts/caboose/modal_controller.js +129 -0
  10. data/app/assets/javascripts/caboose/model/bound_richtext.js +5 -0
  11. data/app/assets/javascripts/caboose/tinymce_init.js +15 -0
  12. data/app/assets/stylesheets/caboose/admin_block_edit_image.css.scss +0 -9
  13. data/app/assets/stylesheets/caboose/icomoon_fonts.css +10 -2
  14. data/app/assets/stylesheets/caboose/modal_inline.css +12 -0
  15. data/app/controllers/caboose/blocks_controller.rb +29 -34
  16. data/app/views/caboose/blocks/tinymce.js.erb +1 -0
  17. data/app/views/caboose/pages/admin_edit_content.html.erb +7 -4
  18. data/lib/caboose/version.rb +1 -1
  19. metadata +11 -6
  20. data/app/assets/javascripts/caboose/modal_controllers/modal_block_controller.js +0 -325
  21. data/app/assets/javascripts/caboose/modal_controllers/modal_controller.js +0 -217
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c7db5fd2f83983190e31cad9070c3f0e1303a82
4
- data.tar.gz: a7957d2e142835db616a46b9e2131937685a4092
3
+ metadata.gz: 8071f7f65c943a12d34fe0ec4ac2ffe3b9252282
4
+ data.tar.gz: 1c9c68fd1aaf5a12c34d9c2b52f429ce5a158dd9
5
5
  SHA512:
6
- metadata.gz: f8ea193f4e83786726457a54efb7ca49a1ba6f218bc8dd70d6be555e178f9f03f940dc101ce7608e0b429681ed73667b6cba34162d583e639898cedc6e38af27
7
- data.tar.gz: 84b430310d349b61930a8632d9e91b414fd257bb8a6abc234ea886a4af2f695c58715ab8d424dc9879f461f08b61856ebcac82c9260d1240eedd73e647a0e573
6
+ metadata.gz: 0af932f6fb9cf7245057371e5f8ecb931ec43e786690f8845d668a66f4c3a934b0b752803558bebf1a3f740901b7d3ae8e3a7deba998866b7c280f9b3dce5f52
7
+ data.tar.gz: a87a6cd391521e6443385294e6e1a6b2a1411e480acb0dc0c6975053c1d4039d6838287d7b825ac6cabc8dc8bcd1475f905ca024a8e4fab51fe1754b99d49553
@@ -48,10 +48,13 @@ PageContentController.prototype = {
48
48
  var that = this;
49
49
  var b = that.block_with_id(block_id);
50
50
  var modal_controller = '';
51
- if (b.use_js_for_modal == true) { $.each(b.name.split('_'), function(j, word) { modal_controller += word.charAt(0).toUpperCase() + word.toLowerCase().slice(1); }); }
52
- else if (b.field_type == 'image') { modal_controller = 'Media'; }
53
- else { modal_controller = 'Block'; }
54
- that.modal = eval("new Modal" + modal_controller + "Controller({ " +
51
+ if (b.block_type.use_js_for_modal == true) {
52
+ $.each(b.name.split('_'), function(j, word) { modal_controller += word.charAt(0).toUpperCase() + word.toLowerCase().slice(1); });
53
+ }
54
+ else if (b.block_type.field_type == 'image') { modal_controller = 'Media'; }
55
+ else if (b.block_type.field_type == 'richtext') { modal_controller = 'Richtext'; }
56
+ else { modal_controller = 'Block'; }
57
+ that.modal = eval("new " + modal_controller + "ModalController({ " +
55
58
  " page_id: " + that.page_id + ", " +
56
59
  " block_id: " + block_id + ", " +
57
60
  " authenticity_token: '" + that.authenticity_token + "', " +
@@ -63,9 +66,10 @@ PageContentController.prototype = {
63
66
 
64
67
  new_block: function(parent_id, before_block_id, after_block_id)
65
68
  {
66
- var that = this;
69
+ var that = this;
70
+ console.log(parent_id);
67
71
  //caboose_modal_url('/admin/pages/' + this.page_id + '/blocks/' + parent_id + '/new');
68
- that.modal = new ModalController({
72
+ that.modal = new BlockModalController({
69
73
  page_id: that.page_id,
70
74
  block_id: parent_id,
71
75
  authenticity_token: that.authenticity_token,
@@ -228,7 +232,7 @@ PageContentController.prototype = {
228
232
  .click(function(e) {
229
233
  e.preventDefault(); e.stopPropagation();
230
234
  //caboose_modal_url('/admin/pages/' + that.page_id + '/blocks/' + parent_id + '/new?before_id=' + b.id);
231
- that.new_block({ before_id: b.id });
235
+ that.new_block(parent_id, b.id);
232
236
  })
233
237
  )
234
238
  .mouseover(function(e) { $(this).removeClass('new_block_link').addClass('new_block_link_over'); e.stopPropagation(); })
@@ -245,7 +249,7 @@ PageContentController.prototype = {
245
249
  .click(function(e) {
246
250
  e.preventDefault(); e.stopPropagation();
247
251
  //caboose_modal_url('/admin/pages/' + that.page_id + '/blocks/' + parent_id + '/new?after_id=' + b.id);
248
- that.new_block({ after_id: b.id });
252
+ that.new_block(parent_id, null, b.id);
249
253
  })
250
254
  )
251
255
  .mouseover(function(e) { $(this).removeClass('new_block_link').addClass('new_block_link_over'); e.stopPropagation(); })
@@ -266,9 +270,9 @@ PageContentController.prototype = {
266
270
  {
267
271
  var count = b.children.length;
268
272
  $.each(b.children, function(i, b2) {
269
- if (b2.field_type == 'block')
273
+ if (b2.block_type.field_type == 'block')
270
274
  show_mouseover = false;
271
- that.set_clickable_helper(b2, b.id, b.allow_child_blocks, i == (count-1));
275
+ that.set_clickable_helper(b2, b.id, b.block_type.allow_child_blocks, i == (count-1));
272
276
  });
273
277
  }
274
278
  //if (b.allow_child_blocks)
@@ -0,0 +1,3 @@
1
+ <textarea id="block_119227_value" class="tinymce" placeholder="empty" style="width: 800px; height: 300px;"></textarea>
2
+
3
+ removeEditorFromList
@@ -0,0 +1,255 @@
1
+
2
+ var BlockModalController = DefaultBlockModalController.extend({
3
+
4
+ block_types: false,
5
+
6
+ print_content: function()
7
+ {
8
+ var that = this;
9
+ var div = $('<div/>').attr('id', 'modal_content');
10
+ if (that.block.block_type.field_type != 'block')
11
+ div.append($('<p/>').append($('<div/>').attr('id', 'block_' + that.block.id + '_value')));
12
+ else
13
+ {
14
+ if (that.block.children.length > 0)
15
+ {
16
+ var complex_field_types = ['block', 'richtext', 'image', 'file'];
17
+ $.each(that.block.children, function(i, b) {
18
+ var div_id = 'block_' + b.id + (complex_field_types.indexOf(b.block_type.field_type) == -1 ? '_value' : '');
19
+ div.append($('<div/>').css('margin-bottom', '10px').append($('<div/>').attr('id', div_id)));
20
+ });
21
+ }
22
+ else
23
+ {
24
+ div.append($('<p/>').append("This block doesn't have any content yet."));
25
+ }
26
+ if (that.block.block_type.allow_child_blocks)
27
+ {
28
+ div.append($('<p/>').css('clear', 'both').append($('<a/>').attr('href', '#').html("Add a child block!").click(function(e) {
29
+ e.preventDefault();
30
+ that.add_block();
31
+ })));
32
+ }
33
+ }
34
+ $('#modal_content').replaceWith(div);
35
+ that.render_blocks();
36
+ that.set_editable();
37
+ that.autosize();
38
+ },
39
+
40
+ /*****************************************************************************
41
+ Block Rendering
42
+ *****************************************************************************/
43
+
44
+ render_blocks: function()
45
+ {
46
+ var that = this;
47
+ if (that.block.block_type.field_type != 'block' && that.block.children.length == 0)
48
+ return;
49
+
50
+ $.each(that.block.children, function(i, b) {
51
+ var ft = b.block_type.field_type;
52
+ if (ft == 'block' || ft == 'richtext' || ft == 'image' || ft == 'file')
53
+ {
54
+ if (!b.rendered_value)
55
+ {
56
+ $.ajax({
57
+ block_id: b.id, // Used in the success function
58
+ url: that.block_url(b) + '/render',
59
+ type: 'get',
60
+ success: function(html) {
61
+ $('#the_modal #block_' + this.block_id).replaceWith(html);
62
+
63
+ var b2 = that.block_with_id(this.block_id);
64
+ b2.rendered_value = html;
65
+ that.set_clickable(b2);
66
+ that.autosize();
67
+ },
68
+ });
69
+ }
70
+ else
71
+ $('#the_modal #block_' + b.id).replaceWith(b.rendered_value);
72
+ }
73
+ });
74
+ },
75
+
76
+ /****************************************************************************/
77
+
78
+ set_clickable: function(b)
79
+ {
80
+ var that = this;
81
+
82
+ if (!b)
83
+ {
84
+ $.each(that.block.children, function(i,b) {
85
+ that.set_clickable(b);
86
+ });
87
+ }
88
+
89
+ $('#the_modal #block_' + b.id).attr('onclick','').unbind('click');
90
+ $('#the_modal #block_' + b.id).click(function(e) {
91
+ e.stopPropagation();
92
+ that.parent_controller.edit_block(b.id);
93
+ });
94
+ //if (b.allow_child_blocks == true)
95
+ //{
96
+ // $('#new_block_' + b.id).replaceWith($('<input/>')
97
+ // .attr('type', 'button')
98
+ // .val('New Block')
99
+ // .click(function(e) { e.stopPropagation(); that.new_block(b.id);
100
+ // })
101
+ // );
102
+ //}
103
+ var show_mouseover = true;
104
+ if (b.children && b.children.length > 0)
105
+ {
106
+ $.each(b.children, function(i, b2) {
107
+ if (b2.block_type.id = 34)
108
+ show_mouseover = false;
109
+ that.set_clickable(b2);
110
+ });
111
+ }
112
+ if (show_mouseover)
113
+ {
114
+ $('#the_modal #block_' + b.id).mouseover(function(el) { $('#the_modal #block_' + b.id).addClass( 'block_over'); });
115
+ $('#the_modal #block_' + b.id).mouseout(function(el) { $('#the_modal #block_' + b.id).removeClass('block_over'); });
116
+ }
117
+ },
118
+
119
+ /****************************************************************************/
120
+
121
+ set_editable: function()
122
+ {
123
+ var that = this;
124
+ that.set_block_value_editable(that.block);
125
+ $.each(that.block.children, function(i, b) {
126
+ that.set_block_value_editable(b);
127
+ });
128
+ },
129
+
130
+ set_block_value_editable: function(b)
131
+ {
132
+ var that = this;
133
+ var bt = b.block_type;
134
+ if (bt.field_type == 'block' || bt.field_type == 'richtext')
135
+ return;
136
+ var h = {
137
+ name: 'value',
138
+ type: bt.field_type,
139
+ nice_name: bt.description ? bt.description : bt.name,
140
+ width: bt.width ? bt.width : 780,
141
+ after_update: function() { that.parent_controller.render_blocks(); },
142
+ after_cancel: function() { that.parent_controller.render_blocks(); }
143
+ };
144
+ h['value'] = b.value
145
+ if (bt.field_type == 'checkbox') h['value'] = b.value ? 'true' : 'false';
146
+ //if (bt.field_type == 'image') h['value'] = b.image.tiny_url;
147
+ //if (bt.field_type == 'file') h['value'] = b.file.url;
148
+ if (bt.field_type == 'select') h['text'] = b.value;
149
+ if (bt.height) h['height'] = bt.height;
150
+ if (bt.fixed_placeholder) h['fixed_placeholder'] = bt.fixed_placeholder;
151
+ if (bt.options || bt.options_function) h['options_url'] = '/admin/block-types/' + bt.id + '/options';
152
+ else if (bt.options_url) h['options_url'] = bt.options_url;
153
+ if (bt.field_type == 'file') h['update_url'] = that.block_url(b) + '/file';
154
+ if (bt.field_type == 'image')
155
+ {
156
+ h['update_url'] = that.block_url(b) + '/image'
157
+ h['image_refresh_delay'] = 100;
158
+ }
159
+
160
+ m = new ModelBinder({
161
+ name: 'Block',
162
+ id: b.id,
163
+ update_url: that.block_url(b),
164
+ authenticity_token: that.authenticity_token,
165
+ attributes: [h]
166
+ });
167
+ },
168
+
169
+ /****************************************************************************/
170
+
171
+ add_block: function(block_type_id)
172
+ {
173
+ var that = this;
174
+
175
+ console.log(that);
176
+
177
+ that.include_inline_css(
178
+ "@font-face {\n" +
179
+ " font-family: 'icomoon';\n" +
180
+ " src: url('" + that.assets_path + "icomoon.eot?-tne7s4');\n" +
181
+ " src: url('" + that.assets_path + "icomoon.eot?#iefix-tne7s4') format('embedded-opentype'),\n" +
182
+ " url('" + that.assets_path + "icomoon.woff?-tne7s4') format('woff'),\n" +
183
+ " url('" + that.assets_path + "icomoon.ttf?-tne7s4') format('truetype'),\n" +
184
+ " url('" + that.assets_path + "icomoon.svg?-tne7s4#icomoon') format('svg');\n" +
185
+ " font-weight: normal;\n" +
186
+ " font-style: normal;\n" +
187
+ "}\n"
188
+ );
189
+ that.include_assets([
190
+ 'caboose/icomoon_fonts.css',
191
+ 'caboose/admin_new_block.css'
192
+ ]);
193
+
194
+ if (!block_type_id)
195
+ {
196
+ that.new_block_types = false;
197
+ $.ajax({
198
+ url: '/admin/block-types/new-options',
199
+ type: 'get',
200
+ success: function(resp) { that.new_block_types = resp; },
201
+ async: false
202
+ });
203
+
204
+ var icons = $('<div/>').addClass('icons');
205
+ $.each(that.new_block_types, function(i, h) {
206
+ if (h.block_types && h.block_types.length > 0)
207
+ {
208
+ var cat = h.block_type_category;
209
+ icons.append($('<h2/>').click(function(e) { $('#cat_' + cat.id + '_container').slideToggle(); }).append(cat.name));
210
+ var cat_container = $('<div/>').attr('id', 'cat_' + cat.id + '_container');
211
+ $.each(h.block_types, function(j, bt) {
212
+ cat_container.append($('<a/>').attr('href', '#')
213
+ .data('block_type_id', bt.id)
214
+ .click(function(e) { e.preventDefault(); that.add_block($(this).data('block_type_id')); })
215
+ .append($('<span/>').addClass('icon icon-' + bt.icon))
216
+ .append($('<span/>').addClass('name').append(bt.description))
217
+ );
218
+ });
219
+ icons.append(cat_container);
220
+ }
221
+ });
222
+ var div = $('<div/>').append($('<form/>').attr('id', 'new_block_form')
223
+ .submit(function(e) { e.preventDefault(); return false; })
224
+ .append(icons)
225
+ );
226
+ that.modal(div, 780);
227
+ return;
228
+ }
229
+
230
+ that.autosize("<p class='loading'>Adding block...</p>");
231
+ var h = {
232
+ authenticity_token: that.authenticity_token,
233
+ block_type_id: block_type_id
234
+ };
235
+ if (that.before_id ) h['before_id'] = that.before_id;
236
+ if (that.after_id ) h['after_id' ] = that.after_id;
237
+
238
+ $.ajax({
239
+ url: '/admin/' + (that.page_id ? 'pages/' + that.page_id : 'posts/' + that.post_id) + '/blocks/' + that.block_id,
240
+ type: 'post',
241
+ data: h,
242
+ success: function(resp) {
243
+ if (resp.error) that.autosize("<p class='note error'>" + resp.error + "</p>");
244
+ if (resp.success)
245
+ {
246
+ that.parent_controller.refresh_blocks(function() {
247
+ that.parent_controller.edit_block(resp.new_id);
248
+ that.parent_controller.render_blocks();
249
+ });
250
+ }
251
+ }
252
+ });
253
+ },
254
+
255
+ });
@@ -1,5 +1,5 @@
1
1
 
2
- var ModalButtonController = ModalController.extend({
2
+ var ButtonModalController = DefaultBlockModalController.extend({
3
3
 
4
4
  print: function()
5
5
  {
@@ -0,0 +1,237 @@
1
+
2
+ var DefaultBlockModalController = ModalController.extend({
3
+
4
+ page_id: false,
5
+ block_id: false,
6
+ block: false,
7
+ block_types: false,
8
+ authenticity_token: false,
9
+ new_block_on_init: false,
10
+ assets_path: false,
11
+
12
+ init: function(params)
13
+ {
14
+ var that = this;
15
+ for (var i in params)
16
+ that[i] = params[i];
17
+ that.include_assets();
18
+ if (that.new_block_on_init == true)
19
+ that.add_block();
20
+ else
21
+ that.print();
22
+ },
23
+
24
+ refresh: function(callback)
25
+ {
26
+ var that = this;
27
+ that.refresh_block(function() {
28
+ if (callback) callback();
29
+ });
30
+ },
31
+
32
+ refresh_block: function(callback)
33
+ {
34
+ var that = this
35
+ $.ajax({
36
+ url: '/admin/pages/' + that.page_id + '/blocks/' + that.block_id + '/tree',
37
+ type: 'get',
38
+ success: function(arr) {
39
+ that.block = arr[0];
40
+ if (callback) callback();
41
+ }
42
+ });
43
+ },
44
+
45
+ /*****************************************************************************
46
+ Printing
47
+ *****************************************************************************/
48
+
49
+ print: function()
50
+ {
51
+ var that = this;
52
+ if (!that.block)
53
+ {
54
+ var div = $('<div/>')
55
+ .append($('<div/>').attr('id', 'modal_crumbtrail' ))
56
+ .append($('<div/>').attr('id', 'modal_content' ))
57
+ .append($('<div/>').attr('id', 'modal_message' ))
58
+ .append($('<div/>').attr('id', 'modal_controls' ));
59
+ that.modal(div, 800);
60
+ that.refresh(function() { that.print(); });
61
+ return;
62
+ }
63
+
64
+ that.print_content();
65
+ that.print_crumbtrail();
66
+ that.print_controls();
67
+ that.autosize();
68
+ },
69
+
70
+ print_content: function() {},
71
+
72
+ print_controls: function()
73
+ {
74
+ var that = this;
75
+ var p = $('<p/>').css('clear', 'both')
76
+ .append($('<input/>').attr('type', 'button').addClass('btn').val('Close').click(function() { that.close(); that.parent_controller.render_blocks(); })).append(' ');
77
+ if (!that.block.name)
78
+ {
79
+ p.append($('<input/>').attr('type', 'button').addClass('btn').val('Delete Block').click(function() { that.delete_block(); })).append(' ');
80
+ }
81
+ p.append($('<input/>').attr('type', 'button').addClass('btn').val('Move Up' ).click(function() { that.move_up(); })).append(' ');
82
+ p.append($('<input/>').attr('type', 'button').addClass('btn').val('Move Down' ).click(function() { that.move_down(); })).append(' ');
83
+ p.append($('<input/>').attr('type', 'button').addClass('btn').val('Advanced' ).attr('id', 'btn_advanced').click(function() { that.print_advanced(); }));
84
+ $('#modal_controls').empty().append(p);
85
+ },
86
+
87
+ before_crumbtrail_click: false,
88
+ print_crumbtrail: function()
89
+ {
90
+ var that = this;
91
+ var crumbs = $('<h2/>').css('margin-top', '0').css('padding-top', '0');
92
+ $.each(that.block.crumbtrail, function(i, h) {
93
+ if (i > 0) crumbs.append(' > ');
94
+ crumbs.append($('<a/>').attr('href', '#').html(h['text']).data('block_id', h['block_id']).click(function(e) {
95
+ e.preventDefault();
96
+ if (that.before_crumbtrail_click) that.before_crumbtrail_click();
97
+ that.parent_controller.edit_block(parseInt($(this).data('block_id')));
98
+ }));
99
+ });
100
+ $('#modal_crumbtrail').empty().append(crumbs);
101
+ },
102
+
103
+ before_print_advanced: false,
104
+ print_advanced: function()
105
+ {
106
+ var that = this;
107
+ if (that.before_print_advanced) that.before_print_advanced();
108
+
109
+ var b = that.block;
110
+ $('#modal_content').empty()
111
+ .append($('<p/>').append($('<div/>').attr('id', 'block_' + b.id + '_block_type_id' )))
112
+ .append($('<p/>').append($('<div/>').attr('id', 'block_' + b.id + '_parent_id' )))
113
+ .append($('<p/>').append($('<div/>').attr('id', 'block_' + b.id + '_constrain' )))
114
+ .append($('<p/>').append($('<div/>').attr('id', 'block_' + b.id + '_full_width' )))
115
+ $('#modal_controls').empty()
116
+ .append($('<p/>')
117
+ .append($('<input/>').attr('type', 'button').addClass('btn').val('Close').click(function() {
118
+ that.close();
119
+ that.parent_controller.render_blocks();
120
+ })).append(' ')
121
+ .append($('<input/>').attr('type', 'button').addClass('btn').val('Back' ).click(function() {
122
+ that.print_content();
123
+ that.print_controls();
124
+ }))
125
+ );
126
+
127
+ var m = new ModelBinder({
128
+ name: 'Block',
129
+ id: b.id,
130
+ update_url: that.block_url(b),
131
+ authenticity_token: that.authenticity_token,
132
+ attributes: [
133
+ { 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(); }},
134
+ { 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(); }},
135
+ { 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(); }},
136
+ { 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(); }}
137
+ ]
138
+ });
139
+ that.autosize();
140
+ },
141
+
142
+ /****************************************************************************/
143
+
144
+ delete_block: function(confirm)
145
+ {
146
+ var that = this;
147
+ if (!confirm)
148
+ {
149
+ var p = $('<p/>').addClass('note warning')
150
+ .append("Are you sure you want to delete the block? This can't be undone.<br />")
151
+ .append($('<input/>').attr('type','button').val('Yes').click(function() { that.delete_block(true); })).append(' ')
152
+ .append($('<input/>').attr('type','button').val('No').click(function() { $('#modal_message').empty(); that.autosize();
153
+ }));
154
+ that.autosize(p);
155
+ return;
156
+ }
157
+ that.autosize("<p class='loading'>Deleting block...</p>");
158
+ $.ajax({
159
+ url: that.block_url(that.block),
160
+ type: 'delete',
161
+ success: function(resp) {
162
+ if (resp.error) that.autosize("<p class='note error'>" + resp.error + "</p>");
163
+ if (resp.redirect)
164
+ {
165
+ that.close();
166
+ that.parent_controller.render_blocks();
167
+ }
168
+ }
169
+ });
170
+ },
171
+
172
+ move_up: function()
173
+ {
174
+ var that = this;
175
+ that.autosize("<p class='loading'>Moving up...</p>");
176
+ $.ajax({
177
+ url: that.block_url(that.block) + '/move-up',
178
+ type: 'put',
179
+ success: function(resp) {
180
+ if (resp.error) that.autosize("<p class='note error'>" + resp.error + "</p>");
181
+ if (resp.success)
182
+ {
183
+ that.autosize("<p class='note success'>" + resp.success + "</p>");
184
+ that.parent_controller.render_blocks();
185
+ }
186
+ }
187
+ });
188
+ },
189
+
190
+ move_down: function()
191
+ {
192
+ var that = this;
193
+ that.autosize("<p class='loading'>Moving down...</p>");
194
+ $.ajax({
195
+ url: that.block_url(that.block) + '/move-down',
196
+ type: 'put',
197
+ success: function(resp) {
198
+ if (resp.error) that.autosize("<p class='note error'>" + resp.error + "</p>");
199
+ if (resp.success)
200
+ {
201
+ that.autosize("<p class='note success'>" + resp.success + "</p>");
202
+ that.parent_controller.render_blocks();
203
+ }
204
+ }
205
+ });
206
+ },
207
+
208
+ block_with_id: function(block_id, b)
209
+ {
210
+ var that = this;
211
+ if (!b) b = that.block;
212
+ if (b.id == block_id) return b;
213
+
214
+ var the_block = false;
215
+ $.each(b.children, function(i, b2) {
216
+ the_block = that.block_with_id(block_id, b2);
217
+ if (the_block)
218
+ return false;
219
+ });
220
+ return the_block;
221
+ },
222
+
223
+ base_url: function(b)
224
+ {
225
+ var that = this;
226
+ if (!b) b = that.block;
227
+ return '/admin/' + (b.page_id ? 'pages/' + b.page_id : 'posts/' + b.post_id) + '/blocks';
228
+ },
229
+
230
+ block_url: function(b)
231
+ {
232
+ var that = this;
233
+ if (!b) b = that.block;
234
+ return this.base_url(b) + '/' + b.id;
235
+ },
236
+
237
+ });