lalala 4.0.0.dev.416 → 4.1.0.dev.299

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/Gemfile +1 -3
  4. data/Haraway.md +14 -0
  5. data/app/assets/javascripts/lalala/base.js +8 -0
  6. data/app/assets/javascripts/lalala/initializers/chosen.module.js +3 -0
  7. data/app/assets/javascripts/lalala/initializers/haraway.module.js +8 -0
  8. data/app/assets/javascripts/lalala/lib/overlay.js +335 -0
  9. data/app/assets/javascripts/lalala/modules/collapsible_pages_tree.module.js +26 -33
  10. data/app/assets/javascripts/lalala/modules/editor.module.js +37 -23
  11. data/app/assets/javascripts/lalala/modules/file-uploader-metadata.module.js +248 -0
  12. data/app/assets/javascripts/lalala/modules/file-uploader.module.js +376 -0
  13. data/app/assets/javascripts/lalala/modules/init.module.js +1 -5
  14. data/app/assets/javascripts/lalala/modules/media_selector.module.js +250 -0
  15. data/app/assets/javascripts/lalala/modules/overlay.module.js +33 -0
  16. data/app/assets/stylesheets/lalala/_base.css.scss +5 -2
  17. data/app/assets/stylesheets/lalala/components/_buttons.css.scss +11 -3
  18. data/app/assets/stylesheets/lalala/components/_forms.css.scss +14 -64
  19. data/app/assets/stylesheets/lalala/lib/_overlay.css.scss +66 -0
  20. data/app/assets/stylesheets/lalala/modules/_dashboard.css.scss +10 -51
  21. data/app/assets/stylesheets/lalala/modules/_editor-cheatsheet.css.scss +1 -17
  22. data/app/assets/stylesheets/lalala/modules/_file-uploader-metadata.css.scss +118 -0
  23. data/app/assets/stylesheets/lalala/modules/_file-uploader.css.scss +289 -0
  24. data/app/assets/stylesheets/lalala/modules/_media-selector.css.scss +113 -0
  25. data/app/assets/stylesheets/lalala/modules/_title-bar.css.scss +0 -17
  26. data/app/controllers/lalala/public/errors_controller.rb +7 -0
  27. data/app/models/lalala/page.rb +0 -1
  28. data/app/views/lalala/markdown/cheatsheet.html.erb +0 -2
  29. data/config/routes.rb +12 -1
  30. data/lalala-assets.gemspec +3 -3
  31. data/lalala-development.gemspec +1 -1
  32. data/lalala-test.gemspec +1 -1
  33. data/lalala.gemspec +4 -5
  34. data/lib/formtastic/form_builder_ext.rb +10 -0
  35. data/lib/formtastic/inputs/haraway_input.rb +151 -0
  36. data/lib/generators/lalala/assets/templates/bower.json.erb +1 -1
  37. data/lib/generators/lalala/install/install_generator.rb +0 -23
  38. data/lib/lalala/admin/pages.rb +1 -26
  39. data/lib/lalala/engine.rb +0 -7
  40. data/lib/lalala/ext_action_dispatch.rb +0 -1
  41. data/lib/lalala/ext_active_record/i18n_translations_writer.rb +0 -1
  42. data/lib/lalala/ext_active_record.rb +0 -1
  43. data/lib/lalala/ext_i18n/input_helper.rb +0 -1
  44. data/lib/lalala/ext_i18n/negotiation_adapter.rb +0 -4
  45. data/lib/lalala/ext_i18n/test_negotiation_adapter.rb +0 -4
  46. data/lib/lalala/ext_rack/i18n_negotiator.rb +7 -9
  47. data/lib/lalala/markdown/handlers/asset.rb +24 -0
  48. data/lib/lalala/markdown/handlers/youtube.rb +9 -13
  49. data/lib/lalala/markdown/html_renderer.rb +2 -2
  50. data/lib/lalala/markdown.rb +2 -3
  51. data/lib/lalala/utils/install_template.rb +3 -9
  52. data/lib/lalala/version.rb +2 -2
  53. data/lib/lalala.rb +6 -7
  54. data/script/ci +33 -30
  55. data/test/dummy/app/admin/articles.rb +26 -12
  56. data/test/dummy/app/admin/dashboard.rb +5 -8
  57. data/test/dummy/app/admin/tags.rb +1 -3
  58. data/test/dummy/app/assets/stylesheets/_normalize.css +423 -0
  59. data/test/dummy/app/assets/stylesheets/application.css.scss +2 -0
  60. data/test/dummy/app/assets/stylesheets/base/_base.css.scss +4 -0
  61. data/test/dummy/app/controllers/pages_controller.rb +4 -0
  62. data/test/dummy/app/models/article.rb +10 -4
  63. data/test/dummy/app/pages/application_page.rb +7 -2
  64. data/test/dummy/app/pages/basic_page.rb +5 -6
  65. data/test/dummy/app/pages/home_page.rb +10 -10
  66. data/test/dummy/app/pages/media_page.rb +23 -0
  67. data/test/dummy/app/views/admin/_stats.html.erb +7 -14
  68. data/test/dummy/app/views/layouts/application.html.erb +6 -2
  69. data/test/dummy/app/views/pages/media.html.erb +3 -0
  70. data/test/dummy/config/initializers/haraway.rb +29 -0
  71. data/test/dummy/config/routes.rb +1 -0
  72. data/test/dummy/db/migrate/20130528092721_create_articles.rb +1 -0
  73. data/test/dummy/db/migrate/20130729125648_create_home_page.rb +4 -0
  74. data/test/dummy/db/migrate/20131122144302_enable_haraway.rb +16 -0
  75. data/test/dummy/db/migrate/20140228141749_create_media_page.rb +8 -0
  76. data/test/dummy/db/schema.rb +2 -4
  77. data/test/integration/aricles_test.rb +0 -1
  78. metadata +59 -81
  79. data/app/assets/javascripts/jquery-ui/sortable.js +0 -0
  80. data/app/assets/javascripts/lalala/lib/jquery-ui.js +0 -16617
  81. data/app/assets/javascripts/lalala/modules/grid.module.js +0 -284
  82. data/app/assets/javascripts/lalala/modules/input_group.module.js +0 -36
  83. data/app/assets/stylesheets/lalala/modules/_grid.css.scss +0 -197
  84. data/app/assets/stylesheets/lalala/modules/_index-as-sortable.css.scss +0 -89
  85. data/app/models/lalala/abstract_asset.rb +0 -24
  86. data/app/models/lalala/file_asset.rb +0 -3
  87. data/app/models/lalala/image_asset.rb +0 -3
  88. data/config/initializers/carrierwave.rb +0 -34
  89. data/lib/formtastic/inputs/grid_input.rb +0 -159
  90. data/lib/formtastic/inputs/single_file_input.rb +0 -44
  91. data/lib/generators/lalala/install/templates/application.html.erb +0 -64
  92. data/lib/generators/lalala/install/templates/helpers/application_helper.rb +0 -16
  93. data/lib/generators/lalala/install/templates/helpers/html_helper.rb +0 -60
  94. data/lib/generators/lalala/install/templates/helpers/open_graph_helper.rb.erb +0 -92
  95. data/lib/generators/lalala/install/templates/helpers/pages_helper.rb +0 -15
  96. data/lib/generators/lalala/install/templates/locales/en.yml +0 -6
  97. data/lib/generators/lalala/install/templates/uploaders/file_uploader.rb +0 -2
  98. data/lib/generators/lalala/install/templates/uploaders/image_uploader.rb +0 -11
  99. data/lib/lalala/ext_action_dispatch/multi_file_upload.rb +0 -55
  100. data/lib/lalala/ext_active_record/assets.rb +0 -25
  101. data/lib/lalala/markdown/handlers/soundcloud.rb +0 -36
  102. data/lib/lalala/markdown/handlers/vimeo.rb +0 -40
  103. data/lib/lalala/uploaders/file.rb +0 -50
  104. data/lib/lalala/uploaders/image.rb +0 -13
  105. data/lib/lalala/uploaders.rb +0 -6
  106. data/test/dummy/app/assets/stylesheets/application.css +0 -13
  107. data/test/dummy/app/models/file_asset.rb +0 -2
  108. data/test/dummy/app/models/image_asset.rb +0 -2
  109. data/test/dummy/app/uploaders/file_uploader.rb +0 -2
  110. data/test/dummy/app/uploaders/image_uploader.rb +0 -11
  111. data/test/dummy/db/migrate/20140926152646_add_pre_and_postpend_test_columns_to_articles.rb +0 -6
@@ -0,0 +1,248 @@
1
+ var Overlay = require("lalala/modules/overlay");
2
+
3
+
4
+
5
+ function FileUploaderMetadata($xfile, fileuploader) {
6
+ this.$el = $('<div class="mod-file-uploader-metadata" />');
7
+ this.$xfile = $xfile;
8
+ this.fileuploader = fileuploader;
9
+
10
+ this.render();
11
+ this.bind_events();
12
+ }
13
+
14
+
15
+
16
+ FileUploaderMetadata.prototype.render = function() {
17
+ var tmpl, main_tmpl, sidebar_tmpl, img_tmpl, meta_tmpl;
18
+ var that = this;
19
+
20
+ // main
21
+ main_tmpl = this.main_template;
22
+ main_tmpl = main_tmpl.replace("{{FIELDS}}",
23
+ this.$xfile.find(".attributes").length ?
24
+ this.$xfile.find(".attributes").html() :
25
+ this.get_form_template()
26
+ );
27
+
28
+ // sidebar
29
+ sidebar_tmpl = this.sidebar_template;
30
+
31
+ if (this.$xfile.hasClass("saved-to-db")) {
32
+ img_tmpl = '<div class="image cover" style="background-image: url(' +
33
+ this.$xfile.attr("data-src-original").replace("original", "cover") + ');"></div>';
34
+
35
+ meta_tmpl = this.$xfile.find(".meta").html();
36
+
37
+ } else {
38
+ img_tmpl = '<div class="image"><canvas></canvas></div>';
39
+ meta_tmpl = '';
40
+
41
+ this.$xfile.find("input")
42
+ .filter("[name$=\"extension]\"]:first")
43
+ .each(function() {
44
+ var $t, name;
45
+
46
+ $t = $(this);
47
+ meta_tmpl += '<div class="row"><span class="label">';
48
+ name = $t.attr("name");
49
+ name = name.substring(name.lastIndexOf("[") + 1, name.lastIndexOf("]"));
50
+
51
+ switch (name) {
52
+ case "extension": meta_tmpl += 'filetype';
53
+ }
54
+
55
+ meta_tmpl += '</span><span class="value">' +
56
+ $t.attr("value") +
57
+ '</span></div>';
58
+ });
59
+
60
+ }
61
+
62
+ sidebar_tmpl = sidebar_tmpl.replace("{{IMAGE}}", img_tmpl);
63
+ sidebar_tmpl = sidebar_tmpl.replace("{{META}}", meta_tmpl);
64
+
65
+ // global template
66
+ tmpl = this.template;
67
+ tmpl = tmpl.replace("{{MAIN}}", main_tmpl);
68
+ tmpl = tmpl.replace("{{SIDEBAR}}", sidebar_tmpl);
69
+
70
+ // add to dom
71
+ this.$el.html(tmpl);
72
+
73
+ // canvas clone
74
+ this.$el.find("canvas").each(function() {
75
+ var $canvas = $(this), file;
76
+ var file_id = that.$xfile.attr("file-id");
77
+
78
+ if (file_id) {
79
+ file = that.fileuploader.state.files[file_id];
80
+
81
+ if (file) {
82
+ file.readThumbnailData(220, 153, function(canvas) {
83
+ $canvas.replaceWith(canvas);
84
+ });
85
+ }
86
+ }
87
+ });
88
+ };
89
+
90
+
91
+
92
+ //
93
+ // Templates
94
+ //
95
+ FileUploaderMetadata.prototype.template = (function() {
96
+ return [
97
+ '<div class="mod-file-uploader-metadata">',
98
+ '<div class="main">{{MAIN}}</div>',
99
+ '<div class="sidebar">{{SIDEBAR}}</div>',
100
+ '</div>'
101
+ ].join("");
102
+ })();
103
+
104
+
105
+ FileUploaderMetadata.prototype.main_template = (function() {
106
+ return [
107
+ '<div class="fields">',
108
+ '{{FIELDS}}',
109
+ '</div>'
110
+ ].join("");
111
+ })();
112
+
113
+
114
+ FileUploaderMetadata.prototype.sidebar_template = (function() {
115
+ return [
116
+ '{{IMAGE}}',
117
+ '<div class="meta">{{META}}</div>',
118
+ '<div class="actions">',
119
+ '<a class="button commit">Update meta data</a>',
120
+ '<a class="button cancel">Cancel</a>',
121
+ '</div>'
122
+ ].join("");
123
+ })();
124
+
125
+
126
+ FileUploaderMetadata.prototype.get_form_template = function() {
127
+ var $x = this.fileuploader.$el.find("template.form-template");
128
+ var x = $x.get(0);
129
+ var wrapper = document.createElement("div");
130
+
131
+ if (x.content) {
132
+ $(wrapper).append( $(x.content.children).clone() );
133
+ } else {
134
+ $(wrapper).append( $x.clone().unwrap() );
135
+ }
136
+
137
+ return wrapper.innerHTML;
138
+ };
139
+
140
+
141
+
142
+ //
143
+ // Events (General)
144
+ //
145
+ FileUploaderMetadata.prototype.bind_events = function() {
146
+ this.$el.on("click", "a.button.commit", $.proxy(this.commit_click_handler, this));
147
+ this.$el.on("click", "a.button.cancel", $.proxy(this.cancel_click_handler, this));
148
+ };
149
+
150
+
151
+ FileUploaderMetadata.prototype.unbind_events = function() {
152
+ this.$el.off("click");
153
+ };
154
+
155
+
156
+
157
+ //
158
+ // Actions
159
+ //
160
+ FileUploaderMetadata.prototype.commit_click_handler = function() {
161
+ this.copy_attributes_to_xfile();
162
+ this.hide();
163
+ };
164
+
165
+
166
+ FileUploaderMetadata.prototype.cancel_click_handler = function() {
167
+ this.hide();
168
+ };
169
+
170
+
171
+
172
+ //
173
+ // Attributes
174
+ //
175
+ FileUploaderMetadata.prototype.copy_attributes_to_xfile = function() {
176
+ var $xattr = this.$xfile.find(".attributes");
177
+ var new_attributes_container;
178
+
179
+ if ($xattr.length === 0) {
180
+ new_attributes_container = document.createElement("div");
181
+ new_attributes_container.className = "attributes";
182
+ new_attributes_container.innerHTML = this.get_form_template();
183
+
184
+ this.$xfile.find("[name$=\"id]\"]").after(new_attributes_container);
185
+ $xattr = $(new_attributes_container);
186
+
187
+ this.fileuploader.remove_hidden_fields_from_checkboxes($xattr);
188
+ }
189
+
190
+ this.$el.find(".fields [name]").each(function() {
191
+ var $field = $(this),
192
+ tag_name = this.tagName.toLowerCase(),
193
+ sel_attr_name = '[name="' + $field.attr("name") + '"]',
194
+ $xattr_field = $xattr.find(sel_attr_name);
195
+
196
+ // input
197
+ if (tag_name == "input") {
198
+ if ($field.attr("type") == "checkbox") {
199
+ $xattr_field = $xattr_field.filter("[type=\"checkbox\"]");
200
+
201
+ if ($field.is(":checked")) {
202
+ $xattr_field.attr("checked", "checked");
203
+ $xattr_field.val($field.val());
204
+ } else {
205
+ $xattr_field.removeAttr("checked");
206
+ }
207
+ } else {
208
+ $xattr_field.val( $field.val() );
209
+ $xattr_field.attr("value", $field.val() );
210
+ }
211
+
212
+ // textarea
213
+ } else if (tag_name == "textarea") {
214
+ $xattr_field.val( $field.val() );
215
+ $xattr_field.html( $field.val() );
216
+
217
+ // select
218
+ } else if (tag_name == "select") {
219
+ var $selected_thru_attr = $field.children("[selected]"),
220
+ $selected_alt = $field.children(":selected");
221
+
222
+ if ($selected_thru_attr.get(0) !== $selected_alt.get(0)) {
223
+ $selected_thru_attr.removeAttr("selected");
224
+ $selected_alt.attr("selected", "selected");
225
+ }
226
+
227
+ $xattr_field.html( $field.html() );
228
+
229
+ }
230
+ });
231
+ };
232
+
233
+
234
+
235
+ //
236
+ // Other
237
+ //
238
+ FileUploaderMetadata.prototype.hide = function() {
239
+ this.unbind_events();
240
+ Overlay.get_instance().hide();
241
+ };
242
+
243
+
244
+
245
+ //
246
+ // -> EXPORT
247
+ //
248
+ module.exports = FileUploaderMetadata;
@@ -0,0 +1,376 @@
1
+ var FileUploaderMetadata = require("lalala/modules/file-uploader-metadata"),
2
+ Overlay = require("lalala/modules/overlay");
3
+
4
+
5
+
6
+ function FileUploader(xfiles_element) {
7
+ this.$el = $(xfiles_element);
8
+ this.$file_container = this.$el.find(".file-container");
9
+ this.$form = this.$el.closest("form");
10
+
11
+ this.state = {
12
+ files: {},
13
+ files_counter: 0
14
+ };
15
+
16
+ this.render_isempty_message_if_needed();
17
+ this.make_xfile_template();
18
+ this.make_items_sortable();
19
+ this.show_amount_of_files();
20
+ this.remove_hidden_fields_from_checkboxes(this.$file_container);
21
+ this.bind_events();
22
+ }
23
+
24
+
25
+
26
+ //
27
+ // Templates, views, etc.
28
+ //
29
+ FileUploader.prototype.make_xfile_template = function() {
30
+ var $template = this.$el.find("template.x-file-template");
31
+ var template = $template.get(0);
32
+ var $wrapper = $("<x-file />");
33
+ var $content;
34
+
35
+ if (template) {
36
+ if (template.content) {
37
+ $content = $(template.content.children);
38
+ $wrapper.append($content);
39
+ } else {
40
+ $content = $template.remove().unwrap();
41
+ $wrapper.append($content);
42
+ }
43
+
44
+ $template.remove();
45
+ this.xfile_template = $wrapper.get(0);
46
+
47
+ } else {
48
+ this.xfile_template = null;
49
+
50
+ }
51
+ };
52
+
53
+
54
+ FileUploader.prototype.render_isempty_message_if_needed = function() {
55
+ if (this.$file_container.find("x-file").length === 0) {
56
+ this.$file_container[0].innerHTML = [
57
+ "<div class=\"is-empty\">",
58
+ "<div class=\"message\">",
59
+ "Browse or drag files in here...",
60
+ "</div>",
61
+ "</div>"
62
+ ].join("");
63
+
64
+ this.set_data_inspection_html("");
65
+ }
66
+ };
67
+
68
+
69
+ FileUploader.prototype.set_data_inspection_html = function(html) {
70
+ this.$el.find("header .data-inspection").html(html);
71
+ };
72
+
73
+
74
+ FileUploader.prototype.clear_file_container = function() {
75
+ this.$file_container.empty();
76
+ this.$file_container.append("<div class=\"inner-wrapper\" />");
77
+ };
78
+
79
+
80
+ FileUploader.prototype.show_amount_of_files = function() {
81
+ var amount_of_files = this.$file_container.find("x-file").length;
82
+ var word = (amount_of_files === 1 ? "file" : "files");
83
+
84
+ this.set_data_inspection_html(
85
+ amount_of_files + " " + word
86
+ );
87
+ };
88
+
89
+
90
+ FileUploader.prototype.remove_hidden_fields_from_checkboxes = function($element) {
91
+ $element.find("input[type=\"checkbox\"]").each(function() {
92
+ var name = $(this).attr("name");
93
+ $element.find('[name="' + name + '"][type="hidden"]').remove();
94
+ });
95
+ };
96
+
97
+
98
+
99
+ //
100
+ // Handle file
101
+ //
102
+ FileUploader.prototype.handle_file = function(file) {
103
+ this.state.files_counter++;
104
+ this.state.files[this.state.files_counter.toString()] = file;
105
+
106
+ // element
107
+ file.$el = $(this.xfile_template).clone();
108
+ file.$el.attr("file-id", this.state.files_counter.toString());
109
+
110
+ file.el = file.$el.get(0);
111
+
112
+ // waiting class
113
+ file.$el.addClass("waiting");
114
+
115
+ // make thumbnail
116
+ if (file.type.indexOf("image") == -1) {
117
+ var fake_thumb = document.createElement("div");
118
+ fake_thumb.className = "thumb no-image";
119
+ file.el.insertBefore(fake_thumb, file.el.firstChild);
120
+
121
+ } else {
122
+ file.readThumbnailData(158, 110, function(canvas) {
123
+ file.el.insertBefore(canvas, file.el.firstChild);
124
+ });
125
+
126
+ }
127
+
128
+ // if there are no files yet in the file container, empty it.
129
+ // this is done to remove messages, etc.
130
+ if (this.$file_container.find("x-file").length === 0) {
131
+ this.clear_file_container();
132
+ }
133
+
134
+ // add file element to dom
135
+ this.$file_container.children(".inner-wrapper").append(file.el);
136
+
137
+ // data inspection
138
+ this.show_amount_of_files();
139
+
140
+ // bind events
141
+ file.on("start", this.file_start_handler);
142
+ file.on("progress", this.file_progess_handler);
143
+ file.on("err", this.file_err_handler);
144
+ file.on("done:uploading", this.file_done_uploading_handler);
145
+ file.on("done:processing", this.file_done_processing_handler);
146
+ file.on("done", this.file_done_handler);
147
+ };
148
+
149
+
150
+
151
+ //
152
+ // Events - File handlers
153
+ //
154
+ // -> this = file
155
+ //
156
+ FileUploader.prototype.file_start_handler = function(e) {
157
+ this.$el.removeClass("waiting");
158
+ this.$el.addClass("uploading");
159
+ };
160
+
161
+
162
+ FileUploader.prototype.file_progess_handler = function(e) {
163
+ if (this.$el.hasClass("error")) return;
164
+
165
+ // if there are no transform -> upload percentage
166
+ if (this.transforms === 0) {
167
+ this.$el.find(".upload-bar").css("width", this.upload_percentage + "%");
168
+
169
+ // if there are -> transform percentage
170
+ } else {
171
+ this.$el.find(".process-bar").css("width", this.transforms_percentage + "%");
172
+
173
+ }
174
+ };
175
+
176
+
177
+ FileUploader.prototype.file_err_handler = function(e) {
178
+ console.error("Error", this);
179
+
180
+ this.$el.addClass("error");
181
+ this.$el.find(".upload-bar").css("width", "100%");
182
+ this.$el.find(".process-bar").css("width", "100%");
183
+ };
184
+
185
+
186
+ FileUploader.prototype.file_done_uploading_handler = function(e) {
187
+ this.$el.find(".upload-bar").addClass("done");
188
+ this.$el.removeClass("uploading");
189
+ this.$el.addClass("processing");
190
+ };
191
+
192
+
193
+ FileUploader.prototype.file_done_processing_handler = function(e) {
194
+ this.$el.find(".process-bar").addClass("done");
195
+ };
196
+
197
+
198
+ FileUploader.prototype.file_done_handler = function(e) {
199
+ var name = this.$el.closest("x-files").attr("name");
200
+ var pairs = format_asset_metadata(this.metadata, name + "[]");
201
+
202
+ for (var i in pairs) {
203
+ var input = document.createElement("input");
204
+ input.type = "hidden";
205
+ input.name = pairs[i].name;
206
+ input.value = pairs[i].value;
207
+ this.el.appendChild(input);
208
+ }
209
+
210
+ this.$el.removeClass("processing");
211
+ this.$el.addClass("uploaded");
212
+ };
213
+
214
+
215
+
216
+ //
217
+ // Events - General
218
+ //
219
+ FileUploader.prototype.bind_events = function() {
220
+ var choose_handler = $.proxy(this.choose_click_handler, this);
221
+ var delete_handler = $.proxy(this.xfile_btn_delete_click_handler, this);
222
+ var meta_handler = $.proxy(this.xfile_btn_meta_click_handler, this);
223
+
224
+ this.$el.on("click", ".choose", choose_handler);
225
+ this.$el.on("click", "x-file [data-action=\"delete\"]", delete_handler);
226
+ this.$el.on("click", "x-file [data-action=\"meta\"]", meta_handler);
227
+
228
+ // when processing/uploading files -> disable form
229
+ Haraway.on("busy", $.proxy(function() {
230
+ this.$form.on("submit", this.defer_submit);
231
+ }, this));
232
+
233
+ // when not processing/uploading files -> resume default behaviour
234
+ Haraway.on("idle", $.proxy(function() {
235
+ this.$form.off("submit", this.defer_submit);
236
+ }, this));
237
+ };
238
+
239
+
240
+ FileUploader.prototype.choose_click_handler = function(e) {
241
+ var accept = this.$el.attr("accept").split(",");
242
+ var profile = this.$el.attr("profile");
243
+
244
+ // prevent default
245
+ e.preventDefault();
246
+
247
+ // show choose dialog
248
+ Haraway.choose(accept, true, profile, $.proxy(this.handle_file, this));
249
+ };
250
+
251
+
252
+ FileUploader.prototype.defer_submit = function(e) {
253
+ var $form = $(e.currentTarget);
254
+
255
+ // prevent default behaviour
256
+ e.preventDefault();
257
+
258
+ // disable submit button
259
+ $form.find("input[type=\"submit\"]").attr("disabled", "disabled");
260
+
261
+ // once processing/uploading is complete
262
+ // enable submit button and submit form
263
+ Haraway.once("idle", function() {
264
+ $form.find("input[type=submit]").attr("disabled", null);
265
+ $form.submit();
266
+ });
267
+ };
268
+
269
+
270
+ FileUploader.prototype.xfile_btn_delete_click_handler = function(e) {
271
+ var $xfile = $(e.currentTarget).closest("x-file");
272
+ if ($xfile.length) this.toggle_destroy($xfile);
273
+ };
274
+
275
+
276
+ FileUploader.prototype.xfile_btn_meta_click_handler = function(e) {
277
+ var $xfile = $(e.currentTarget).closest("x-file"), fum;
278
+ var main_overlay = Overlay.get_instance();
279
+
280
+ // check status, must be uploaded file
281
+ if (!$xfile.hasClass("uploaded")) return;
282
+
283
+ // new metadata overlay-content block
284
+ fum = new FileUploaderMetadata($xfile, this);
285
+ main_overlay.append_content(fum.$el);
286
+ main_overlay.$el.find("select").chosen({ width: "80%" });
287
+ main_overlay.show("file-uploader-metadata");
288
+ };
289
+
290
+
291
+
292
+ //
293
+ // Destroy
294
+ //
295
+ FileUploader.prototype.toggle_destroy = function($xfile) {
296
+ if ($xfile.hasClass("about-to-destroy")) {
297
+ this.set_to_not_destroy($xfile);
298
+ } else {
299
+ this.set_to_destroy($xfile);
300
+ }
301
+ };
302
+
303
+
304
+ FileUploader.prototype.set_to_destroy = function($xfile) {
305
+ var $destroy, $id;
306
+
307
+ // add class
308
+ $xfile.addClass("about-to-destroy");
309
+
310
+ // input
311
+ $destroy = $xfile.find("[name$=\"_destroy]\"]");
312
+
313
+ if ($destroy.length === 0) {
314
+ $id = $xfile.find("[name$=\"[id]\"]");
315
+ $destroy = $("<input />");
316
+ $destroy.attr("type", "hidden");
317
+ $destroy.attr("name", $id.attr("name").replace("id", "_destroy"));
318
+ $id.after($destroy);
319
+ }
320
+
321
+ // set
322
+ $destroy.attr("value", "1");
323
+ };
324
+
325
+
326
+ FileUploader.prototype.set_to_not_destroy = function($xfile) {
327
+ $xfile.removeClass("about-to-destroy");
328
+ $xfile.find("[name$=\"_destroy]\"]").attr("value", "0");
329
+ };
330
+
331
+
332
+
333
+ //
334
+ // Sortable
335
+ //
336
+ FileUploader.prototype.make_items_sortable = function() {
337
+ this.$el.sortable({
338
+ containment: "parent",
339
+ items: "x-file",
340
+ handle: "[data-action=\"move\"]"
341
+ });
342
+ };
343
+
344
+
345
+
346
+ //
347
+ // Extra's
348
+ //
349
+ function format_asset_metadata(value, prefix) {
350
+ var results = [], i;
351
+
352
+ if (value instanceof Array) {
353
+ for (i in value) {
354
+ results = results.concat(format_asset_metadata(value[i], prefix + "[]"));
355
+ }
356
+ return results;
357
+ }
358
+
359
+ if (value === Object(value)) {
360
+ for (i in value) {
361
+ if (value.hasOwnProperty(i)) {
362
+ results = results.concat(format_asset_metadata(value[i], prefix + "[" + i + "]"));
363
+ }
364
+ }
365
+ return results;
366
+ }
367
+
368
+ return [{ name: prefix, value: value }];
369
+ }
370
+
371
+
372
+
373
+ //
374
+ // -> EXPORT
375
+ //
376
+ module.exports = FileUploader;
@@ -1,24 +1,20 @@
1
1
  var console = require('browser/console'),
2
2
  calendar = require('lalala/modules/calendar'),
3
3
  editor = require('lalala/modules/editor'),
4
- grid = require('lalala/modules/grid'),
5
4
  locale_chooser = require("lalala/modules/locale_chooser"),
6
5
  sorted_pages_tree = require("lalala/modules/sorted_pages_tree"),
7
6
  login = require("lalala/modules/login"),
8
7
  dashboard = require("lalala/modules/dashboard"),
9
- collapsible_pages_tree = require("lalala/modules/collapsible_pages_tree"),
10
- input_group = require("lalala/modules/input_group");
8
+ collapsible_pages_tree = require("lalala/modules/collapsible_pages_tree");
11
9
 
12
10
  $(function() {
13
11
  login.init();
14
12
  locale_chooser.init();
15
13
  editor.init();
16
14
  calendar.init();
17
- grid.init();
18
15
  sorted_pages_tree.init();
19
16
  dashboard.init();
20
17
  collapsible_pages_tree.init();
21
- input_group.init();
22
18
 
23
19
  $('select').not(".bypass-chosen").chosen();
24
20
  });