Skip to content

Commit aca957f

Browse files
authored
Merge pull request #33 from NikoRoberts/master
Converted coffee files to es6
2 parents 588af96 + 8d10d03 commit aca957f

File tree

6 files changed

+103
-81
lines changed

6 files changed

+103
-81
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ And then execute:
2929
$ bundle
3030
```
3131

32-
Add the following line at the end of "app/assets/javascript/active_admin.js.coffee":
32+
Add the following line at the end of "app/assets/javascript/active_admin.js":
3333

3434
```javascript
3535
//= require active_admin_scoped_collection_actions

active_admin_scoped_collection_actions.gemspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,5 @@ Gem::Specification.new do |spec|
1717
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
1818
spec.require_paths = ["lib"]
1919

20-
spec.add_dependency "coffee-rails"
2120
spec.add_dependency "activeadmin", ">= 1.1", "< 3.a"
2221
end
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//= require ./lib/dialog_mass_fields_update
2+
3+
$(document).ready(() =>
4+
5+
$(document).on('click', '.scoped_collection_action_button', function(e) {
6+
e.preventDefault();
7+
const fields = JSON.parse( $(this).attr('data') );
8+
9+
return ActiveAdmin.dialogMassFieldsUpdate(fields['confirm'], fields['inputs'],
10+
inputs=> {
11+
const url = window.location.pathname + '/batch_action' + window.location.search;
12+
const form_data = {
13+
changes: inputs,
14+
collection_selection: [],
15+
authenticity_token: fields['auth_token'],
16+
batch_action: fields['batch_action']
17+
};
18+
$('.paginated_collection').find('input.collection_selection:checked').each((i, el) => form_data["collection_selection"].push($(el).val()));
19+
20+
return $.post(url, form_data).always(function(data, textStatus, jqXHR) {
21+
if (jqXHR.getResponseHeader('Location')) {
22+
return window.location.assign(jqXHR.getResponseHeader('Location'));
23+
} else {
24+
return window.location.reload();
25+
}
26+
});
27+
});
28+
})
29+
);

vendor/assets/javascripts/active_admin_scoped_collection_actions.js.coffee

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
ActiveAdmin.dialogMassFieldsUpdate = function(message, inputs, callback){
2+
let html = `<form id="dialog_confirm" title="${message}"><div stype="padding-right:4px;padding-left:1px;margin-right:2px"><ul>`;
3+
for (let name in inputs) {
4+
var elem, opts, wrapper;
5+
let type = inputs[name];
6+
if (/^(datepicker|checkbox|text)$/.test(type)) {
7+
wrapper = 'input';
8+
} else if ($.isArray(type)) {
9+
[wrapper, elem, opts, type] = Array.from(['select', 'option', type, '']);
10+
} else {
11+
throw new Error(`Unsupported input type: {${name}: ${type}}`);
12+
}
13+
14+
let klass = type === 'datepicker' ? type : '';
15+
html += `<li>
16+
<input type='checkbox' class='mass_update_protect_fild_flag' value='Y' id="mass_update_dialog_${name}" />
17+
<label for="mass_update_dialog_${name}"> ${name.charAt(0).toUpperCase() + name.slice(1)}</label>
18+
<${wrapper} name="${name}" class="${klass}" type="${type}" disabled="disabled">` +
19+
(opts ? ((() => {
20+
const result = [];
21+
22+
for (let v of Array.from(opts)) {
23+
const $elem = $(`<${elem}/>`);
24+
if ($.isArray(v)) {
25+
$elem.text(v[0]).val(v[1]);
26+
} else {
27+
$elem.text(v);
28+
}
29+
result.push($elem.wrap('<div>').parent().html());
30+
}
31+
32+
return result;
33+
})()).join('') : '');
34+
if (wrapper === 'select') {
35+
html += `</${wrapper}>`;
36+
}
37+
html += "</li>";
38+
39+
[wrapper, elem, opts, type, klass] = Array.from([]);
40+
} // unset any temporary variables
41+
42+
html += "</ul></div></form>";
43+
44+
const form = $(html).appendTo('body');
45+
46+
$('body').trigger('mass_update_modal_dialog:before_open', [form]);
47+
48+
return form.dialog({
49+
modal: true,
50+
dialogClass: 'active_admin_dialog active_admin_dialog_mass_update_by_filter',
51+
maxHeight: window.innerHeight - (window.innerHeight * 0.1),
52+
open() {
53+
$('body').trigger('mass_update_modal_dialog:after_open', [form]);
54+
return $('.mass_update_protect_fild_flag').on('change', function(e) {
55+
if (this.checked) {
56+
return $(e.target).next().next().removeAttr('disabled').trigger("chosen:updated");
57+
} else {
58+
return $(e.target).next().next().attr('disabled', 'disabled').trigger("chosen:updated");
59+
}
60+
});
61+
},
62+
buttons: {
63+
OK(e){
64+
$(e.target).closest('.ui-dialog-buttonset').html('<span>Processing. Please wait...</span>');
65+
return callback($(this).serializeObject());
66+
},
67+
Cancel() {
68+
$('.mass_update_protect_fild_flag').off('change');
69+
return $(this).dialog('close').remove();
70+
}
71+
}
72+
});
73+
};

vendor/assets/javascripts/lib/dialog_mass_fields_update.js.coffee

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)