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.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/Gemfile +1 -3
- data/Haraway.md +14 -0
- data/app/assets/javascripts/lalala/base.js +8 -0
- data/app/assets/javascripts/lalala/initializers/chosen.module.js +3 -0
- data/app/assets/javascripts/lalala/initializers/haraway.module.js +8 -0
- data/app/assets/javascripts/lalala/lib/overlay.js +335 -0
- data/app/assets/javascripts/lalala/modules/collapsible_pages_tree.module.js +26 -33
- data/app/assets/javascripts/lalala/modules/editor.module.js +37 -23
- data/app/assets/javascripts/lalala/modules/file-uploader-metadata.module.js +248 -0
- data/app/assets/javascripts/lalala/modules/file-uploader.module.js +376 -0
- data/app/assets/javascripts/lalala/modules/init.module.js +1 -5
- data/app/assets/javascripts/lalala/modules/media_selector.module.js +250 -0
- data/app/assets/javascripts/lalala/modules/overlay.module.js +33 -0
- data/app/assets/stylesheets/lalala/_base.css.scss +5 -2
- data/app/assets/stylesheets/lalala/components/_buttons.css.scss +11 -3
- data/app/assets/stylesheets/lalala/components/_forms.css.scss +14 -64
- data/app/assets/stylesheets/lalala/lib/_overlay.css.scss +66 -0
- data/app/assets/stylesheets/lalala/modules/_dashboard.css.scss +10 -51
- data/app/assets/stylesheets/lalala/modules/_editor-cheatsheet.css.scss +1 -17
- data/app/assets/stylesheets/lalala/modules/_file-uploader-metadata.css.scss +118 -0
- data/app/assets/stylesheets/lalala/modules/_file-uploader.css.scss +289 -0
- data/app/assets/stylesheets/lalala/modules/_media-selector.css.scss +113 -0
- data/app/assets/stylesheets/lalala/modules/_title-bar.css.scss +0 -17
- data/app/controllers/lalala/public/errors_controller.rb +7 -0
- data/app/models/lalala/page.rb +0 -1
- data/app/views/lalala/markdown/cheatsheet.html.erb +0 -2
- data/config/routes.rb +12 -1
- data/lalala-assets.gemspec +3 -3
- data/lalala-development.gemspec +1 -1
- data/lalala-test.gemspec +1 -1
- data/lalala.gemspec +4 -5
- data/lib/formtastic/form_builder_ext.rb +10 -0
- data/lib/formtastic/inputs/haraway_input.rb +151 -0
- data/lib/generators/lalala/assets/templates/bower.json.erb +1 -1
- data/lib/generators/lalala/install/install_generator.rb +0 -23
- data/lib/lalala/admin/pages.rb +1 -26
- data/lib/lalala/engine.rb +0 -7
- data/lib/lalala/ext_action_dispatch.rb +0 -1
- data/lib/lalala/ext_active_record/i18n_translations_writer.rb +0 -1
- data/lib/lalala/ext_active_record.rb +0 -1
- data/lib/lalala/ext_i18n/input_helper.rb +0 -1
- data/lib/lalala/ext_i18n/negotiation_adapter.rb +0 -4
- data/lib/lalala/ext_i18n/test_negotiation_adapter.rb +0 -4
- data/lib/lalala/ext_rack/i18n_negotiator.rb +7 -9
- data/lib/lalala/markdown/handlers/asset.rb +24 -0
- data/lib/lalala/markdown/handlers/youtube.rb +9 -13
- data/lib/lalala/markdown/html_renderer.rb +2 -2
- data/lib/lalala/markdown.rb +2 -3
- data/lib/lalala/utils/install_template.rb +3 -9
- data/lib/lalala/version.rb +2 -2
- data/lib/lalala.rb +6 -7
- data/script/ci +33 -30
- data/test/dummy/app/admin/articles.rb +26 -12
- data/test/dummy/app/admin/dashboard.rb +5 -8
- data/test/dummy/app/admin/tags.rb +1 -3
- data/test/dummy/app/assets/stylesheets/_normalize.css +423 -0
- data/test/dummy/app/assets/stylesheets/application.css.scss +2 -0
- data/test/dummy/app/assets/stylesheets/base/_base.css.scss +4 -0
- data/test/dummy/app/controllers/pages_controller.rb +4 -0
- data/test/dummy/app/models/article.rb +10 -4
- data/test/dummy/app/pages/application_page.rb +7 -2
- data/test/dummy/app/pages/basic_page.rb +5 -6
- data/test/dummy/app/pages/home_page.rb +10 -10
- data/test/dummy/app/pages/media_page.rb +23 -0
- data/test/dummy/app/views/admin/_stats.html.erb +7 -14
- data/test/dummy/app/views/layouts/application.html.erb +6 -2
- data/test/dummy/app/views/pages/media.html.erb +3 -0
- data/test/dummy/config/initializers/haraway.rb +29 -0
- data/test/dummy/config/routes.rb +1 -0
- data/test/dummy/db/migrate/20130528092721_create_articles.rb +1 -0
- data/test/dummy/db/migrate/20130729125648_create_home_page.rb +4 -0
- data/test/dummy/db/migrate/20131122144302_enable_haraway.rb +16 -0
- data/test/dummy/db/migrate/20140228141749_create_media_page.rb +8 -0
- data/test/dummy/db/schema.rb +2 -4
- data/test/integration/aricles_test.rb +0 -1
- metadata +59 -81
- data/app/assets/javascripts/jquery-ui/sortable.js +0 -0
- data/app/assets/javascripts/lalala/lib/jquery-ui.js +0 -16617
- data/app/assets/javascripts/lalala/modules/grid.module.js +0 -284
- data/app/assets/javascripts/lalala/modules/input_group.module.js +0 -36
- data/app/assets/stylesheets/lalala/modules/_grid.css.scss +0 -197
- data/app/assets/stylesheets/lalala/modules/_index-as-sortable.css.scss +0 -89
- data/app/models/lalala/abstract_asset.rb +0 -24
- data/app/models/lalala/file_asset.rb +0 -3
- data/app/models/lalala/image_asset.rb +0 -3
- data/config/initializers/carrierwave.rb +0 -34
- data/lib/formtastic/inputs/grid_input.rb +0 -159
- data/lib/formtastic/inputs/single_file_input.rb +0 -44
- data/lib/generators/lalala/install/templates/application.html.erb +0 -64
- data/lib/generators/lalala/install/templates/helpers/application_helper.rb +0 -16
- data/lib/generators/lalala/install/templates/helpers/html_helper.rb +0 -60
- data/lib/generators/lalala/install/templates/helpers/open_graph_helper.rb.erb +0 -92
- data/lib/generators/lalala/install/templates/helpers/pages_helper.rb +0 -15
- data/lib/generators/lalala/install/templates/locales/en.yml +0 -6
- data/lib/generators/lalala/install/templates/uploaders/file_uploader.rb +0 -2
- data/lib/generators/lalala/install/templates/uploaders/image_uploader.rb +0 -11
- data/lib/lalala/ext_action_dispatch/multi_file_upload.rb +0 -55
- data/lib/lalala/ext_active_record/assets.rb +0 -25
- data/lib/lalala/markdown/handlers/soundcloud.rb +0 -36
- data/lib/lalala/markdown/handlers/vimeo.rb +0 -40
- data/lib/lalala/uploaders/file.rb +0 -50
- data/lib/lalala/uploaders/image.rb +0 -13
- data/lib/lalala/uploaders.rb +0 -6
- data/test/dummy/app/assets/stylesheets/application.css +0 -13
- data/test/dummy/app/models/file_asset.rb +0 -2
- data/test/dummy/app/models/image_asset.rb +0 -2
- data/test/dummy/app/uploaders/file_uploader.rb +0 -2
- data/test/dummy/app/uploaders/image_uploader.rb +0 -11
- 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
|
});
|