Merge pull request #3653 from consul/migrate_coffeescript
Migrate CoffeeScript to JavaScript
This commit is contained in:
@@ -1,41 +0,0 @@
|
||||
{
|
||||
"arrow_spacing": {
|
||||
"level": "error"
|
||||
},
|
||||
"braces_spacing": {
|
||||
"level": "error",
|
||||
"spaces": 1
|
||||
},
|
||||
"colon_assignment_spacing": {
|
||||
"level": "error",
|
||||
"spacing": {
|
||||
"left": 0,
|
||||
"right": 1
|
||||
}
|
||||
},
|
||||
"eol_last": {
|
||||
"level": "error"
|
||||
},
|
||||
"indentation": {
|
||||
"value": 2
|
||||
},
|
||||
"line_endings": {
|
||||
"level": "error"
|
||||
},
|
||||
"max_line_length": {
|
||||
"value": 100,
|
||||
"level": "error",
|
||||
"limitComments": true
|
||||
},
|
||||
"no_trailing_whitespace": {
|
||||
"level": "error",
|
||||
"allowed_in_comments": false,
|
||||
"allowed_in_empty_lines": false
|
||||
},
|
||||
"space_operators": {
|
||||
"level": "error"
|
||||
},
|
||||
"spacing_after_comma": {
|
||||
"level": "error"
|
||||
}
|
||||
}
|
||||
84
.eslintrc.yml
Normal file
84
.eslintrc.yml
Normal file
@@ -0,0 +1,84 @@
|
||||
env:
|
||||
browser: true
|
||||
es6: false
|
||||
extends: "eslint:recommended"
|
||||
globals:
|
||||
$: readonly
|
||||
App: readonly
|
||||
annotator: readonly
|
||||
c3: readonly
|
||||
CKEDITOR: readonly
|
||||
L: readonly
|
||||
Turbolinks: readonly
|
||||
parserOptions:
|
||||
ecmaVersion: 5
|
||||
rules:
|
||||
array-bracket-spacing: error
|
||||
array-callback-return: error
|
||||
block-spacing: error
|
||||
brace-style: error
|
||||
comma-spacing: error
|
||||
computed-property-spacing: error
|
||||
curly: error
|
||||
dot-notation: error
|
||||
eol-last: error
|
||||
eqeqeq:
|
||||
- error
|
||||
- always
|
||||
- "null": ignore
|
||||
func-call-spacing: error
|
||||
indent:
|
||||
- error
|
||||
- 2
|
||||
key-spacing: error
|
||||
keyword-spacing: error
|
||||
linebreak-style: error
|
||||
lines-between-class-members: error
|
||||
max-len:
|
||||
- warn
|
||||
- code: 110
|
||||
no-array-constructor: error
|
||||
no-console: error
|
||||
no-multi-spaces: error
|
||||
no-multiple-empty-lines:
|
||||
- error
|
||||
- max: 1
|
||||
no-param-reassign: error
|
||||
no-shadow: error
|
||||
no-spaced-func: error
|
||||
no-tabs: error
|
||||
no-trailing-spaces: error
|
||||
no-void: error
|
||||
no-whitespace-before-property: error
|
||||
object-curly-spacing:
|
||||
- error
|
||||
- always
|
||||
- objectsInObjects: false
|
||||
padded-blocks:
|
||||
- error
|
||||
- never
|
||||
quotes:
|
||||
- error
|
||||
- double
|
||||
- avoidEscape: true
|
||||
semi:
|
||||
- error
|
||||
- always
|
||||
semi-spacing: error
|
||||
space-before-blocks: error
|
||||
space-before-function-paren:
|
||||
- error
|
||||
- never
|
||||
space-in-parens: error
|
||||
space-infix-ops: error
|
||||
space-unary-ops: error
|
||||
spaced-comment:
|
||||
- error
|
||||
- always
|
||||
- markers:
|
||||
- "="
|
||||
exceptions:
|
||||
- "-"
|
||||
strict: error
|
||||
switch-colon-spacing: error
|
||||
yoda: error
|
||||
@@ -2,8 +2,9 @@ rubocop:
|
||||
config_file: .rubocop_basic.yml
|
||||
scss:
|
||||
config_file: .scss-lint.yml
|
||||
coffeescript:
|
||||
config_file: .coffeelint.json
|
||||
erblint:
|
||||
enabled: true
|
||||
config_file: .erb-lint.yml
|
||||
eslint:
|
||||
enabled: true
|
||||
config_file: .eslintrc.yml
|
||||
|
||||
1
Gemfile
1
Gemfile
@@ -13,7 +13,6 @@ gem "browser", "~> 2.5.3"
|
||||
gem "cancancan", "~> 2.3.0"
|
||||
gem "ckeditor", "~> 4.2.3"
|
||||
gem "cocoon", "~> 1.2.9"
|
||||
gem "coffee-rails", "~> 4.2.2"
|
||||
gem "daemons", "~> 1.2.4"
|
||||
gem "dalli", "~> 2.7.6"
|
||||
gem "delayed_job_active_record", "~> 4.1.3"
|
||||
|
||||
@@ -594,7 +594,6 @@ DEPENDENCIES
|
||||
capybara-webmock (~> 0.5.3)
|
||||
ckeditor (~> 4.2.3)
|
||||
cocoon (~> 1.2.9)
|
||||
coffee-rails (~> 4.2.2)
|
||||
coveralls (~> 0.8.22)
|
||||
daemons (~> 1.2.4)
|
||||
dalli (~> 2.7.6)
|
||||
|
||||
47
app/assets/javascripts/advanced_search.js
Normal file
47
app/assets/javascripts/advanced_search.js
Normal file
@@ -0,0 +1,47 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.AdvancedSearch = {
|
||||
advanced_search_terms: function() {
|
||||
return $("#js-advanced-search").data("advanced-search-terms");
|
||||
},
|
||||
toggle_form: function(event) {
|
||||
event.preventDefault();
|
||||
$("#js-advanced-search").slideToggle();
|
||||
},
|
||||
toggle_date_options: function() {
|
||||
if ($("#js-advanced-search-date-min").val() === "custom") {
|
||||
$("#js-custom-date").show();
|
||||
$(".js-calendar").datepicker("option", "disabled", false);
|
||||
} else {
|
||||
$("#js-custom-date").hide();
|
||||
$(".js-calendar").datepicker("option", "disabled", true);
|
||||
}
|
||||
},
|
||||
init_calendar: function() {
|
||||
var locale;
|
||||
locale = $("#js-locale").data("current-locale");
|
||||
$(".js-calendar").datepicker({
|
||||
maxDate: "+0d"
|
||||
});
|
||||
$(".js-calendar-full").datepicker();
|
||||
$.datepicker.setDefaults($.datepicker.regional[locale]);
|
||||
},
|
||||
initialize: function() {
|
||||
App.AdvancedSearch.init_calendar();
|
||||
if (App.AdvancedSearch.advanced_search_terms()) {
|
||||
$("#js-advanced-search").show();
|
||||
App.AdvancedSearch.toggle_date_options();
|
||||
}
|
||||
$("#js-advanced-search-title").on({
|
||||
click: function(event) {
|
||||
App.AdvancedSearch.toggle_form(event);
|
||||
}
|
||||
});
|
||||
$("#js-advanced-search-date-min").on({
|
||||
change: function() {
|
||||
App.AdvancedSearch.toggle_date_options();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,41 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.AdvancedSearch =
|
||||
|
||||
advanced_search_terms: ->
|
||||
$("#js-advanced-search").data("advanced-search-terms")
|
||||
|
||||
toggle_form: (event) ->
|
||||
event.preventDefault()
|
||||
$("#js-advanced-search").slideToggle()
|
||||
|
||||
toggle_date_options: ->
|
||||
if $("#js-advanced-search-date-min").val() == "custom"
|
||||
$("#js-custom-date").show()
|
||||
$( ".js-calendar" ).datepicker( "option", "disabled", false )
|
||||
else
|
||||
$("#js-custom-date").hide()
|
||||
$( ".js-calendar" ).datepicker( "option", "disabled", true )
|
||||
|
||||
init_calendar: ->
|
||||
locale = $("#js-locale").data("current-locale")
|
||||
|
||||
$(".js-calendar").datepicker
|
||||
maxDate: "+0d"
|
||||
$(".js-calendar-full").datepicker()
|
||||
$.datepicker.setDefaults($.datepicker.regional[locale])
|
||||
|
||||
initialize: ->
|
||||
App.AdvancedSearch.init_calendar()
|
||||
|
||||
if App.AdvancedSearch.advanced_search_terms()
|
||||
$("#js-advanced-search").show()
|
||||
App.AdvancedSearch.toggle_date_options()
|
||||
|
||||
$("#js-advanced-search-title").on
|
||||
click: (event) ->
|
||||
App.AdvancedSearch.toggle_form(event)
|
||||
|
||||
$("#js-advanced-search-date-min").on
|
||||
change: ->
|
||||
App.AdvancedSearch.toggle_date_options()
|
||||
17
app/assets/javascripts/allow_participation.js
Normal file
17
app/assets/javascripts/allow_participation.js
Normal file
@@ -0,0 +1,17 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.AllowParticipation = {
|
||||
initialize: function() {
|
||||
$(document).on({
|
||||
"mouseenter focus": function() {
|
||||
$(this).find(".js-participation-not-allowed").show();
|
||||
$(this).find(".js-participation-allowed").hide();
|
||||
},
|
||||
mouseleave: function() {
|
||||
$(this).find(".js-participation-not-allowed").hide();
|
||||
$(this).find(".js-participation-allowed").show();
|
||||
}
|
||||
}, ".js-participation");
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,13 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.AllowParticipation =
|
||||
|
||||
initialize: ->
|
||||
$(document).on {
|
||||
"mouseenter focus": ->
|
||||
$(this).find(".js-participation-not-allowed").show()
|
||||
$(this).find(".js-participation-allowed").hide()
|
||||
mouseleave: ->
|
||||
$(this).find(".js-participation-not-allowed").hide()
|
||||
$(this).find(".js-participation-allowed").show()
|
||||
}, ".js-participation"
|
||||
30
app/assets/javascripts/answers.js
Normal file
30
app/assets/javascripts/answers.js
Normal file
@@ -0,0 +1,30 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.Answers = {
|
||||
initializeAnswers: function(answers) {
|
||||
$(answers).on("cocoon:after-insert", function(e, new_answer) {
|
||||
var given_order;
|
||||
given_order = App.Answers.maxGivenOrder(answers) + 1;
|
||||
$(new_answer).find("[name$='[given_order]']").val(given_order);
|
||||
});
|
||||
},
|
||||
maxGivenOrder: function(answers) {
|
||||
var max_order;
|
||||
max_order = 0;
|
||||
$(answers).find("[name$='[given_order]']").each(function(index, answer) {
|
||||
var value;
|
||||
value = parseFloat($(answer).val());
|
||||
max_order = value > max_order ? value : max_order;
|
||||
});
|
||||
return max_order;
|
||||
},
|
||||
nestedAnswers: function() {
|
||||
$(".js-answers").each(function(index, answers) {
|
||||
App.Answers.initializeAnswers(answers);
|
||||
});
|
||||
},
|
||||
initialize: function() {
|
||||
App.Answers.nestedAnswers();
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,22 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.Answers =
|
||||
|
||||
initializeAnswers: (answers) ->
|
||||
$(answers).on "cocoon:after-insert", (e, new_answer) ->
|
||||
given_order = App.Answers.maxGivenOrder(answers) + 1
|
||||
$(new_answer).find("[name$='[given_order]']").val(given_order)
|
||||
|
||||
maxGivenOrder: (answers) ->
|
||||
max_order = 0
|
||||
$(answers).find("[name$='[given_order]']").each (index, answer) ->
|
||||
value = parseFloat($(answer).val())
|
||||
max_order = if value > max_order then value else max_order
|
||||
return max_order
|
||||
|
||||
nestedAnswers: ->
|
||||
$(".js-answers").each (index, answers) ->
|
||||
App.Answers.initializeAnswers(answers)
|
||||
|
||||
initialize: ->
|
||||
App.Answers.nestedAnswers()
|
||||
5
app/assets/javascripts/app.js
Normal file
5
app/assets/javascripts/app.js
Normal file
@@ -0,0 +1,5 @@
|
||||
// Generated by CoffeeScript 1.12.6
|
||||
(function() {
|
||||
"use strict";
|
||||
window.App = {};
|
||||
}).call(this);
|
||||
@@ -1,3 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
window.App = {}
|
||||
@@ -84,7 +84,7 @@
|
||||
//= require settings
|
||||
//= require cookies
|
||||
//= require columns_selector
|
||||
//= require budget_edit_associations.js.coffee
|
||||
//= require budget_edit_associations
|
||||
//= require votations
|
||||
|
||||
var initialize_modules = function() {
|
||||
@@ -116,8 +116,9 @@ var initialize_modules = function() {
|
||||
App.LegislationAdmin.initialize();
|
||||
App.LegislationAllegations.initialize();
|
||||
App.Legislation.initialize();
|
||||
if ( $(".legislation-annotatable").length )
|
||||
if ($(".legislation-annotatable").length) {
|
||||
App.LegislationAnnotatable.initialize();
|
||||
}
|
||||
App.WatchFormChanges.initialize();
|
||||
App.TreeNavigator.initialize();
|
||||
App.Documentable.initialize();
|
||||
@@ -135,14 +136,16 @@ var initialize_modules = function() {
|
||||
App.SendAdminNotificationAlert.initialize();
|
||||
App.ModalDownload.initialize();
|
||||
App.Settings.initialize();
|
||||
if ( $("#js-columns-selector").length )
|
||||
if ($("#js-columns-selector").length) {
|
||||
App.ColumnsSelector.initialize();
|
||||
}
|
||||
App.BudgetEditAssociations.initialize();
|
||||
if ( $("#votation_type_enum_type").length )
|
||||
if ($("#votation_type_enum_type").length) {
|
||||
App.Votations.initialize();
|
||||
}
|
||||
};
|
||||
|
||||
$(function(){
|
||||
$(function() {
|
||||
"use strict";
|
||||
|
||||
Turbolinks.enableProgressBar();
|
||||
|
||||
28
app/assets/javascripts/banners.js
Normal file
28
app/assets/javascripts/banners.js
Normal file
@@ -0,0 +1,28 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.Banners = {
|
||||
initialize: function() {
|
||||
$("[data-js-banner-title]").on({
|
||||
change: function() {
|
||||
$("#js-banner-title").html($(this).val());
|
||||
}
|
||||
});
|
||||
$("[data-js-banner-description]").on({
|
||||
change: function() {
|
||||
$("#js-banner-description").html($(this).val());
|
||||
}
|
||||
});
|
||||
$("[name='banner[background_color]']").on({
|
||||
change: function() {
|
||||
$("#js-banner-background").css("background-color", $(this).val());
|
||||
}
|
||||
});
|
||||
$("[name='banner[font_color]']").on({
|
||||
change: function() {
|
||||
$("#js-banner-title").css("color", $(this).val());
|
||||
$("#js-banner-description").css("color", $(this).val());
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,20 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.Banners =
|
||||
initialize: ->
|
||||
$("[data-js-banner-title]").on
|
||||
change: ->
|
||||
$("#js-banner-title").html($(this).val())
|
||||
|
||||
$("[data-js-banner-description]").on
|
||||
change: ->
|
||||
$("#js-banner-description").html($(this).val())
|
||||
|
||||
$("[name='banner[background_color]']").on
|
||||
change: ->
|
||||
$("#js-banner-background").css("background-color", $(this).val())
|
||||
|
||||
$("[name='banner[font_color]']").on
|
||||
change: ->
|
||||
$("#js-banner-title").css("color", $(this).val())
|
||||
$("#js-banner-description").css("color", $(this).val())
|
||||
41
app/assets/javascripts/budget_edit_associations.js
Normal file
41
app/assets/javascripts/budget_edit_associations.js
Normal file
@@ -0,0 +1,41 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.BudgetEditAssociations = {
|
||||
set_text: function(response) {
|
||||
$(".js-budget-show-administrators-list").text(response.administrators);
|
||||
$(".js-budget-show-valuators-list").text(response.valuators);
|
||||
$(".js-budget-show-trackers-list").text(response.trackers);
|
||||
},
|
||||
initialize: function() {
|
||||
$(".js-budget-list-checkbox-user").on({
|
||||
click: function() {
|
||||
var admin_count, budget, params, tracker_count, url, valuator_count;
|
||||
admin_count = $(".js-budget-list-checkbox-administrators:checkbox:checked").length;
|
||||
valuator_count = $(".js-budget-list-checkbox-valuators:checkbox:checked").length;
|
||||
tracker_count = $(".js-budget-list-checkbox-trackers:checkbox:checked").length;
|
||||
budget = $(".js-budget-id").attr("id");
|
||||
url = "/admin/budgets/" + budget + "/assigned_users_translation.json";
|
||||
params = {
|
||||
administrators: admin_count,
|
||||
valuators: valuator_count,
|
||||
trackers: tracker_count
|
||||
};
|
||||
$.get(url, params, function(response) {
|
||||
App.BudgetEditAssociations.set_text(response, "json");
|
||||
});
|
||||
}
|
||||
});
|
||||
$(".js-budget-show-users-list").on({
|
||||
click: function() {
|
||||
var div_id;
|
||||
div_id = $(this).data().toggle;
|
||||
$(".js-budget-users-list").each(function() {
|
||||
if (this.id !== div_id && !$(this).hasClass("is-hidden")) {
|
||||
$(this).addClass("is-hidden");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,26 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.BudgetEditAssociations =
|
||||
|
||||
set_text: (response)->
|
||||
$(".js-budget-show-administrators-list").text(response["administrators"])
|
||||
$(".js-budget-show-valuators-list").text(response["valuators"])
|
||||
$(".js-budget-show-trackers-list").text(response["trackers"])
|
||||
|
||||
initialize: ->
|
||||
$(".js-budget-list-checkbox-user").on
|
||||
click: ->
|
||||
admin_count = $(".js-budget-list-checkbox-administrators:checkbox:checked").length
|
||||
valuator_count = $(".js-budget-list-checkbox-valuators:checkbox:checked").length
|
||||
tracker_count = $(".js-budget-list-checkbox-trackers:checkbox:checked").length
|
||||
budget = $(".js-budget-id").attr("id")
|
||||
url = "/admin/budgets/" + budget + "/assigned_users_translation.json"
|
||||
params = {administrators: admin_count, valuators: valuator_count, trackers: tracker_count}
|
||||
$.get(url, params, (response) -> App.BudgetEditAssociations.set_text response, "json")
|
||||
|
||||
$(".js-budget-show-users-list").on
|
||||
click: ->
|
||||
div_id = $(this).data().toggle
|
||||
$(".js-budget-users-list").each ->
|
||||
if this.id != div_id && !$(this).hasClass("is-hidden")
|
||||
$(this).addClass("is-hidden")
|
||||
17
app/assets/javascripts/check_all_none.js
Normal file
17
app/assets/javascripts/check_all_none.js
Normal file
@@ -0,0 +1,17 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.CheckAllNone = {
|
||||
initialize: function() {
|
||||
$("[data-check-all]").on("click", function() {
|
||||
var target_name;
|
||||
target_name = $(this).data("check-all");
|
||||
$("[name='" + target_name + "']").prop("checked", true);
|
||||
});
|
||||
$("[data-check-none]").on("click", function() {
|
||||
var target_name;
|
||||
target_name = $(this).data("check-none");
|
||||
$("[name='" + target_name + "']").prop("checked", false);
|
||||
});
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,12 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.CheckAllNone =
|
||||
|
||||
initialize: ->
|
||||
$("[data-check-all]").on "click", ->
|
||||
target_name = $(this).data("check-all")
|
||||
$("[name='#{target_name}']").prop("checked", true)
|
||||
|
||||
$("[data-check-none]").on "click", ->
|
||||
target_name = $(this).data("check-none")
|
||||
$("[name='#{target_name}']").prop("checked", false)
|
||||
17
app/assets/javascripts/checkbox_toggle.js
Normal file
17
app/assets/javascripts/checkbox_toggle.js
Normal file
@@ -0,0 +1,17 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.CheckboxToggle = {
|
||||
initialize: function() {
|
||||
$("[data-checkbox-toggle]").on("change", function() {
|
||||
var $target;
|
||||
$target = $($(this).data("checkbox-toggle"));
|
||||
|
||||
if ($(this).is(":checked")) {
|
||||
$target.show();
|
||||
} else {
|
||||
$target.hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,11 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.CheckboxToggle =
|
||||
|
||||
initialize: ->
|
||||
$("[data-checkbox-toggle]").on "change", ->
|
||||
$target = $($(this).data("checkbox-toggle"))
|
||||
if $(this).is(":checked")
|
||||
$target.show()
|
||||
else
|
||||
$target.hide()
|
||||
87
app/assets/javascripts/columns_selector.js
Normal file
87
app/assets/javascripts/columns_selector.js
Normal file
@@ -0,0 +1,87 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.ColumnsSelector = {
|
||||
initColums: function() {
|
||||
var c_value, columns;
|
||||
App.ColumnsSelector.hideAll();
|
||||
c_value = App.ColumnsSelector.currentValue();
|
||||
if (c_value.length === 0) {
|
||||
c_value = $("#js-columns-selector").data("default");
|
||||
App.Cookies.saveCookie($("#js-columns-selector").data("cookie"), c_value, 30);
|
||||
}
|
||||
columns = c_value.split(",");
|
||||
columns.forEach(function(column) {
|
||||
$("[data-field=" + column + "]").removeClass("hidden");
|
||||
$("#column_selector_" + column).prop("checked", true);
|
||||
});
|
||||
},
|
||||
initChecks: function() {
|
||||
$(".column-selecteable th[data-field]").each(function() {
|
||||
var field, input, item, label, text;
|
||||
field = $(this).data("field");
|
||||
text = $(this).text().trim();
|
||||
item = $("#column_selector_item_template").clone();
|
||||
item.prop("id", "column_selector_item_" + field);
|
||||
input = item.find("input");
|
||||
input.prop("name", "column-selector[" + field + "]");
|
||||
input.prop("id", "column_selector_" + field);
|
||||
input.data("column", field);
|
||||
label = item.find("label");
|
||||
label.prop("for", "column_selector_" + field);
|
||||
label.text(text);
|
||||
item.removeClass("hidden");
|
||||
$("#js-columns-selector-wrapper").append(item);
|
||||
});
|
||||
},
|
||||
toggleOptions: function(event) {
|
||||
event.preventDefault();
|
||||
$("#js-columns-selector").toggleClass("hollow");
|
||||
$("#js-columns-selector-wrapper").toggleClass("hidden");
|
||||
},
|
||||
hideAll: function() {
|
||||
$("[data-field]").addClass("hidden");
|
||||
$(".column-selector-item input").prop("checked", false);
|
||||
},
|
||||
toggleColumn: function(event) {
|
||||
App.ColumnsSelector.displayColumn($(event.target).data("column"));
|
||||
},
|
||||
displayColumn: function(column) {
|
||||
var value;
|
||||
if ($("#column_selector_" + column).prop("checked")) {
|
||||
$("[data-field=" + column + "]").removeClass("hidden");
|
||||
} else {
|
||||
$("[data-field=" + column + "]").addClass("hidden");
|
||||
}
|
||||
value = App.ColumnsSelector.updateItem(column);
|
||||
App.Cookies.saveCookie($("#js-columns-selector").data("cookie"), value, 30);
|
||||
},
|
||||
updateItem: function(value) {
|
||||
var index, values;
|
||||
values = App.ColumnsSelector.currentValue().split(",");
|
||||
index = values.indexOf(value);
|
||||
if (index >= 0) {
|
||||
values.splice(index, 1);
|
||||
} else {
|
||||
values.push(value);
|
||||
}
|
||||
return values.join(",");
|
||||
},
|
||||
currentValue: function() {
|
||||
return App.Cookies.getCookie($("#js-columns-selector").data("cookie"));
|
||||
},
|
||||
initialize: function() {
|
||||
App.ColumnsSelector.initChecks();
|
||||
App.ColumnsSelector.initColums();
|
||||
$("#js-columns-selector").on({
|
||||
click: function(event) {
|
||||
App.ColumnsSelector.toggleOptions(event);
|
||||
}
|
||||
});
|
||||
$(".column-selector-item input").on({
|
||||
click: function(event) {
|
||||
App.ColumnsSelector.toggleColumn(event);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,78 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.ColumnsSelector =
|
||||
|
||||
initColums: () ->
|
||||
App.ColumnsSelector.hideAll()
|
||||
c_value = App.ColumnsSelector.currentValue()
|
||||
|
||||
if c_value.length == 0
|
||||
c_value = $("#js-columns-selector").data("default")
|
||||
App.Cookies.saveCookie($("#js-columns-selector").data("cookie"), c_value, 30)
|
||||
columns = c_value.split(",")
|
||||
|
||||
columns.forEach (column) ->
|
||||
$("[data-field=" + column + "]").removeClass("hidden")
|
||||
$("#column_selector_" + column).prop("checked", true)
|
||||
|
||||
initChecks: () ->
|
||||
$(".column-selecteable th[data-field]").each ->
|
||||
field = $(this).data("field")
|
||||
text = $(this).text().trim()
|
||||
item = $("#column_selector_item_template").clone()
|
||||
item.prop("id", "column_selector_item_" + field)
|
||||
input = item.find("input")
|
||||
input.prop("name", "column-selector[" + field + "]")
|
||||
input.prop("id", "column_selector_" + field)
|
||||
input.data("column", field)
|
||||
label = item.find("label")
|
||||
label.prop("for", "column_selector_" + field)
|
||||
label.text(text)
|
||||
item.removeClass("hidden")
|
||||
$("#js-columns-selector-wrapper").append(item)
|
||||
|
||||
toggleOptions: (event) ->
|
||||
event.preventDefault()
|
||||
$("#js-columns-selector").toggleClass("hollow")
|
||||
$("#js-columns-selector-wrapper").toggleClass("hidden")
|
||||
|
||||
hideAll: () ->
|
||||
$("[data-field]").addClass("hidden")
|
||||
$(".column-selector-item input").prop("checked", false)
|
||||
|
||||
toggleColumn: (event) ->
|
||||
App.ColumnsSelector.displayColumn($(event.target).data("column"))
|
||||
|
||||
displayColumn: (column) ->
|
||||
if $("#column_selector_" + column).prop("checked")
|
||||
$("[data-field=" + column + "]").removeClass("hidden")
|
||||
else
|
||||
$("[data-field=" + column + "]").addClass("hidden")
|
||||
|
||||
value = App.ColumnsSelector.updateItem(column)
|
||||
App.Cookies.saveCookie($("#js-columns-selector").data("cookie"), value, 30)
|
||||
|
||||
updateItem: (value) ->
|
||||
values = App.ColumnsSelector.currentValue().split(",")
|
||||
index = values.indexOf(value)
|
||||
if index >= 0
|
||||
values.splice index, 1
|
||||
else
|
||||
values.push value
|
||||
|
||||
values.join ","
|
||||
|
||||
currentValue: () ->
|
||||
App.Cookies.getCookie($("#js-columns-selector").data("cookie"))
|
||||
|
||||
initialize: ->
|
||||
App.ColumnsSelector.initChecks()
|
||||
App.ColumnsSelector.initColums()
|
||||
|
||||
$("#js-columns-selector").on
|
||||
click: (event) ->
|
||||
App.ColumnsSelector.toggleOptions(event)
|
||||
|
||||
$(".column-selector-item input").on
|
||||
click: (event) ->
|
||||
App.ColumnsSelector.toggleColumn(event)
|
||||
72
app/assets/javascripts/comments.js
Normal file
72
app/assets/javascripts/comments.js
Normal file
@@ -0,0 +1,72 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.Comments = {
|
||||
add_comment: function(parent_id, response_html) {
|
||||
$(response_html).insertAfter($("#js-comment-form-" + parent_id));
|
||||
this.update_comments_count();
|
||||
},
|
||||
add_reply: function(parent_id, response_html) {
|
||||
if ($("#" + parent_id + " .comment-children").length === 0) {
|
||||
$("#" + parent_id).append("<li><ul id='" + parent_id + "_children' class='no-bullet comment-children'></ul></li>");
|
||||
}
|
||||
$("#" + parent_id + " .comment-children:first").prepend($(response_html));
|
||||
this.update_comments_count();
|
||||
},
|
||||
update_comments_count: function() {
|
||||
$(".js-comments-count").each(function() {
|
||||
var new_val;
|
||||
new_val = $(this).text().trim().replace(/\d+/, function(match) {
|
||||
return parseInt(match, 10) + 1;
|
||||
});
|
||||
$(this).text(new_val);
|
||||
});
|
||||
},
|
||||
display_error: function(field_with_errors, error_html) {
|
||||
$(error_html).insertAfter($("" + field_with_errors));
|
||||
},
|
||||
reset_and_hide_form: function(id) {
|
||||
var form_container, input;
|
||||
form_container = $("#js-comment-form-" + id);
|
||||
input = form_container.find("form textarea");
|
||||
input.val("");
|
||||
form_container.hide();
|
||||
},
|
||||
reset_form: function(id) {
|
||||
var input;
|
||||
input = $("#js-comment-form-" + id + " form textarea");
|
||||
input.val("");
|
||||
},
|
||||
toggle_form: function(id) {
|
||||
$("#js-comment-form-" + id).toggle();
|
||||
},
|
||||
toggle_arrow: function(id) {
|
||||
var arrow;
|
||||
arrow = "span#" + id + "_arrow";
|
||||
if ($(arrow).hasClass("icon-arrow-right")) {
|
||||
$(arrow).removeClass("icon-arrow-right").addClass("icon-arrow-down");
|
||||
} else {
|
||||
$(arrow).removeClass("icon-arrow-down").addClass("icon-arrow-right");
|
||||
}
|
||||
},
|
||||
initialize: function() {
|
||||
$("body .js-add-comment-link").each(function() {
|
||||
if ($(this).data("initialized") !== "yes") {
|
||||
$(this).on("click", function() {
|
||||
App.Comments.toggle_form($(this).data().id);
|
||||
return false;
|
||||
}).data("initialized", "yes");
|
||||
}
|
||||
});
|
||||
$("body .js-toggle-children").each(function() {
|
||||
$(this).on("click", function() {
|
||||
var children_container_id;
|
||||
children_container_id = ($(this).data().id) + "_children";
|
||||
$("#" + children_container_id).toggle("slow");
|
||||
App.Comments.toggle_arrow(children_container_id);
|
||||
$(this).children(".js-child-toggle").toggle();
|
||||
return false;
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,58 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.Comments =
|
||||
|
||||
add_comment: (parent_id, response_html) ->
|
||||
$(response_html).insertAfter($("#js-comment-form-#{parent_id}"))
|
||||
this.update_comments_count()
|
||||
|
||||
add_reply: (parent_id, response_html) ->
|
||||
if $("##{parent_id} .comment-children").length == 0
|
||||
$("##{parent_id}").append("<li><ul id='#{parent_id}_children' class='no-bullet comment-children'></ul></li>")
|
||||
$("##{parent_id} .comment-children:first").prepend($(response_html))
|
||||
this.update_comments_count()
|
||||
|
||||
update_comments_count: ->
|
||||
$(".js-comments-count").each ->
|
||||
new_val = $(this).text().trim().replace /\d+/, (match) -> parseInt(match, 10) + 1
|
||||
$(this).text(new_val)
|
||||
|
||||
display_error: (field_with_errors, error_html) ->
|
||||
$(error_html).insertAfter($("#{field_with_errors}"))
|
||||
|
||||
reset_and_hide_form: (id) ->
|
||||
form_container = $("#js-comment-form-#{id}")
|
||||
input = form_container.find("form textarea")
|
||||
input.val("")
|
||||
form_container.hide()
|
||||
|
||||
reset_form: (id) ->
|
||||
input = $("#js-comment-form-#{id} form textarea")
|
||||
input.val("")
|
||||
|
||||
toggle_form: (id) ->
|
||||
$("#js-comment-form-#{id}").toggle()
|
||||
|
||||
toggle_arrow: (id) ->
|
||||
arrow = "span##{id}_arrow"
|
||||
if $(arrow).hasClass("icon-arrow-right")
|
||||
$(arrow).removeClass("icon-arrow-right").addClass("icon-arrow-down")
|
||||
else
|
||||
$(arrow).removeClass("icon-arrow-down").addClass("icon-arrow-right")
|
||||
|
||||
initialize: ->
|
||||
$("body .js-add-comment-link").each ->
|
||||
unless $(this).data("initialized") is "yes"
|
||||
$(this).on("click", ->
|
||||
App.Comments.toggle_form($(this).data().id)
|
||||
false
|
||||
).data "initialized", "yes"
|
||||
|
||||
$("body .js-toggle-children").each ->
|
||||
$(this).on("click", ->
|
||||
children_container_id = "#{$(this).data().id}_children"
|
||||
$("##{children_container_id}").toggle("slow")
|
||||
App.Comments.toggle_arrow(children_container_id)
|
||||
$(this).children(".js-child-toggle").toggle()
|
||||
false
|
||||
)
|
||||
32
app/assets/javascripts/cookies.js
Normal file
32
app/assets/javascripts/cookies.js
Normal file
@@ -0,0 +1,32 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.Cookies = {
|
||||
saveCookie: function(name, value, days) {
|
||||
var date, expires;
|
||||
expires = undefined;
|
||||
if (days) {
|
||||
date = new Date;
|
||||
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
|
||||
expires = "; expires=" + date.toGMTString();
|
||||
} else {
|
||||
expires = "";
|
||||
}
|
||||
document.cookie = name + "=" + value + expires + "; path=/";
|
||||
},
|
||||
getCookie: function(name) {
|
||||
var c_end, c_start;
|
||||
if (document.cookie.length > 0) {
|
||||
c_start = document.cookie.indexOf(name + "=");
|
||||
if (c_start !== -1) {
|
||||
c_start = c_start + name.length + 1;
|
||||
c_end = document.cookie.indexOf(";", c_start);
|
||||
if (c_end === -1) {
|
||||
c_end = document.cookie.length;
|
||||
}
|
||||
return unescape(document.cookie.substring(c_start, c_end));
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,25 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.Cookies =
|
||||
|
||||
saveCookie: (name, value, days) ->
|
||||
expires = undefined
|
||||
if days
|
||||
date = new Date
|
||||
date.setTime date.getTime() + days * 24 * 60 * 60 * 1000
|
||||
expires = "; expires=" + date.toGMTString()
|
||||
else
|
||||
expires = ""
|
||||
document.cookie = name + "=" + value + expires + "; path=/"
|
||||
return
|
||||
|
||||
getCookie: (name) ->
|
||||
if document.cookie.length > 0
|
||||
c_start = document.cookie.indexOf(name + "=")
|
||||
if c_start != -1
|
||||
c_start = c_start + name.length + 1
|
||||
c_end = document.cookie.indexOf(";", c_start)
|
||||
if c_end == -1
|
||||
c_end = document.cookie.length
|
||||
return unescape(document.cookie.substring(c_start, c_end))
|
||||
""
|
||||
@@ -1,5 +1,5 @@
|
||||
// Overrides and adds customized javascripts in this file
|
||||
// Read more on documentation:
|
||||
// Read more on documentation:
|
||||
// * English: https://github.com/consul/consul/blob/master/CUSTOMIZE_EN.md#javascript
|
||||
// * Spanish: https://github.com/consul/consul/blob/master/CUSTOMIZE_ES.md#javascript
|
||||
//
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
// TODO: This module is complex enough to require its own tests. Rewrite it using Ecma6 class syntax and
|
||||
// write tests for this feature after consul has been migrated to Rails 5.1
|
||||
(function(){
|
||||
(function() {
|
||||
"use strict";
|
||||
|
||||
var ProposalGraph = function(url) {
|
||||
@@ -33,7 +33,7 @@
|
||||
.done(this.draw.bind(this));
|
||||
};
|
||||
|
||||
ProposalGraph.prototype.refreshGoals = function () {
|
||||
ProposalGraph.prototype.refreshGoals = function() {
|
||||
return $.ajax({
|
||||
url: this.resourcesUrl,
|
||||
cache: false,
|
||||
@@ -52,11 +52,11 @@
|
||||
});
|
||||
};
|
||||
|
||||
ProposalGraph.prototype.refreshData = function () {
|
||||
ProposalGraph.prototype.refreshData = function() {
|
||||
return $.ajax({
|
||||
url: this.url,
|
||||
cache: false,
|
||||
success: function (data) {
|
||||
success: function(data) {
|
||||
this.parseData(data);
|
||||
}.bind(this),
|
||||
data: {
|
||||
@@ -68,8 +68,8 @@
|
||||
ProposalGraph.prototype.parseData = function(data) {
|
||||
var key;
|
||||
|
||||
this.xColumnValues = [ ];
|
||||
this.progressColumnValues = [ this.progressLabel ];
|
||||
this.xColumnValues = [];
|
||||
this.progressColumnValues = [this.progressLabel];
|
||||
|
||||
for (key in data) {
|
||||
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
||||
@@ -87,7 +87,7 @@
|
||||
return $.ajax({
|
||||
url: this.successfulProposalDataUrl,
|
||||
cache: false,
|
||||
success: function (data) {
|
||||
success: function(data) {
|
||||
this.parseSuccessfulProposalData(data);
|
||||
}.bind(this),
|
||||
data: {
|
||||
@@ -99,7 +99,7 @@
|
||||
ProposalGraph.prototype.parseSuccessfulProposalData = function(data) {
|
||||
var key;
|
||||
|
||||
this.successfulColumnValues = [ this.successLabel ];
|
||||
this.successfulColumnValues = [this.successLabel];
|
||||
|
||||
for (key in data) {
|
||||
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
||||
@@ -113,7 +113,7 @@
|
||||
return $.ajax({
|
||||
url: this.proposalAchievementsUrl,
|
||||
cache: false,
|
||||
success: function (data) {
|
||||
success: function(data) {
|
||||
this.parseAchievements(data);
|
||||
}.bind(this),
|
||||
data: {
|
||||
@@ -138,7 +138,7 @@
|
||||
}
|
||||
};
|
||||
|
||||
ProposalGraph.prototype.addXColumnValue = function (value) {
|
||||
ProposalGraph.prototype.addXColumnValue = function(value) {
|
||||
if (this.xColumnValues.indexOf(value) === -1) {
|
||||
this.xColumnValues.push(value);
|
||||
}
|
||||
@@ -146,7 +146,7 @@
|
||||
|
||||
ProposalGraph.prototype.draw = function() {
|
||||
var colors = {},
|
||||
maximumValue = this.maximumValue === 0 ? this.proposalSuccess : Math.round(this.maximumValue * 1.10);
|
||||
maximumValue = this.maximumValue === 0 ? this.proposalSuccess : Math.round(this.maximumValue * 1.10);
|
||||
|
||||
this.formatXColumnValues();
|
||||
|
||||
@@ -163,14 +163,14 @@
|
||||
this.successfulColumnValues
|
||||
],
|
||||
colors: colors,
|
||||
color: function (color, d) {
|
||||
color: function(color, d) {
|
||||
var achievement;
|
||||
|
||||
if (d.id === this.successfulColumnValues[0] || !Object.prototype.hasOwnProperty.call(d, "x")) {
|
||||
return color;
|
||||
}
|
||||
|
||||
achievement = this.achievements.find(function (element) {
|
||||
achievement = this.achievements.find(function(element) {
|
||||
return element.value === this.xColumnValues[d.index + 1];
|
||||
}.bind(this));
|
||||
|
||||
@@ -211,8 +211,8 @@
|
||||
},
|
||||
tooltip: {
|
||||
format: {
|
||||
title: function (d) {
|
||||
var achievement = this.achievements.find(function (element) {
|
||||
title: function(d) {
|
||||
var achievement = this.achievements.find(function(element) {
|
||||
return element.value === this.xColumnValues[d + 1];
|
||||
}.bind(this));
|
||||
|
||||
@@ -227,11 +227,11 @@
|
||||
});
|
||||
};
|
||||
|
||||
ProposalGraph.prototype.tickYValues = function () {
|
||||
ProposalGraph.prototype.tickYValues = function() {
|
||||
var i,
|
||||
tick = [0],
|
||||
maximumValue = this.maximumValue === 0 ? this.proposalSuccess : Math.round(this.maximumValue * 1.10),
|
||||
step = maximumValue <= 10 ? 1 : Math.round(maximumValue / 10);
|
||||
tick = [0],
|
||||
maximumValue = this.maximumValue === 0 ? this.proposalSuccess : Math.round(this.maximumValue * 1.10),
|
||||
step = maximumValue <= 10 ? 1 : Math.round(maximumValue / 10);
|
||||
|
||||
for (i = step; i < maximumValue; i += step) {
|
||||
tick.push(i);
|
||||
@@ -242,16 +242,16 @@
|
||||
return tick;
|
||||
};
|
||||
|
||||
ProposalGraph.prototype.tickXValues = function () {
|
||||
ProposalGraph.prototype.tickXValues = function() {
|
||||
var i,
|
||||
l,
|
||||
tick = [],
|
||||
step = this.xColumnValues.length < 13 ? 1 : Math.round((this.xColumnValues.length - 1) / 12);
|
||||
l,
|
||||
tick = [],
|
||||
step = this.xColumnValues.length < 13 ? 1 : Math.round((this.xColumnValues.length - 1) / 12);
|
||||
|
||||
if (this.xColumnValues.length > 1) {
|
||||
tick.push(0);
|
||||
|
||||
for(i = step, l = this.xColumnValues.length - 1; i < l; i += step) {
|
||||
for (i = step, l = this.xColumnValues.length - 1; i < l; i += step) {
|
||||
tick.push(i);
|
||||
}
|
||||
}
|
||||
@@ -259,7 +259,7 @@
|
||||
return tick;
|
||||
};
|
||||
|
||||
ProposalGraph.prototype.formatXColumnValues = function () {
|
||||
ProposalGraph.prototype.formatXColumnValues = function() {
|
||||
var i, l;
|
||||
|
||||
this.xColumnValues = this.xColumnValues.sort();
|
||||
@@ -286,8 +286,8 @@
|
||||
return this.groupBy === undefined || this.groupBy === "" || this.groupBy === null;
|
||||
};
|
||||
|
||||
$(document).ready(function () {
|
||||
$("[data-proposal-graph-url]").each(function () {
|
||||
$(document).ready(function() {
|
||||
$("[data-proposal-graph-url]").each(function() {
|
||||
var graph = new ProposalGraph($(this).data("proposal-graph-url"));
|
||||
graph.successfulProposalDataUrl = $(this).data("successful-proposal-graph-url");
|
||||
graph.proposalAchievementsUrl = $(this).data("proposal-achievements-url");
|
||||
|
||||
169
app/assets/javascripts/documentable.js
Normal file
169
app/assets/javascripts/documentable.js
Normal file
@@ -0,0 +1,169 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.Documentable = {
|
||||
initialize: function() {
|
||||
$(".js-document-attachment").each(function() {
|
||||
App.Documentable.initializeDirectUploadInput(this);
|
||||
});
|
||||
$("#nested-documents").on("cocoon:after-remove", function() {
|
||||
App.Documentable.unlockUploads();
|
||||
});
|
||||
$("#nested-documents").on("cocoon:after-insert", function(e, nested_document) {
|
||||
var input;
|
||||
input = $(nested_document).find(".js-document-attachment");
|
||||
input.lockUpload = $(nested_document).closest("#nested-documents").find(".document:visible").length >= $("#nested-documents").data("max-documents-allowed");
|
||||
App.Documentable.initializeDirectUploadInput(input);
|
||||
if (input.lockUpload) {
|
||||
App.Documentable.lockUploads();
|
||||
}
|
||||
});
|
||||
},
|
||||
initializeDirectUploadInput: function(input) {
|
||||
var inputData;
|
||||
inputData = this.buildData([], input);
|
||||
this.initializeRemoveCachedDocumentLink(input, inputData);
|
||||
$(input).fileupload({
|
||||
paramName: "attachment",
|
||||
formData: null,
|
||||
add: function(e, data) {
|
||||
var upload_data;
|
||||
upload_data = App.Documentable.buildData(data, e.target);
|
||||
App.Documentable.clearProgressBar(upload_data);
|
||||
App.Documentable.setProgressBar(upload_data, "uploading");
|
||||
upload_data.submit();
|
||||
},
|
||||
change: function(e, data) {
|
||||
data.files.forEach(function(file) {
|
||||
App.Documentable.setFilename(inputData, file.name);
|
||||
});
|
||||
},
|
||||
fail: function(e, data) {
|
||||
$(data.cachedAttachmentField).val("");
|
||||
App.Documentable.clearFilename(data);
|
||||
App.Documentable.setProgressBar(data, "errors");
|
||||
App.Documentable.clearInputErrors(data);
|
||||
App.Documentable.setInputErrors(data);
|
||||
$(data.destroyAttachmentLinkContainer).find("a.delete:not(.remove-nested)").remove();
|
||||
$(data.addAttachmentLabel).addClass("error");
|
||||
$(data.addAttachmentLabel).show();
|
||||
},
|
||||
done: function(e, data) {
|
||||
var destroyAttachmentLink;
|
||||
$(data.cachedAttachmentField).val(data.result.cached_attachment);
|
||||
App.Documentable.setTitleFromFile(data, data.result.filename);
|
||||
App.Documentable.setProgressBar(data, "complete");
|
||||
App.Documentable.setFilename(data, data.result.filename);
|
||||
App.Documentable.clearInputErrors(data);
|
||||
$(data.addAttachmentLabel).hide();
|
||||
$(data.wrapper).find(".attachment-actions").removeClass("small-12").addClass("small-6 float-right");
|
||||
$(data.wrapper).find(".attachment-actions .action-remove").removeClass("small-3").addClass("small-12");
|
||||
destroyAttachmentLink = $(data.result.destroy_link);
|
||||
$(data.destroyAttachmentLinkContainer).html(destroyAttachmentLink);
|
||||
$(destroyAttachmentLink).on("click", function(event) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
App.Documentable.doDeleteCachedAttachmentRequest(this.href, data);
|
||||
});
|
||||
if (input.lockUpload) {
|
||||
App.Documentable.showNotice();
|
||||
}
|
||||
},
|
||||
progress: function(e, data) {
|
||||
var progress;
|
||||
progress = parseInt(data.loaded / data.total * 100, 10);
|
||||
$(data.progressBar).find(".loading-bar").css("width", progress + "%");
|
||||
}
|
||||
});
|
||||
},
|
||||
buildData: function(data, input) {
|
||||
var wrapper;
|
||||
wrapper = $(input).closest(".direct-upload");
|
||||
data.input = input;
|
||||
data.wrapper = wrapper;
|
||||
data.progressBar = $(wrapper).find(".progress-bar-placeholder");
|
||||
data.errorContainer = $(wrapper).find(".attachment-errors");
|
||||
data.fileNameContainer = $(wrapper).find("p.file-name");
|
||||
data.destroyAttachmentLinkContainer = $(wrapper).find(".action-remove");
|
||||
data.addAttachmentLabel = $(wrapper).find(".action-add label");
|
||||
data.cachedAttachmentField = $(wrapper).find("input[name$='[cached_attachment]']");
|
||||
data.titleField = $(wrapper).find("input[name$='[title]']");
|
||||
$(wrapper).find(".progress-bar-placeholder").css("display", "block");
|
||||
return data;
|
||||
},
|
||||
clearFilename: function(data) {
|
||||
$(data.fileNameContainer).text("");
|
||||
$(data.fileNameContainer).hide();
|
||||
},
|
||||
clearInputErrors: function(data) {
|
||||
$(data.errorContainer).find("small.error").remove();
|
||||
},
|
||||
clearProgressBar: function(data) {
|
||||
$(data.progressBar).find(".loading-bar").removeClass("complete errors uploading").css("width", "0px");
|
||||
},
|
||||
setFilename: function(data, file_name) {
|
||||
$(data.fileNameContainer).text(file_name);
|
||||
$(data.fileNameContainer).show();
|
||||
},
|
||||
setProgressBar: function(data, klass) {
|
||||
$(data.progressBar).find(".loading-bar").addClass(klass);
|
||||
},
|
||||
setTitleFromFile: function(data, title) {
|
||||
if ($(data.titleField).val() === "") {
|
||||
$(data.titleField).val(title);
|
||||
}
|
||||
},
|
||||
setInputErrors: function(data) {
|
||||
var errors;
|
||||
errors = "<small class='error'>" + data.jqXHR.responseJSON.errors + "</small>";
|
||||
$(data.errorContainer).append(errors);
|
||||
},
|
||||
lockUploads: function() {
|
||||
$("#new_document_link").addClass("hide");
|
||||
},
|
||||
unlockUploads: function() {
|
||||
$("#max-documents-notice").addClass("hide");
|
||||
$("#new_document_link").removeClass("hide");
|
||||
},
|
||||
showNotice: function() {
|
||||
$("#max-documents-notice").removeClass("hide");
|
||||
},
|
||||
doDeleteCachedAttachmentRequest: function(url, data) {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: url,
|
||||
dataType: "json",
|
||||
data: {
|
||||
"_method": "delete"
|
||||
},
|
||||
complete: function() {
|
||||
$(data.cachedAttachmentField).val("");
|
||||
$(data.addAttachmentLabel).show();
|
||||
App.Documentable.clearFilename(data);
|
||||
App.Documentable.clearInputErrors(data);
|
||||
App.Documentable.clearProgressBar(data);
|
||||
App.Documentable.unlockUploads();
|
||||
$(data.wrapper).find(".attachment-actions").addClass("small-12").removeClass("small-6 float-right");
|
||||
$(data.wrapper).find(".attachment-actions .action-remove").addClass("small-3").removeClass("small-12");
|
||||
if ($(data.input).data("nested-document") === true) {
|
||||
$(data.wrapper).remove();
|
||||
} else {
|
||||
$(data.wrapper).find("a.remove-cached-attachment").remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
initializeRemoveCachedDocumentLink: function(input, data) {
|
||||
var remove_document_link, wrapper;
|
||||
wrapper = $(input).closest(".direct-upload");
|
||||
remove_document_link = $(wrapper).find("a.remove-cached-attachment");
|
||||
$(remove_document_link).on("click", function(e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
App.Documentable.doDeleteCachedAttachmentRequest(this.href, data);
|
||||
});
|
||||
},
|
||||
removeDocument: function(id) {
|
||||
$("#" + id).remove();
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,156 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.Documentable =
|
||||
|
||||
initialize: ->
|
||||
$(".js-document-attachment").each ->
|
||||
App.Documentable.initializeDirectUploadInput(this)
|
||||
|
||||
$("#nested-documents").on "cocoon:after-remove", ->
|
||||
App.Documentable.unlockUploads()
|
||||
|
||||
$("#nested-documents").on "cocoon:after-insert", (e, nested_document) ->
|
||||
input = $(nested_document).find(".js-document-attachment")
|
||||
input["lockUpload"] = $(nested_document).closest("#nested-documents").find(".document:visible").length >= $("#nested-documents").data("max-documents-allowed")
|
||||
App.Documentable.initializeDirectUploadInput(input)
|
||||
App.Documentable.lockUploads() if input["lockUpload"]
|
||||
|
||||
initializeDirectUploadInput: (input) ->
|
||||
|
||||
inputData = this.buildData([], input)
|
||||
|
||||
this.initializeRemoveCachedDocumentLink(input, inputData)
|
||||
|
||||
$(input).fileupload
|
||||
|
||||
paramName: "attachment"
|
||||
|
||||
formData: null
|
||||
|
||||
add: (e, data) ->
|
||||
upload_data = App.Documentable.buildData(data, e.target)
|
||||
App.Documentable.clearProgressBar(upload_data)
|
||||
App.Documentable.setProgressBar(upload_data, "uploading")
|
||||
upload_data.submit()
|
||||
|
||||
change: (e, data) ->
|
||||
data.files.forEach (file) ->
|
||||
App.Documentable.setFilename(inputData, file.name)
|
||||
|
||||
fail: (e, data) ->
|
||||
$(data.cachedAttachmentField).val("")
|
||||
App.Documentable.clearFilename(data)
|
||||
App.Documentable.setProgressBar(data, "errors")
|
||||
App.Documentable.clearInputErrors(data)
|
||||
App.Documentable.setInputErrors(data)
|
||||
$(data.destroyAttachmentLinkContainer).find("a.delete:not(.remove-nested)").remove()
|
||||
$(data.addAttachmentLabel).addClass("error")
|
||||
$(data.addAttachmentLabel).show()
|
||||
|
||||
done: (e, data) ->
|
||||
$(data.cachedAttachmentField).val(data.result.cached_attachment)
|
||||
App.Documentable.setTitleFromFile(data, data.result.filename)
|
||||
App.Documentable.setProgressBar(data, "complete")
|
||||
App.Documentable.setFilename(data, data.result.filename)
|
||||
App.Documentable.clearInputErrors(data)
|
||||
$(data.addAttachmentLabel).hide()
|
||||
$(data.wrapper).find(".attachment-actions").removeClass("small-12").addClass("small-6 float-right")
|
||||
$(data.wrapper).find(".attachment-actions .action-remove").removeClass("small-3").addClass("small-12")
|
||||
|
||||
destroyAttachmentLink = $(data.result.destroy_link)
|
||||
$(data.destroyAttachmentLinkContainer).html(destroyAttachmentLink)
|
||||
$(destroyAttachmentLink).on "click", (e) ->
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
App.Documentable.doDeleteCachedAttachmentRequest(this.href, data)
|
||||
|
||||
App.Documentable.showNotice() if input["lockUpload"]
|
||||
|
||||
|
||||
progress: (e, data) ->
|
||||
progress = parseInt(data.loaded / data.total * 100, 10)
|
||||
$(data.progressBar).find(".loading-bar").css "width", "#{progress}%"
|
||||
return
|
||||
|
||||
buildData: (data, input) ->
|
||||
wrapper = $(input).closest(".direct-upload")
|
||||
data.input = input
|
||||
data.wrapper = wrapper
|
||||
data.progressBar = $(wrapper).find(".progress-bar-placeholder")
|
||||
data.errorContainer = $(wrapper).find(".attachment-errors")
|
||||
data.fileNameContainer = $(wrapper).find("p.file-name")
|
||||
data.destroyAttachmentLinkContainer = $(wrapper).find(".action-remove")
|
||||
data.addAttachmentLabel = $(wrapper).find(".action-add label")
|
||||
data.cachedAttachmentField = $(wrapper).find("input[name$='[cached_attachment]']")
|
||||
data.titleField = $(wrapper).find("input[name$='[title]']")
|
||||
$(wrapper).find(".progress-bar-placeholder").css("display", "block")
|
||||
return data
|
||||
|
||||
clearFilename: (data) ->
|
||||
$(data.fileNameContainer).text("")
|
||||
$(data.fileNameContainer).hide()
|
||||
|
||||
clearInputErrors: (data) ->
|
||||
$(data.errorContainer).find("small.error").remove()
|
||||
|
||||
clearProgressBar: (data) ->
|
||||
$(data.progressBar).find(".loading-bar").removeClass("complete errors uploading").css("width", "0px")
|
||||
|
||||
setFilename: (data, file_name) ->
|
||||
$(data.fileNameContainer).text(file_name)
|
||||
$(data.fileNameContainer).show()
|
||||
|
||||
setProgressBar: (data, klass) ->
|
||||
$(data.progressBar).find(".loading-bar").addClass(klass)
|
||||
|
||||
setTitleFromFile: (data, title) ->
|
||||
if $(data.titleField).val() == ""
|
||||
$(data.titleField).val(title)
|
||||
|
||||
setInputErrors: (data) ->
|
||||
errors = "<small class='error'>#{data.jqXHR.responseJSON.errors}</small>"
|
||||
$(data.errorContainer).append(errors)
|
||||
|
||||
lockUploads: ->
|
||||
$("#new_document_link").addClass("hide")
|
||||
|
||||
unlockUploads: ->
|
||||
$("#max-documents-notice").addClass("hide")
|
||||
$("#new_document_link").removeClass("hide")
|
||||
|
||||
showNotice: ->
|
||||
$("#max-documents-notice").removeClass("hide")
|
||||
|
||||
doDeleteCachedAttachmentRequest: (url, data) ->
|
||||
$.ajax
|
||||
type: "POST"
|
||||
url: url
|
||||
dataType: "json"
|
||||
data: { "_method": "delete" }
|
||||
complete: ->
|
||||
$(data.cachedAttachmentField).val("")
|
||||
$(data.addAttachmentLabel).show()
|
||||
|
||||
App.Documentable.clearFilename(data)
|
||||
App.Documentable.clearInputErrors(data)
|
||||
App.Documentable.clearProgressBar(data)
|
||||
|
||||
App.Documentable.unlockUploads()
|
||||
$(data.wrapper).find(".attachment-actions").addClass("small-12").removeClass("small-6 float-right")
|
||||
$(data.wrapper).find(".attachment-actions .action-remove").addClass("small-3").removeClass("small-12")
|
||||
|
||||
if $(data.input).data("nested-document") == true
|
||||
$(data.wrapper).remove()
|
||||
else
|
||||
$(data.wrapper).find("a.remove-cached-attachment").remove()
|
||||
|
||||
initializeRemoveCachedDocumentLink: (input, data) ->
|
||||
wrapper = $(input).closest(".direct-upload")
|
||||
remove_document_link = $(wrapper).find("a.remove-cached-attachment")
|
||||
$(remove_document_link).on "click", (e) ->
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
App.Documentable.doDeleteCachedAttachmentRequest(this.href, data)
|
||||
|
||||
removeDocument: (id) ->
|
||||
$("##{id}").remove()
|
||||
12
app/assets/javascripts/embed_video.js
Normal file
12
app/assets/javascripts/embed_video.js
Normal file
@@ -0,0 +1,12 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.EmbedVideo = {
|
||||
initialize: function() {
|
||||
$("#js-embedded-video").each(function() {
|
||||
var code;
|
||||
code = $(this).data("video-code");
|
||||
$("#js-embedded-video").html(code);
|
||||
});
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,8 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.EmbedVideo =
|
||||
|
||||
initialize: ->
|
||||
$("#js-embedded-video").each ->
|
||||
code = $(this).data("video-code")
|
||||
$("#js-embedded-video").html(code)
|
||||
21
app/assets/javascripts/fixed_bar.js
Normal file
21
app/assets/javascripts/fixed_bar.js
Normal file
@@ -0,0 +1,21 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.FixedBar = {
|
||||
initialize: function() {
|
||||
$("[data-fixed-bar]").each(function() {
|
||||
var $this, fixedBarTopPosition;
|
||||
$this = $(this);
|
||||
fixedBarTopPosition = $this.offset().top;
|
||||
$(window).on("scroll", function() {
|
||||
if ($(window).scrollTop() > fixedBarTopPosition) {
|
||||
$this.addClass("is-fixed");
|
||||
$("#check-ballot").css({ "display": "inline-block" });
|
||||
} else {
|
||||
$this.removeClass("is-fixed");
|
||||
$("#check-ballot").hide();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,15 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.FixedBar =
|
||||
initialize: ->
|
||||
$("[data-fixed-bar]").each ->
|
||||
$this = $(this)
|
||||
fixedBarTopPosition = $this.offset().top
|
||||
|
||||
$(window).on "scroll", ->
|
||||
if $(window).scrollTop() > fixedBarTopPosition
|
||||
$this.addClass("is-fixed")
|
||||
$("#check-ballot").css({ "display": "inline-block" })
|
||||
else
|
||||
$this.removeClass("is-fixed")
|
||||
$("#check-ballot").hide()
|
||||
8
app/assets/javascripts/flaggable.js
Normal file
8
app/assets/javascripts/flaggable.js
Normal file
@@ -0,0 +1,8 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.Flaggable = {
|
||||
update: function(resource_id, button) {
|
||||
$("#" + resource_id + " .js-flag-actions").html(button).foundation();
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,6 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.Flaggable =
|
||||
|
||||
update: (resource_id, button) ->
|
||||
$("##{resource_id} .js-flag-actions").html(button).foundation()
|
||||
13
app/assets/javascripts/followable.js
Normal file
13
app/assets/javascripts/followable.js
Normal file
@@ -0,0 +1,13 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.Followable = {
|
||||
update: function(followable_id, button, notice) {
|
||||
$("#" + followable_id + " .js-follow").html(button);
|
||||
if ($("[data-alert]").length > 0) {
|
||||
$("[data-alert]").replaceWith(notice);
|
||||
} else {
|
||||
$("body").append(notice);
|
||||
}
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,10 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.Followable =
|
||||
|
||||
update: (followable_id, button, notice) ->
|
||||
$("##{followable_id} .js-follow").html(button)
|
||||
if ($("[data-alert]").length > 0)
|
||||
$("[data-alert]").replaceWith(notice)
|
||||
else
|
||||
$("body").append(notice)
|
||||
67
app/assets/javascripts/forms.js
Normal file
67
app/assets/javascripts/forms.js
Normal file
@@ -0,0 +1,67 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.Forms = {
|
||||
disableEnter: function() {
|
||||
$("form.js-enter-disabled").on("keyup keypress", function(event) {
|
||||
if (event.which === 13) {
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
},
|
||||
submitOnChange: function() {
|
||||
$(".js-submit-on-change").unbind("change").on("change", function() {
|
||||
$(this).closest("form").submit();
|
||||
return false;
|
||||
});
|
||||
},
|
||||
toggleLink: function() {
|
||||
$(".js-toggle-link").unbind("click").on("click", function() {
|
||||
var toggle_txt;
|
||||
$($(this).data("toggle-selector")).toggle("down");
|
||||
if ($(this).data("toggle-text") !== undefined) {
|
||||
toggle_txt = $(this).text();
|
||||
$(this).text($(this).data("toggle-text"));
|
||||
$(this).data("toggle-text", toggle_txt);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
},
|
||||
synchronizeInputs: function() {
|
||||
var banners, inputs, processes, progress_bar;
|
||||
progress_bar = "[name='progress_bar[percentage]']";
|
||||
processes = "[name='legislation_process[background_color]'], [name='legislation_process[font_color]']";
|
||||
banners = "[name='banner[background_color]'], [name='banner[font_color]']";
|
||||
inputs = $(progress_bar + ", " + processes + ", " + banners);
|
||||
inputs.on({
|
||||
input: function() {
|
||||
$("[name='" + this.name + "']").val($(this).val());
|
||||
}
|
||||
});
|
||||
inputs.trigger("input");
|
||||
},
|
||||
hideOrShowFieldsAfterSelection: function() {
|
||||
$("[name='progress_bar[kind]']").on({
|
||||
change: function() {
|
||||
var locale, title_field;
|
||||
locale = App.Globalize.selected_language();
|
||||
title_field = $(".translatable-fields[data-locale=" + locale + "]");
|
||||
if (this.value === "primary") {
|
||||
title_field.hide();
|
||||
$(".globalize-languages").hide();
|
||||
} else {
|
||||
title_field.show();
|
||||
$(".globalize-languages").show();
|
||||
}
|
||||
}
|
||||
});
|
||||
$("[name='progress_bar[kind]']").change();
|
||||
},
|
||||
initialize: function() {
|
||||
App.Forms.disableEnter();
|
||||
App.Forms.submitOnChange();
|
||||
App.Forms.toggleLink();
|
||||
App.Forms.synchronizeInputs();
|
||||
App.Forms.hideOrShowFieldsAfterSelection();
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,60 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.Forms =
|
||||
|
||||
disableEnter: ->
|
||||
$("form.js-enter-disabled").on("keyup keypress", (event) ->
|
||||
if event.which == 13
|
||||
event.preventDefault()
|
||||
)
|
||||
|
||||
submitOnChange: ->
|
||||
$(".js-submit-on-change").unbind("change").on("change", ->
|
||||
$(this).closest("form").submit()
|
||||
false
|
||||
)
|
||||
|
||||
toggleLink: ->
|
||||
$(".js-toggle-link").unbind("click").on("click", ->
|
||||
$($(this).data("toggle-selector")).toggle("down")
|
||||
if $(this).data("toggle-text") isnt undefined
|
||||
toggle_txt = $(this).text()
|
||||
$(this).text( $(this).data("toggle-text") )
|
||||
$(this).data("toggle-text", toggle_txt)
|
||||
|
||||
false
|
||||
)
|
||||
|
||||
synchronizeInputs: ->
|
||||
progress_bar = "[name='progress_bar[percentage]']"
|
||||
processes = "[name='legislation_process[background_color]'], [name='legislation_process[font_color]']"
|
||||
banners = "[name='banner[background_color]'], [name='banner[font_color]']"
|
||||
|
||||
inputs = $("#{progress_bar}, #{processes}, #{banners}")
|
||||
inputs.on
|
||||
input: ->
|
||||
$("[name='#{this.name}']").val($(this).val())
|
||||
|
||||
inputs.trigger("input")
|
||||
|
||||
hideOrShowFieldsAfterSelection: ->
|
||||
$("[name='progress_bar[kind]']").on
|
||||
change: ->
|
||||
locale = App.Globalize.selected_language()
|
||||
title_field = $(".translatable-fields[data-locale=#{locale}]")
|
||||
|
||||
if this.value == "primary"
|
||||
title_field.hide()
|
||||
$(".globalize-languages").hide()
|
||||
else
|
||||
title_field.show()
|
||||
$(".globalize-languages").show()
|
||||
|
||||
$("[name='progress_bar[kind]']").change()
|
||||
|
||||
initialize: ->
|
||||
App.Forms.disableEnter()
|
||||
App.Forms.submitOnChange()
|
||||
App.Forms.toggleLink()
|
||||
App.Forms.synchronizeInputs()
|
||||
App.Forms.hideOrShowFieldsAfterSelection()
|
||||
29
app/assets/javascripts/foundation_extras.js
Normal file
29
app/assets/javascripts/foundation_extras.js
Normal file
@@ -0,0 +1,29 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.FoundationExtras = {
|
||||
clearSticky: function() {
|
||||
if ($("[data-sticky]").length) {
|
||||
$("[data-sticky]").foundation("destroy");
|
||||
}
|
||||
},
|
||||
mobile_ui_init: function() {
|
||||
$(window).trigger("load.zf.sticky");
|
||||
},
|
||||
desktop_ui_init: function() {
|
||||
$(window).trigger("init.zf.sticky");
|
||||
},
|
||||
initialize: function() {
|
||||
$(document).foundation();
|
||||
$(window).trigger("resize");
|
||||
$(document).on("page:before-unload", this.clearSticky);
|
||||
window.addEventListener("popstate", this.clearSticky, false);
|
||||
$(function() {
|
||||
if ($(window).width() < 620) {
|
||||
App.FoundationExtras.mobile_ui_init();
|
||||
} else {
|
||||
App.FoundationExtras.desktop_ui_init();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,23 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.FoundationExtras =
|
||||
clearSticky: ->
|
||||
$("[data-sticky]").foundation("destroy") if $("[data-sticky]").length
|
||||
|
||||
mobile_ui_init: ->
|
||||
$(window).trigger "load.zf.sticky"
|
||||
|
||||
desktop_ui_init: ->
|
||||
$(window).trigger "init.zf.sticky"
|
||||
|
||||
initialize: ->
|
||||
$(document).foundation()
|
||||
$(window).trigger "resize"
|
||||
$(document).on("page:before-unload", this.clearSticky)
|
||||
window.addEventListener("popstate", this.clearSticky, false)
|
||||
|
||||
$ ->
|
||||
if $(window).width() < 620
|
||||
App.FoundationExtras.mobile_ui_init()
|
||||
else
|
||||
App.FoundationExtras.desktop_ui_init()
|
||||
40
app/assets/javascripts/gettext.js
Normal file
40
app/assets/javascripts/gettext.js
Normal file
@@ -0,0 +1,40 @@
|
||||
// Generated by CoffeeScript 1.12.6
|
||||
(function() {
|
||||
"use strict";
|
||||
var i18n;
|
||||
|
||||
i18n = {
|
||||
es: {
|
||||
"Comments": "Comentarios",
|
||||
"No comment": "Sin comentarios",
|
||||
"Cancel": "Cancelar",
|
||||
"Save": "Guardar",
|
||||
"Edit": "Editar",
|
||||
"Delete": "Borrar",
|
||||
"Unregistered": "<p>Necesitas <a href='/users/sign_in'>iniciar sesión</a> o <a href='/users/sign_up'>registrarte</a> para continuar.</p>"
|
||||
},
|
||||
en: {
|
||||
"Comments": "Coments",
|
||||
"No comment": "No comment",
|
||||
"Cancel": "Cancel",
|
||||
"Save": "Save",
|
||||
"Edit": "Edit",
|
||||
"Delete": "Delete",
|
||||
"Unregistered": "You need to <a href='/users/sign_in'>sign in</a> or <a href='/users/sign_up'>sign up</a> to continue."
|
||||
}
|
||||
};
|
||||
|
||||
window.Gettext = function() {
|
||||
return {
|
||||
gettext: function(key) {
|
||||
var locale, locale_id;
|
||||
locale_id = $("html").attr("lang");
|
||||
locale = i18n[locale_id];
|
||||
if (locale && locale[key]) {
|
||||
return locale[key];
|
||||
}
|
||||
return key;
|
||||
}
|
||||
};
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,30 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
i18n = {
|
||||
es: {
|
||||
"Comments": "Comentarios",
|
||||
"No comment": "Sin comentarios",
|
||||
"Cancel": "Cancelar",
|
||||
"Save": "Guardar",
|
||||
"Edit": "Editar",
|
||||
"Delete": "Borrar",
|
||||
"Unregistered": "<p>Necesitas <a href='/users/sign_in'>iniciar sesión</a> o <a href='/users/sign_up'>registrarte</a> para continuar.</p>"
|
||||
},
|
||||
en: {
|
||||
"Comments": "Coments",
|
||||
"No comment": "No comment",
|
||||
"Cancel": "Cancel",
|
||||
"Save": "Save",
|
||||
"Edit": "Edit",
|
||||
"Delete": "Delete",
|
||||
"Unregistered": "You need to <a href='/users/sign_in'>sign in</a> or <a href='/users/sign_up'>sign up</a> to continue."
|
||||
}
|
||||
}
|
||||
|
||||
window.Gettext = ->
|
||||
gettext: (key) ->
|
||||
locale_id = $("html").attr("lang")
|
||||
locale = i18n[locale_id]
|
||||
if locale && locale[key]
|
||||
return locale[key]
|
||||
key
|
||||
117
app/assets/javascripts/globalize.js
Normal file
117
app/assets/javascripts/globalize.js
Normal file
@@ -0,0 +1,117 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.Globalize = {
|
||||
selected_language: function() {
|
||||
return $("#select_language").val();
|
||||
},
|
||||
display_locale: function(locale) {
|
||||
App.Globalize.enable_locale(locale);
|
||||
App.Globalize.add_language(locale);
|
||||
$(".js-add-language option:selected").removeAttr("selected");
|
||||
},
|
||||
display_translations: function(locale) {
|
||||
$(".js-select-language option[value=" + locale + "]").prop("selected", true);
|
||||
$(".js-globalize-attribute").each(function() {
|
||||
if ($(this).data("locale") === locale) {
|
||||
$(this).show();
|
||||
} else {
|
||||
$(this).hide();
|
||||
}
|
||||
$(".js-delete-language").hide();
|
||||
$(".js-delete-" + locale).show();
|
||||
});
|
||||
},
|
||||
add_language: function(locale) {
|
||||
var language_option, option;
|
||||
language_option = $(".js-add-language [value=" + locale + "]");
|
||||
if ($(".js-select-language option[value=" + locale + "]").length === 0) {
|
||||
option = new Option(language_option.text(), language_option.val());
|
||||
$(".js-select-language").append(option);
|
||||
}
|
||||
$(".js-select-language option[value=" + locale + "]").prop("selected", true);
|
||||
},
|
||||
remove_language: function(locale) {
|
||||
var next;
|
||||
$(".js-globalize-attribute[data-locale=" + locale + "]").each(function() {
|
||||
$(this).val("").hide();
|
||||
App.Globalize.resetEditor(this);
|
||||
});
|
||||
$(".js-select-language option[value=" + locale + "]").remove();
|
||||
next = $(".js-select-language option:not([value=''])").first();
|
||||
App.Globalize.display_translations(next.val());
|
||||
App.Globalize.disable_locale(locale);
|
||||
App.Globalize.update_description();
|
||||
if ($(".js-select-language option").length === 1) {
|
||||
$(".js-select-language option").prop("selected", true);
|
||||
}
|
||||
},
|
||||
resetEditor: function(element) {
|
||||
if (CKEDITOR.instances[$(element).attr("id")]) {
|
||||
CKEDITOR.instances[$(element).attr("id")].setData("");
|
||||
}
|
||||
},
|
||||
enable_locale: function(locale) {
|
||||
App.Globalize.destroy_locale_field(locale).val(false);
|
||||
App.Globalize.site_customization_enable_locale_field(locale).val(1);
|
||||
},
|
||||
disable_locale: function(locale) {
|
||||
App.Globalize.destroy_locale_field(locale).val(true);
|
||||
App.Globalize.site_customization_enable_locale_field(locale).val(0);
|
||||
},
|
||||
enabled_locales: function() {
|
||||
return $.map($(".js-select-language:first option:not([value=''])"), function(element) {
|
||||
return $(element).val();
|
||||
});
|
||||
},
|
||||
destroy_locale_field: function(locale) {
|
||||
return $("input[id$=_destroy][data-locale=" + locale + "]");
|
||||
},
|
||||
site_customization_enable_locale_field: function(locale) {
|
||||
return $("#enabled_translations_" + locale);
|
||||
},
|
||||
refresh_visible_translations: function() {
|
||||
var locale;
|
||||
locale = $(".js-select-language").val();
|
||||
App.Globalize.display_translations(locale);
|
||||
},
|
||||
update_description: function() {
|
||||
var count, description;
|
||||
count = App.Globalize.enabled_locales().length;
|
||||
description = App.Globalize.language_description(count);
|
||||
$(".js-languages-description").html(description);
|
||||
$(".js-languages-count").text(count);
|
||||
},
|
||||
language_description: function(count) {
|
||||
switch (count) {
|
||||
case 0:
|
||||
return $(".globalize-languages").data("zero-languages-description");
|
||||
case 1:
|
||||
return $(".globalize-languages").data("one-languages-description");
|
||||
default:
|
||||
return $(".globalize-languages").data("other-languages-description");
|
||||
}
|
||||
},
|
||||
initialize: function() {
|
||||
$(".js-add-language").on("change", function() {
|
||||
var locale;
|
||||
locale = $(this).val();
|
||||
App.Globalize.display_translations(locale);
|
||||
App.Globalize.display_locale(locale);
|
||||
App.Globalize.update_description();
|
||||
});
|
||||
$(".js-select-language").on("change", function() {
|
||||
App.Globalize.display_translations($(this).val());
|
||||
});
|
||||
$(".js-delete-language").on("click", function(e) {
|
||||
e.preventDefault();
|
||||
App.Globalize.remove_language($(this).data("locale"));
|
||||
$(this).hide();
|
||||
});
|
||||
$(".js-add-fields-container").on("cocoon:after-insert", function() {
|
||||
App.Globalize.enabled_locales().forEach(function(locale) {
|
||||
App.Globalize.enable_locale(locale);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,101 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.Globalize =
|
||||
|
||||
selected_language: ->
|
||||
$("#select_language").val()
|
||||
|
||||
display_locale: (locale) ->
|
||||
App.Globalize.enable_locale(locale)
|
||||
App.Globalize.add_language(locale)
|
||||
$(".js-add-language option:selected").removeAttr("selected")
|
||||
|
||||
display_translations: (locale) ->
|
||||
$(".js-select-language option[value=#{locale}]").prop("selected", true)
|
||||
$(".js-globalize-attribute").each ->
|
||||
if $(this).data("locale") == locale
|
||||
$(this).show()
|
||||
else
|
||||
$(this).hide()
|
||||
$(".js-delete-language").hide()
|
||||
$(".js-delete-" + locale).show()
|
||||
|
||||
add_language: (locale) ->
|
||||
language_option = $(".js-add-language [value=#{locale}]")
|
||||
if $(".js-select-language option[value=#{locale}]").length == 0
|
||||
option = new Option(language_option.text(), language_option.val())
|
||||
$(".js-select-language").append(option)
|
||||
$(".js-select-language option[value=#{locale}]").prop("selected", true)
|
||||
|
||||
remove_language: (locale) ->
|
||||
$(".js-globalize-attribute[data-locale=#{locale}]").each ->
|
||||
$(this).val("").hide()
|
||||
App.Globalize.resetEditor(this)
|
||||
|
||||
$(".js-select-language option[value=#{locale}]").remove()
|
||||
next = $(".js-select-language option:not([value=''])").first()
|
||||
App.Globalize.display_translations(next.val())
|
||||
App.Globalize.disable_locale(locale)
|
||||
App.Globalize.update_description()
|
||||
|
||||
if $(".js-select-language option").length == 1
|
||||
$(".js-select-language option").prop("selected", true)
|
||||
|
||||
resetEditor: (element) ->
|
||||
if CKEDITOR.instances[$(element).attr("id")]
|
||||
CKEDITOR.instances[$(element).attr("id")].setData("")
|
||||
|
||||
enable_locale: (locale) ->
|
||||
App.Globalize.destroy_locale_field(locale).val(false)
|
||||
App.Globalize.site_customization_enable_locale_field(locale).val(1)
|
||||
|
||||
disable_locale: (locale) ->
|
||||
App.Globalize.destroy_locale_field(locale).val(true)
|
||||
App.Globalize.site_customization_enable_locale_field(locale).val(0)
|
||||
|
||||
enabled_locales: ->
|
||||
$.map(
|
||||
$(".js-select-language:first option:not([value=''])"),
|
||||
(element) -> $(element).val()
|
||||
)
|
||||
|
||||
destroy_locale_field: (locale) ->
|
||||
$("input[id$=_destroy][data-locale=#{locale}]")
|
||||
|
||||
site_customization_enable_locale_field: (locale) ->
|
||||
$("#enabled_translations_#{locale}")
|
||||
|
||||
refresh_visible_translations: ->
|
||||
locale = $(".js-select-language").val()
|
||||
App.Globalize.display_translations(locale)
|
||||
|
||||
update_description: ->
|
||||
count = App.Globalize.enabled_locales().length
|
||||
description = App.Globalize.language_description(count)
|
||||
$(".js-languages-description").html(description)
|
||||
$(".js-languages-count").text(count)
|
||||
|
||||
language_description: (count) ->
|
||||
switch count
|
||||
when 0 then $(".globalize-languages").data("zero-languages-description")
|
||||
when 1 then $(".globalize-languages").data("one-languages-description")
|
||||
else $(".globalize-languages").data("other-languages-description")
|
||||
|
||||
initialize: ->
|
||||
$(".js-add-language").on "change", ->
|
||||
locale = $(this).val()
|
||||
App.Globalize.display_translations(locale)
|
||||
App.Globalize.display_locale(locale)
|
||||
App.Globalize.update_description()
|
||||
|
||||
$(".js-select-language").on "change", ->
|
||||
App.Globalize.display_translations($(this).val())
|
||||
|
||||
$(".js-delete-language").on "click", (e) ->
|
||||
e.preventDefault()
|
||||
App.Globalize.remove_language($(this).data("locale"))
|
||||
$(this).hide()
|
||||
|
||||
$(".js-add-fields-container").on "cocoon:after-insert", ->
|
||||
App.Globalize.enabled_locales().forEach (locale) ->
|
||||
App.Globalize.enable_locale(locale)
|
||||
18
app/assets/javascripts/ie_alert.js
Normal file
18
app/assets/javascripts/ie_alert.js
Normal file
@@ -0,0 +1,18 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.IeAlert = {
|
||||
set_cookie_and_hide: function(event) {
|
||||
event.preventDefault();
|
||||
$.cookie("ie_alert_closed", "true", {
|
||||
path: "/",
|
||||
expires: 365
|
||||
});
|
||||
$(".ie-callout").remove();
|
||||
},
|
||||
initialize: function() {
|
||||
$(".ie-callout-close-js").on("click", function(event) {
|
||||
App.IeAlert.set_cookie_and_hide(event);
|
||||
});
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,11 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.IeAlert =
|
||||
set_cookie_and_hide: (event) ->
|
||||
event.preventDefault()
|
||||
$.cookie("ie_alert_closed", "true", { path: "/", expires: 365 })
|
||||
$(".ie-callout").remove()
|
||||
|
||||
initialize: ->
|
||||
$(".ie-callout-close-js").on "click", (event) ->
|
||||
App.IeAlert.set_cookie_and_hide(event)
|
||||
174
app/assets/javascripts/imageable.js
Normal file
174
app/assets/javascripts/imageable.js
Normal file
@@ -0,0 +1,174 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.Imageable = {
|
||||
initialize: function() {
|
||||
$(".js-image-attachment").each(function() {
|
||||
App.Imageable.initializeDirectUploadInput(this);
|
||||
});
|
||||
$("#nested-image").on("cocoon:after-remove", function() {
|
||||
$("#new_image_link").removeClass("hide");
|
||||
});
|
||||
$("#nested-image").on("cocoon:before-insert", function() {
|
||||
$(".js-image-attachment").closest(".image").remove();
|
||||
});
|
||||
$("#nested-image").on("cocoon:after-insert", function(e, nested_image) {
|
||||
var input;
|
||||
$("#new_image_link").addClass("hide");
|
||||
input = $(nested_image).find(".js-image-attachment");
|
||||
App.Imageable.initializeDirectUploadInput(input);
|
||||
});
|
||||
},
|
||||
initializeDirectUploadInput: function(input) {
|
||||
var inputData;
|
||||
inputData = this.buildData([], input);
|
||||
this.initializeRemoveCachedImageLink(input, inputData);
|
||||
$(input).fileupload({
|
||||
paramName: "attachment",
|
||||
formData: null,
|
||||
add: function(e, data) {
|
||||
var upload_data;
|
||||
upload_data = App.Imageable.buildData(data, e.target);
|
||||
App.Imageable.clearProgressBar(upload_data);
|
||||
App.Imageable.setProgressBar(upload_data, "uploading");
|
||||
upload_data.submit();
|
||||
},
|
||||
change: function(e, data) {
|
||||
data.files.forEach(function(file) {
|
||||
App.Imageable.setFilename(inputData, file.name);
|
||||
});
|
||||
},
|
||||
fail: function(e, data) {
|
||||
$(data.cachedAttachmentField).val("");
|
||||
App.Imageable.clearFilename(data);
|
||||
App.Imageable.setProgressBar(data, "errors");
|
||||
App.Imageable.clearInputErrors(data);
|
||||
App.Imageable.setInputErrors(data);
|
||||
App.Imageable.clearPreview(data);
|
||||
$(data.destroyAttachmentLinkContainer).find("a.delete:not(.remove-nested)").remove();
|
||||
$(data.addAttachmentLabel).addClass("error");
|
||||
$(data.addAttachmentLabel).show();
|
||||
},
|
||||
done: function(e, data) {
|
||||
var destroyAttachmentLink;
|
||||
$(data.cachedAttachmentField).val(data.result.cached_attachment);
|
||||
App.Imageable.setTitleFromFile(data, data.result.filename);
|
||||
App.Imageable.setProgressBar(data, "complete");
|
||||
App.Imageable.setFilename(data, data.result.filename);
|
||||
App.Imageable.clearInputErrors(data);
|
||||
$(data.addAttachmentLabel).hide();
|
||||
$(data.wrapper).find(".attachment-actions").removeClass("small-12").addClass("small-6 float-right");
|
||||
$(data.wrapper).find(".attachment-actions .action-remove").removeClass("small-3").addClass("small-12");
|
||||
App.Imageable.setPreview(data);
|
||||
destroyAttachmentLink = $(data.result.destroy_link);
|
||||
$(data.destroyAttachmentLinkContainer).html(destroyAttachmentLink);
|
||||
$(destroyAttachmentLink).on("click", function(event) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
App.Imageable.doDeleteCachedAttachmentRequest(this.href, data);
|
||||
});
|
||||
},
|
||||
progress: function(e, data) {
|
||||
var progress;
|
||||
progress = parseInt(data.loaded / data.total * 100, 10);
|
||||
$(data.progressBar).find(".loading-bar").css("width", progress + "%");
|
||||
}
|
||||
});
|
||||
},
|
||||
buildData: function(data, input) {
|
||||
var wrapper;
|
||||
wrapper = $(input).closest(".direct-upload");
|
||||
data.input = input;
|
||||
data.wrapper = wrapper;
|
||||
data.progressBar = $(wrapper).find(".progress-bar-placeholder");
|
||||
data.preview = $(wrapper).find(".image-preview");
|
||||
data.errorContainer = $(wrapper).find(".attachment-errors");
|
||||
data.fileNameContainer = $(wrapper).find("p.file-name");
|
||||
data.destroyAttachmentLinkContainer = $(wrapper).find(".action-remove");
|
||||
data.addAttachmentLabel = $(wrapper).find(".action-add label");
|
||||
data.cachedAttachmentField = $(wrapper).find("input[name$='[cached_attachment]']");
|
||||
data.titleField = $(wrapper).find("input[name$='[title]']");
|
||||
$(wrapper).find(".progress-bar-placeholder").css("display", "block");
|
||||
return data;
|
||||
},
|
||||
clearFilename: function(data) {
|
||||
$(data.fileNameContainer).text("");
|
||||
$(data.fileNameContainer).hide();
|
||||
},
|
||||
clearInputErrors: function(data) {
|
||||
$(data.errorContainer).find("small.error").remove();
|
||||
},
|
||||
clearProgressBar: function(data) {
|
||||
$(data.progressBar).find(".loading-bar").removeClass("complete errors uploading").css("width", "0px");
|
||||
},
|
||||
clearPreview: function(data) {
|
||||
$(data.wrapper).find(".image-preview").remove();
|
||||
},
|
||||
setFilename: function(data, file_name) {
|
||||
$(data.fileNameContainer).text(file_name);
|
||||
$(data.fileNameContainer).show();
|
||||
},
|
||||
setProgressBar: function(data, klass) {
|
||||
$(data.progressBar).find(".loading-bar").addClass(klass);
|
||||
},
|
||||
setTitleFromFile: function(data, title) {
|
||||
if ($(data.titleField).val() === "") {
|
||||
$(data.titleField).val(title);
|
||||
}
|
||||
},
|
||||
setInputErrors: function(data) {
|
||||
var errors;
|
||||
errors = "<small class='error'>" + data.jqXHR.responseJSON.errors + "</small>";
|
||||
$(data.errorContainer).append(errors);
|
||||
},
|
||||
setPreview: function(data) {
|
||||
var image_preview;
|
||||
image_preview = "<div class='small-12 column text-center image-preview'><figure><img src='" + data.result.attachment_url + "' class='cached-image'></figure></div>";
|
||||
if ($(data.preview).length > 0) {
|
||||
$(data.preview).replaceWith(image_preview);
|
||||
} else {
|
||||
$(image_preview).insertBefore($(data.wrapper).find(".attachment-actions"));
|
||||
data.preview = $(data.wrapper).find(".image-preview");
|
||||
}
|
||||
},
|
||||
doDeleteCachedAttachmentRequest: function(url, data) {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: url,
|
||||
dataType: "json",
|
||||
data: {
|
||||
"_method": "delete"
|
||||
},
|
||||
complete: function() {
|
||||
$(data.cachedAttachmentField).val("");
|
||||
$(data.addAttachmentLabel).show();
|
||||
App.Imageable.clearFilename(data);
|
||||
App.Imageable.clearInputErrors(data);
|
||||
App.Imageable.clearProgressBar(data);
|
||||
App.Imageable.clearPreview(data);
|
||||
$("#new_image_link").removeClass("hide");
|
||||
$(data.wrapper).find(".attachment-actions").addClass("small-12").removeClass("small-6 float-right");
|
||||
$(data.wrapper).find(".attachment-actions .action-remove").addClass("small-3").removeClass("small-12");
|
||||
if ($(data.input).data("nested-image") === true) {
|
||||
$(data.wrapper).remove();
|
||||
} else {
|
||||
$(data.wrapper).find("a.remove-cached-attachment").remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
initializeRemoveCachedImageLink: function(input, data) {
|
||||
var remove_image_link, wrapper;
|
||||
wrapper = $(input).closest(".direct-upload");
|
||||
remove_image_link = $(wrapper).find("a.remove-cached-attachment");
|
||||
$(remove_image_link).on("click", function(e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
App.Imageable.doDeleteCachedAttachmentRequest(this.href, data);
|
||||
});
|
||||
},
|
||||
removeImage: function(id) {
|
||||
$("#" + id).remove();
|
||||
$("#new_image_link").removeClass("hide");
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,162 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.Imageable =
|
||||
|
||||
initialize: ->
|
||||
$(".js-image-attachment").each ->
|
||||
App.Imageable.initializeDirectUploadInput(this)
|
||||
|
||||
$("#nested-image").on "cocoon:after-remove", ->
|
||||
$("#new_image_link").removeClass("hide")
|
||||
|
||||
$("#nested-image").on "cocoon:before-insert", ->
|
||||
$(".js-image-attachment").closest(".image").remove()
|
||||
|
||||
$("#nested-image").on "cocoon:after-insert", (e, nested_image) ->
|
||||
$("#new_image_link").addClass("hide")
|
||||
input = $(nested_image).find(".js-image-attachment")
|
||||
App.Imageable.initializeDirectUploadInput(input)
|
||||
|
||||
initializeDirectUploadInput: (input) ->
|
||||
|
||||
inputData = this.buildData([], input)
|
||||
|
||||
this.initializeRemoveCachedImageLink(input, inputData)
|
||||
|
||||
$(input).fileupload
|
||||
|
||||
paramName: "attachment"
|
||||
|
||||
formData: null
|
||||
|
||||
add: (e, data) ->
|
||||
upload_data = App.Imageable.buildData(data, e.target)
|
||||
App.Imageable.clearProgressBar(upload_data)
|
||||
App.Imageable.setProgressBar(upload_data, "uploading")
|
||||
upload_data.submit()
|
||||
|
||||
change: (e, data) ->
|
||||
data.files.forEach (file) ->
|
||||
App.Imageable.setFilename(inputData, file.name)
|
||||
|
||||
fail: (e, data) ->
|
||||
$(data.cachedAttachmentField).val("")
|
||||
App.Imageable.clearFilename(data)
|
||||
App.Imageable.setProgressBar(data, "errors")
|
||||
App.Imageable.clearInputErrors(data)
|
||||
App.Imageable.setInputErrors(data)
|
||||
App.Imageable.clearPreview(data)
|
||||
$(data.destroyAttachmentLinkContainer).find("a.delete:not(.remove-nested)").remove()
|
||||
$(data.addAttachmentLabel).addClass("error")
|
||||
$(data.addAttachmentLabel).show()
|
||||
|
||||
done: (e, data) ->
|
||||
$(data.cachedAttachmentField).val(data.result.cached_attachment)
|
||||
App.Imageable.setTitleFromFile(data, data.result.filename)
|
||||
App.Imageable.setProgressBar(data, "complete")
|
||||
App.Imageable.setFilename(data, data.result.filename)
|
||||
App.Imageable.clearInputErrors(data)
|
||||
$(data.addAttachmentLabel).hide()
|
||||
$(data.wrapper).find(".attachment-actions").removeClass("small-12").addClass("small-6 float-right")
|
||||
$(data.wrapper).find(".attachment-actions .action-remove").removeClass("small-3").addClass("small-12")
|
||||
App.Imageable.setPreview(data)
|
||||
|
||||
destroyAttachmentLink = $(data.result.destroy_link)
|
||||
$(data.destroyAttachmentLinkContainer).html(destroyAttachmentLink)
|
||||
$(destroyAttachmentLink).on "click", (e) ->
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
App.Imageable.doDeleteCachedAttachmentRequest(this.href, data)
|
||||
|
||||
progress: (e, data) ->
|
||||
progress = parseInt(data.loaded / data.total * 100, 10)
|
||||
$(data.progressBar).find(".loading-bar").css "width", "#{progress}%"
|
||||
return
|
||||
|
||||
buildData: (data, input) ->
|
||||
wrapper = $(input).closest(".direct-upload")
|
||||
data.input = input
|
||||
data.wrapper = wrapper
|
||||
data.progressBar = $(wrapper).find(".progress-bar-placeholder")
|
||||
data.preview = $(wrapper).find(".image-preview")
|
||||
data.errorContainer = $(wrapper).find(".attachment-errors")
|
||||
data.fileNameContainer = $(wrapper).find("p.file-name")
|
||||
data.destroyAttachmentLinkContainer = $(wrapper).find(".action-remove")
|
||||
data.addAttachmentLabel = $(wrapper).find(".action-add label")
|
||||
data.cachedAttachmentField = $(wrapper).find("input[name$='[cached_attachment]']")
|
||||
data.titleField = $(wrapper).find("input[name$='[title]']")
|
||||
$(wrapper).find(".progress-bar-placeholder").css("display", "block")
|
||||
return data
|
||||
|
||||
clearFilename: (data) ->
|
||||
$(data.fileNameContainer).text("")
|
||||
$(data.fileNameContainer).hide()
|
||||
|
||||
clearInputErrors: (data) ->
|
||||
$(data.errorContainer).find("small.error").remove()
|
||||
|
||||
clearProgressBar: (data) ->
|
||||
$(data.progressBar).find(".loading-bar").removeClass("complete errors uploading").css("width", "0px")
|
||||
|
||||
clearPreview: (data) ->
|
||||
$(data.wrapper).find(".image-preview").remove()
|
||||
|
||||
setFilename: (data, file_name) ->
|
||||
$(data.fileNameContainer).text(file_name)
|
||||
$(data.fileNameContainer).show()
|
||||
|
||||
setProgressBar: (data, klass) ->
|
||||
$(data.progressBar).find(".loading-bar").addClass(klass)
|
||||
|
||||
setTitleFromFile: (data, title) ->
|
||||
if $(data.titleField).val() == ""
|
||||
$(data.titleField).val(title)
|
||||
|
||||
setInputErrors: (data) ->
|
||||
errors = "<small class='error'>#{data.jqXHR.responseJSON.errors}</small>"
|
||||
$(data.errorContainer).append(errors)
|
||||
|
||||
setPreview: (data) ->
|
||||
image_preview = "<div class='small-12 column text-center image-preview'><figure><img src='#{data.result.attachment_url}' class='cached-image'></figure></div>"
|
||||
if $(data.preview).length > 0
|
||||
$(data.preview).replaceWith(image_preview)
|
||||
else
|
||||
$(image_preview).insertBefore($(data.wrapper).find(".attachment-actions"))
|
||||
data.preview = $(data.wrapper).find(".image-preview")
|
||||
|
||||
doDeleteCachedAttachmentRequest: (url, data) ->
|
||||
$.ajax
|
||||
type: "POST"
|
||||
url: url
|
||||
dataType: "json"
|
||||
data: { "_method": "delete" }
|
||||
complete: ->
|
||||
$(data.cachedAttachmentField).val("")
|
||||
$(data.addAttachmentLabel).show()
|
||||
|
||||
App.Imageable.clearFilename(data)
|
||||
App.Imageable.clearInputErrors(data)
|
||||
App.Imageable.clearProgressBar(data)
|
||||
App.Imageable.clearPreview(data)
|
||||
|
||||
$("#new_image_link").removeClass("hide")
|
||||
|
||||
$(data.wrapper).find(".attachment-actions").addClass("small-12").removeClass("small-6 float-right")
|
||||
$(data.wrapper).find(".attachment-actions .action-remove").addClass("small-3").removeClass("small-12")
|
||||
|
||||
if $(data.input).data("nested-image") == true
|
||||
$(data.wrapper).remove()
|
||||
else
|
||||
$(data.wrapper).find("a.remove-cached-attachment").remove()
|
||||
|
||||
initializeRemoveCachedImageLink: (input, data) ->
|
||||
wrapper = $(input).closest(".direct-upload")
|
||||
remove_image_link = $(wrapper).find("a.remove-cached-attachment")
|
||||
$(remove_image_link).on "click", (e) ->
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
App.Imageable.doDeleteCachedAttachmentRequest(this.href, data)
|
||||
|
||||
removeImage: (id) ->
|
||||
$("##{id}").remove()
|
||||
$("#new_image_link").removeClass("hide")
|
||||
14
app/assets/javascripts/investment_report_alert.js
Normal file
14
app/assets/javascripts/investment_report_alert.js
Normal file
@@ -0,0 +1,14 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.InvestmentReportAlert = {
|
||||
initialize: function() {
|
||||
$("#js-investment-report-alert").on("click", function() {
|
||||
if (this.checked && $("#budget_investment_feasibility_unfeasible").is(":checked")) {
|
||||
return confirm(this.dataset.alert + "\n" + this.dataset.notFeasibleAlert);
|
||||
} else if (this.checked) {
|
||||
return confirm(this.dataset.alert);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,9 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.InvestmentReportAlert =
|
||||
initialize: ->
|
||||
$("#js-investment-report-alert").on "click", ->
|
||||
if this.checked && $("#budget_investment_feasibility_unfeasible").is(":checked")
|
||||
confirm("#{this.dataset.alert}\n#{this.dataset.notFeasibleAlert}")
|
||||
else if this.checked
|
||||
confirm(this.dataset.alert)
|
||||
19
app/assets/javascripts/legislation.js
Normal file
19
app/assets/javascripts/legislation.js
Normal file
@@ -0,0 +1,19 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.Legislation = {
|
||||
initialize: function() {
|
||||
$("form#new_legislation_answer input.button").hide();
|
||||
$("form#new_legislation_answer input[type=radio]").on({
|
||||
click: function() {
|
||||
$("form#new_legislation_answer").submit();
|
||||
}
|
||||
});
|
||||
$("form#draft_version_go_to_version input.button").hide();
|
||||
$("form#draft_version_go_to_version select").on({
|
||||
change: function() {
|
||||
$("form#draft_version_go_to_version").submit();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,14 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.Legislation =
|
||||
|
||||
initialize: ->
|
||||
$("form#new_legislation_answer input.button").hide()
|
||||
$("form#new_legislation_answer input[type=radio]").on
|
||||
click: ->
|
||||
$("form#new_legislation_answer").submit()
|
||||
|
||||
$("form#draft_version_go_to_version input.button").hide()
|
||||
$("form#draft_version_go_to_version select").on
|
||||
change: ->
|
||||
$("form#draft_version_go_to_version").submit()
|
||||
25
app/assets/javascripts/legislation_admin.js
Normal file
25
app/assets/javascripts/legislation_admin.js
Normal file
@@ -0,0 +1,25 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.LegislationAdmin = {
|
||||
initialize: function() {
|
||||
$("input[type='checkbox'][data-disable-date]").on({
|
||||
change: function() {
|
||||
var checkbox, date_selector, parent;
|
||||
checkbox = $(this);
|
||||
parent = $(this).parents(".row:eq(0)");
|
||||
date_selector = $(this).data("disable-date");
|
||||
parent.find("input[type='text'][id^='" + date_selector + "']").each(function() {
|
||||
if (checkbox.is(":checked")) {
|
||||
$(this).removeAttr("disabled");
|
||||
} else {
|
||||
$(this).val("");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
$("#nested_question_options").on("cocoon:after-insert", function() {
|
||||
App.Globalize.refresh_visible_translations();
|
||||
});
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,18 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.LegislationAdmin =
|
||||
|
||||
initialize: ->
|
||||
$("input[type='checkbox'][data-disable-date]").on
|
||||
change: ->
|
||||
checkbox = $(this)
|
||||
parent = $(this).parents(".row:eq(0)")
|
||||
date_selector = $(this).data("disable-date")
|
||||
parent.find("input[type='text'][id^='#{date_selector}']").each ->
|
||||
if checkbox.is(":checked")
|
||||
$(this).removeAttr("disabled")
|
||||
else
|
||||
$(this).val("")
|
||||
|
||||
$("#nested_question_options").on "cocoon:after-insert", ->
|
||||
App.Globalize.refresh_visible_translations()
|
||||
36
app/assets/javascripts/legislation_allegations.js
Normal file
36
app/assets/javascripts/legislation_allegations.js
Normal file
@@ -0,0 +1,36 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.LegislationAllegations = {
|
||||
toggle_comments: function() {
|
||||
if (!App.LegislationAnnotatable.isMobile()) {
|
||||
$(".draft-allegation").toggleClass("comments-on");
|
||||
$("#comments-box").html("").hide();
|
||||
}
|
||||
},
|
||||
show_comments: function() {
|
||||
if (!App.LegislationAnnotatable.isMobile()) {
|
||||
$(".draft-allegation").addClass("comments-on");
|
||||
}
|
||||
},
|
||||
initialize: function() {
|
||||
$(".js-toggle-allegations .draft-panel").on({
|
||||
click: function(e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
if (!App.LegislationAnnotatable.isMobile()) {
|
||||
App.LegislationAllegations.toggle_comments();
|
||||
}
|
||||
}
|
||||
});
|
||||
$(".js-toggle-allegations").on({
|
||||
click: function() {
|
||||
if (!App.LegislationAnnotatable.isMobile()) {
|
||||
if ($(this).find(".draft-panel .panel-title:visible").length === 0) {
|
||||
App.LegislationAllegations.toggle_comments();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,27 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.LegislationAllegations =
|
||||
|
||||
toggle_comments: ->
|
||||
if !App.LegislationAnnotatable.isMobile()
|
||||
$(".draft-allegation").toggleClass("comments-on")
|
||||
$("#comments-box").html("").hide()
|
||||
|
||||
show_comments: ->
|
||||
if !App.LegislationAnnotatable.isMobile()
|
||||
$(".draft-allegation").addClass("comments-on")
|
||||
|
||||
initialize: ->
|
||||
$(".js-toggle-allegations .draft-panel").on
|
||||
click: (e) ->
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
if !App.LegislationAnnotatable.isMobile()
|
||||
App.LegislationAllegations.toggle_comments()
|
||||
|
||||
$(".js-toggle-allegations").on
|
||||
click: ->
|
||||
# Toggle comments when the section title is visible
|
||||
if !App.LegislationAnnotatable.isMobile()
|
||||
if $(this).find(".draft-panel .panel-title:visible").length == 0
|
||||
App.LegislationAllegations.toggle_comments()
|
||||
232
app/assets/javascripts/legislation_annotatable.js
Normal file
232
app/assets/javascripts/legislation_annotatable.js
Normal file
@@ -0,0 +1,232 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.LegislationAnnotatable = {
|
||||
makeEditableAndHighlight: function(colour) {
|
||||
var range, sel;
|
||||
sel = window.getSelection();
|
||||
if (sel.rangeCount && sel.getRangeAt) {
|
||||
range = sel.getRangeAt(0);
|
||||
}
|
||||
document.designMode = "on";
|
||||
if (range) {
|
||||
sel.removeAllRanges();
|
||||
sel.addRange(range);
|
||||
}
|
||||
if (!document.execCommand("HiliteColor", false, colour)) {
|
||||
document.execCommand("BackColor", false, colour);
|
||||
}
|
||||
document.designMode = "off";
|
||||
},
|
||||
highlight: function(colour) {
|
||||
try {
|
||||
if (!document.execCommand("BackColor", false, colour)) {
|
||||
App.LegislationAnnotatable.makeEditableAndHighlight(colour);
|
||||
}
|
||||
} catch (error) {
|
||||
App.LegislationAnnotatable.makeEditableAndHighlight(colour);
|
||||
}
|
||||
},
|
||||
remove_highlight: function() {
|
||||
$("[data-legislation-draft-version-id] span[style]").replaceWith(function() {
|
||||
return $(this).contents();
|
||||
});
|
||||
},
|
||||
renderAnnotationComments: function(event) {
|
||||
if (event.offset) {
|
||||
$("#comments-box").css({
|
||||
top: event.offset - $(".calc-comments").offset().top
|
||||
});
|
||||
}
|
||||
if (App.LegislationAnnotatable.isMobile()) {
|
||||
return;
|
||||
}
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: event.annotation_url + "/annotations/" + event.annotation_id + "/comments",
|
||||
dataType: "script"
|
||||
});
|
||||
},
|
||||
onClick: function(event) {
|
||||
var annotation_id, annotation_url, parents, parents_ids, target;
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
if (App.LegislationAnnotatable.isMobile()) {
|
||||
annotation_url = $(event.target).closest(".legislation-annotatable").data("legislation-annotatable-base-url");
|
||||
window.location.href = annotation_url + "/annotations/" + ($(this).data("annotation-id"));
|
||||
return;
|
||||
}
|
||||
$("[data-annotation-id]").removeClass("current-annotation");
|
||||
target = $(this);
|
||||
parents = target.parents(".annotator-hl");
|
||||
parents_ids = parents.map(function(_, elem) {
|
||||
return $(elem).data("annotation-id");
|
||||
});
|
||||
annotation_id = target.data("annotation-id");
|
||||
$("[data-annotation-id='" + annotation_id + "']").addClass("current-annotation");
|
||||
$("#comments-box").html("");
|
||||
App.LegislationAllegations.show_comments();
|
||||
$("#comments-box").show();
|
||||
$.event.trigger({
|
||||
type: "renderLegislationAnnotation",
|
||||
annotation_id: target.data("annotation-id"),
|
||||
annotation_url: target.closest(".legislation-annotatable").data("legislation-annotatable-base-url"),
|
||||
offset: target.offset().top
|
||||
});
|
||||
parents_ids.each(function(i, pid) {
|
||||
$.event.trigger({
|
||||
type: "renderLegislationAnnotation",
|
||||
annotation_id: pid,
|
||||
annotation_url: target.closest(".legislation-annotatable").data("legislation-annotatable-base-url")
|
||||
});
|
||||
});
|
||||
},
|
||||
isMobile: function() {
|
||||
return window.innerWidth <= 652;
|
||||
},
|
||||
viewerExtension: function(viewer) {
|
||||
return viewer._onHighlightMouseover = function() {};
|
||||
},
|
||||
customShow: function(position) {
|
||||
var annotation_url;
|
||||
$(this.element).html("");
|
||||
// Clean comments section and open it
|
||||
$("#comments-box").html("");
|
||||
App.LegislationAllegations.show_comments();
|
||||
$("#comments-box").show();
|
||||
annotation_url = $("[data-legislation-annotatable-base-url]").data("legislation-annotatable-base-url");
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: annotation_url + "/annotations/new",
|
||||
dataType: "script"
|
||||
}).done((function() {
|
||||
$("#new_legislation_annotation #legislation_annotation_quote").val(this.annotation.quote);
|
||||
$("#new_legislation_annotation #legislation_annotation_ranges").val(JSON.stringify(this.annotation.ranges));
|
||||
$("#comments-box").css({
|
||||
top: position.top - $(".calc-comments").offset().top
|
||||
});
|
||||
if ($("[data-legislation-open-phase]").data("legislation-open-phase") !== false) {
|
||||
App.LegislationAnnotatable.highlight("#7fff9a");
|
||||
$("#comments-box textarea").focus();
|
||||
$("#new_legislation_annotation").on("ajax:complete", function(e, data) {
|
||||
App.LegislationAnnotatable.app.destroy();
|
||||
if (data.status === 200) {
|
||||
App.LegislationAnnotatable.remove_highlight();
|
||||
$("#comments-box").html("").hide();
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: annotation_url + "/annotations/" + data.responseJSON.id + "/comments",
|
||||
dataType: "script"
|
||||
});
|
||||
} else {
|
||||
$(e.target).find("label").addClass("error");
|
||||
$("<small class='error'>" + data.responseJSON[0] + "</small>").insertAfter($(e.target).find("textarea"));
|
||||
}
|
||||
});
|
||||
}
|
||||
}).bind(this));
|
||||
},
|
||||
editorExtension: function(editor) {
|
||||
return editor.show = App.LegislationAnnotatable.customShow;
|
||||
},
|
||||
scrollToAnchor: function() {
|
||||
return {
|
||||
annotationsLoaded: function() {
|
||||
var anchor, ann_id, checkExist;
|
||||
anchor = $(location).attr("hash");
|
||||
if (anchor && anchor.startsWith("#annotation")) {
|
||||
ann_id = anchor.split("-").slice(-1);
|
||||
return checkExist = setInterval((function() {
|
||||
var el;
|
||||
if ($("span[data-annotation-id='" + ann_id + "']").length) {
|
||||
el = $("span[data-annotation-id='" + ann_id + "']");
|
||||
el.addClass("current-annotation");
|
||||
$("#comments-box").html("");
|
||||
App.LegislationAllegations.show_comments();
|
||||
$("html,body").animate({
|
||||
scrollTop: el.offset().top
|
||||
});
|
||||
$.event.trigger({
|
||||
type: "renderLegislationAnnotation",
|
||||
annotation_id: ann_id,
|
||||
annotation_url: el.closest(".legislation-annotatable").data("legislation-annotatable-base-url"),
|
||||
offset: el.offset().top
|
||||
});
|
||||
clearInterval(checkExist);
|
||||
}
|
||||
}), 100);
|
||||
}
|
||||
}
|
||||
};
|
||||
},
|
||||
propotionalWeight: function(v, max) {
|
||||
return Math.floor(v * 5 / (max + 1)) + 1;
|
||||
},
|
||||
addWeightClasses: function() {
|
||||
return {
|
||||
annotationsLoaded: function(annotations) {
|
||||
var checkExist, last_annotation, max_weight, weights;
|
||||
if (annotations.length === 0) {
|
||||
return;
|
||||
}
|
||||
weights = annotations.map(function(ann) {
|
||||
return ann.weight;
|
||||
});
|
||||
max_weight = Math.max.apply(null, weights);
|
||||
last_annotation = annotations[annotations.length - 1];
|
||||
return checkExist = setInterval((function() {
|
||||
if ($("span[data-annotation-id='" + last_annotation.id + "']").length) {
|
||||
annotations.forEach(function(annotation) {
|
||||
var ann_weight, el;
|
||||
ann_weight = App.LegislationAnnotatable.propotionalWeight(annotation.weight, max_weight);
|
||||
el = $("span[data-annotation-id='" + annotation.id + "']");
|
||||
el.addClass("weight-" + ann_weight);
|
||||
});
|
||||
clearInterval(checkExist);
|
||||
}
|
||||
}), 100);
|
||||
}
|
||||
};
|
||||
},
|
||||
initialize: function() {
|
||||
var current_user_id;
|
||||
$(document).off("renderLegislationAnnotation").on("renderLegislationAnnotation", App.LegislationAnnotatable.renderAnnotationComments);
|
||||
$(document).off("click", "[data-annotation-id]").on("click", "[data-annotation-id]", App.LegislationAnnotatable.onClick);
|
||||
$(document).off("click", "[data-cancel-annotation]").on("click", "[data-cancel-annotation]", function(e) {
|
||||
e.preventDefault();
|
||||
$("#comments-box").html("");
|
||||
$("#comments-box").hide();
|
||||
App.LegislationAnnotatable.remove_highlight();
|
||||
});
|
||||
current_user_id = $("html").data("current-user-id");
|
||||
$(".legislation-annotatable").each(function() {
|
||||
var ann_id, base_url;
|
||||
ann_id = $(this).data("legislation-draft-version-id");
|
||||
base_url = $(this).data("legislation-annotatable-base-url");
|
||||
App.LegislationAnnotatable.app = new annotator.App().include(function() {
|
||||
return {
|
||||
beforeAnnotationCreated: function(ann) {
|
||||
ann.legislation_draft_version_id = ann_id;
|
||||
ann.permissions = ann.permissions || {};
|
||||
ann.permissions.admin = [];
|
||||
}
|
||||
};
|
||||
}).include(annotator.ui.main, {
|
||||
element: this,
|
||||
viewerExtensions: [App.LegislationAnnotatable.viewerExtension],
|
||||
editorExtensions: [App.LegislationAnnotatable.editorExtension]
|
||||
}).include(App.LegislationAnnotatable.scrollToAnchor).include(App.LegislationAnnotatable.addWeightClasses).include(annotator.storage.http, {
|
||||
prefix: base_url,
|
||||
urls: {
|
||||
search: "/annotations/search"
|
||||
}
|
||||
});
|
||||
App.LegislationAnnotatable.app.start().then(function() {
|
||||
App.LegislationAnnotatable.app.ident.identity = current_user_id;
|
||||
App.LegislationAnnotatable.app.annotations.load({
|
||||
legislation_draft_version_id: ann_id
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,205 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.LegislationAnnotatable =
|
||||
|
||||
makeEditableAndHighlight: (colour) ->
|
||||
sel = window.getSelection()
|
||||
if sel.rangeCount and sel.getRangeAt
|
||||
range = sel.getRangeAt(0)
|
||||
document.designMode = "on"
|
||||
if range
|
||||
sel.removeAllRanges()
|
||||
sel.addRange range
|
||||
# Use HiliteColor since some browsers apply BackColor to the whole block
|
||||
if !document.execCommand("HiliteColor", false, colour)
|
||||
document.execCommand "BackColor", false, colour
|
||||
document.designMode = "off"
|
||||
return
|
||||
|
||||
highlight: (colour) ->
|
||||
try
|
||||
if !document.execCommand("BackColor", false, colour)
|
||||
App.LegislationAnnotatable.makeEditableAndHighlight colour
|
||||
catch
|
||||
App.LegislationAnnotatable.makeEditableAndHighlight colour
|
||||
|
||||
return
|
||||
|
||||
remove_highlight: ->
|
||||
$("[data-legislation-draft-version-id] span[style]").replaceWith(->
|
||||
return $(this).contents()
|
||||
)
|
||||
return
|
||||
|
||||
renderAnnotationComments: (event) ->
|
||||
if event.offset
|
||||
$("#comments-box").css({ top: event.offset - $(".calc-comments").offset().top })
|
||||
|
||||
if App.LegislationAnnotatable.isMobile()
|
||||
return
|
||||
|
||||
$.ajax
|
||||
method: "GET"
|
||||
url: "#{event.annotation_url}/annotations/#{event.annotation_id}/comments"
|
||||
dataType: "script"
|
||||
|
||||
onClick: (event) ->
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
|
||||
if App.LegislationAnnotatable.isMobile()
|
||||
annotation_url = $(event.target).closest(".legislation-annotatable").data("legislation-annotatable-base-url")
|
||||
window.location.href = "#{annotation_url}/annotations/#{$(this).data("annotation-id")}"
|
||||
return
|
||||
|
||||
$("[data-annotation-id]").removeClass("current-annotation")
|
||||
|
||||
target = $(this)
|
||||
|
||||
parents = target.parents(".annotator-hl")
|
||||
parents_ids = parents.map (_, elem) ->
|
||||
$(elem).data("annotation-id")
|
||||
|
||||
annotation_id = target.data("annotation-id")
|
||||
$("[data-annotation-id='#{annotation_id}']").addClass("current-annotation")
|
||||
|
||||
$("#comments-box").html("")
|
||||
App.LegislationAllegations.show_comments()
|
||||
$("#comments-box").show()
|
||||
|
||||
$.event.trigger
|
||||
type: "renderLegislationAnnotation"
|
||||
annotation_id: target.data("annotation-id")
|
||||
annotation_url: target.closest(".legislation-annotatable").data("legislation-annotatable-base-url")
|
||||
offset: target.offset()["top"]
|
||||
|
||||
parents_ids.each (i, pid) ->
|
||||
$.event.trigger
|
||||
type: "renderLegislationAnnotation"
|
||||
annotation_id: pid
|
||||
annotation_url: target.closest(".legislation-annotatable").data("legislation-annotatable-base-url")
|
||||
|
||||
isMobile: ->
|
||||
return window.innerWidth <= 652
|
||||
|
||||
viewerExtension: (viewer) ->
|
||||
viewer._onHighlightMouseover = ->
|
||||
return
|
||||
|
||||
customShow: (position) ->
|
||||
$(this.element).html ""
|
||||
# Clean comments section and open it
|
||||
$("#comments-box").html ""
|
||||
App.LegislationAllegations.show_comments()
|
||||
$("#comments-box").show()
|
||||
|
||||
annotation_url = $("[data-legislation-annotatable-base-url]").data("legislation-annotatable-base-url")
|
||||
$.ajax(
|
||||
method: "GET"
|
||||
url: "#{annotation_url}/annotations/new"
|
||||
dataType: "script").done (->
|
||||
$("#new_legislation_annotation #legislation_annotation_quote").val(this.annotation.quote)
|
||||
$("#new_legislation_annotation #legislation_annotation_ranges").val(JSON.stringify(this.annotation.ranges))
|
||||
$("#comments-box").css({ top: position.top - $(".calc-comments").offset().top })
|
||||
|
||||
unless $("[data-legislation-open-phase]").data("legislation-open-phase") == false
|
||||
App.LegislationAnnotatable.highlight("#7fff9a")
|
||||
$("#comments-box textarea").focus()
|
||||
|
||||
$("#new_legislation_annotation").on("ajax:complete", (e, data) ->
|
||||
App.LegislationAnnotatable.app.destroy()
|
||||
if data.status == 200
|
||||
App.LegislationAnnotatable.remove_highlight()
|
||||
$("#comments-box").html("").hide()
|
||||
$.ajax
|
||||
method: "GET"
|
||||
url: "#{annotation_url}/annotations/#{data.responseJSON.id}/comments"
|
||||
dataType: "script"
|
||||
else
|
||||
$(e.target).find("label").addClass("error")
|
||||
$("<small class='error'>#{data.responseJSON[0]}</small>").insertAfter($(e.target).find("textarea"))
|
||||
return true
|
||||
)
|
||||
return
|
||||
).bind(this)
|
||||
|
||||
editorExtension: (editor) ->
|
||||
editor.show = App.LegislationAnnotatable.customShow
|
||||
|
||||
scrollToAnchor: ->
|
||||
annotationsLoaded: ->
|
||||
anchor = $(location).attr("hash")
|
||||
if anchor && anchor.startsWith("#annotation")
|
||||
ann_id = anchor.split("-")[-1..]
|
||||
|
||||
checkExist = setInterval((->
|
||||
if $("span[data-annotation-id='#{ann_id}']").length
|
||||
el = $("span[data-annotation-id='#{ann_id}']")
|
||||
el.addClass("current-annotation")
|
||||
$("#comments-box").html("")
|
||||
App.LegislationAllegations.show_comments()
|
||||
$("html,body").animate({ scrollTop: el.offset().top })
|
||||
$.event.trigger
|
||||
type: "renderLegislationAnnotation"
|
||||
annotation_id: ann_id
|
||||
annotation_url: el.closest(".legislation-annotatable").data("legislation-annotatable-base-url")
|
||||
offset: el.offset()["top"]
|
||||
clearInterval checkExist
|
||||
return
|
||||
), 100)
|
||||
|
||||
propotionalWeight: (v, max) ->
|
||||
Math.floor(v * 5 / (max + 1)) + 1
|
||||
|
||||
addWeightClasses: ->
|
||||
annotationsLoaded: (annotations) ->
|
||||
return if annotations.length == 0
|
||||
weights = annotations.map (ann) -> ann.weight
|
||||
max_weight = Math.max.apply(null, weights)
|
||||
last_annotation = annotations[annotations.length - 1]
|
||||
|
||||
checkExist = setInterval((->
|
||||
if $("span[data-annotation-id='#{last_annotation.id}']").length
|
||||
annotations.forEach (annotation) ->
|
||||
ann_weight = App.LegislationAnnotatable.propotionalWeight(annotation.weight, max_weight)
|
||||
el = $("span[data-annotation-id='#{annotation.id}']")
|
||||
el.addClass("weight-#{ann_weight}")
|
||||
clearInterval checkExist
|
||||
return
|
||||
), 100)
|
||||
|
||||
initialize: ->
|
||||
$(document).off("renderLegislationAnnotation").on("renderLegislationAnnotation", App.LegislationAnnotatable.renderAnnotationComments)
|
||||
$(document).off("click", "[data-annotation-id]").on("click", "[data-annotation-id]", App.LegislationAnnotatable.onClick)
|
||||
$(document).off("click", "[data-cancel-annotation]").on("click", "[data-cancel-annotation]", (e) ->
|
||||
e.preventDefault()
|
||||
$("#comments-box").html("")
|
||||
$("#comments-box").hide()
|
||||
App.LegislationAnnotatable.remove_highlight()
|
||||
return
|
||||
)
|
||||
|
||||
current_user_id = $("html").data("current-user-id")
|
||||
|
||||
$(".legislation-annotatable").each ->
|
||||
ann_id = $(this).data("legislation-draft-version-id")
|
||||
base_url = $(this).data("legislation-annotatable-base-url")
|
||||
|
||||
App.LegislationAnnotatable.app = new annotator.App()
|
||||
.include ->
|
||||
beforeAnnotationCreated: (ann) ->
|
||||
ann["legislation_draft_version_id"] = ann_id
|
||||
ann.permissions = ann.permissions || {}
|
||||
ann.permissions.admin = []
|
||||
.include(annotator.ui.main, {
|
||||
element: this,
|
||||
viewerExtensions: [App.LegislationAnnotatable.viewerExtension],
|
||||
editorExtensions: [App.LegislationAnnotatable.editorExtension]
|
||||
})
|
||||
.include(App.LegislationAnnotatable.scrollToAnchor)
|
||||
.include(App.LegislationAnnotatable.addWeightClasses)
|
||||
.include(annotator.storage.http, { prefix: base_url, urls: { search: "/annotations/search" } })
|
||||
|
||||
App.LegislationAnnotatable.app.start().then ->
|
||||
App.LegislationAnnotatable.app.ident.identity = current_user_id
|
||||
App.LegislationAnnotatable.app.annotations.load(legislation_draft_version_id: ann_id)
|
||||
10
app/assets/javascripts/location_changer.js
Normal file
10
app/assets/javascripts/location_changer.js
Normal file
@@ -0,0 +1,10 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.LocationChanger = {
|
||||
initialize: function() {
|
||||
$(".js-location-changer").on("change", function() {
|
||||
window.location.assign($(this).val());
|
||||
});
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,7 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.LocationChanger =
|
||||
|
||||
initialize: ->
|
||||
$(".js-location-changer").on "change", ->
|
||||
window.location.assign($(this).val())
|
||||
32
app/assets/javascripts/managers.js
Normal file
32
app/assets/javascripts/managers.js
Normal file
@@ -0,0 +1,32 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.Managers = {
|
||||
generatePassword: function() {
|
||||
var chars, possible_chars;
|
||||
possible_chars = "aAbcdeEfghiJkmnpqrstuUvwxyz23456789";
|
||||
chars = Array.apply(null, {
|
||||
length: 12
|
||||
}).map(function() {
|
||||
var i;
|
||||
i = Math.floor(Math.random() * possible_chars.length);
|
||||
return possible_chars.charAt(i);
|
||||
});
|
||||
return chars.join("");
|
||||
},
|
||||
togglePassword: function(type) {
|
||||
$("#user_password").prop("type", type);
|
||||
},
|
||||
initialize: function() {
|
||||
$(".generate-random-value").on("click", function() {
|
||||
$("#user_password").val(App.Managers.generatePassword());
|
||||
});
|
||||
$(".show-password").on("click", function() {
|
||||
if ($("#user_password").is("input[type='password']")) {
|
||||
App.Managers.togglePassword("text");
|
||||
} else {
|
||||
App.Managers.togglePassword("password");
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,25 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.Managers =
|
||||
|
||||
generatePassword: ->
|
||||
possible_chars = "aAbcdeEfghiJkmnpqrstuUvwxyz23456789"
|
||||
|
||||
chars = Array.apply(null, length: 12).map ->
|
||||
i = Math.floor(Math.random() * possible_chars.length)
|
||||
possible_chars.charAt(i)
|
||||
|
||||
chars.join("")
|
||||
|
||||
togglePassword: (type) ->
|
||||
$("#user_password").prop "type", type
|
||||
|
||||
initialize: ->
|
||||
$(".generate-random-value").on "click", ->
|
||||
$("#user_password").val(App.Managers.generatePassword())
|
||||
|
||||
$(".show-password").on "click", ->
|
||||
if $("#user_password").is("input[type='password']")
|
||||
App.Managers.togglePassword("text")
|
||||
else
|
||||
App.Managers.togglePassword("password")
|
||||
131
app/assets/javascripts/map.js
Normal file
131
app/assets/javascripts/map.js
Normal file
@@ -0,0 +1,131 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.Map = {
|
||||
initialize: function() {
|
||||
$("*[data-map]").each(function() {
|
||||
App.Map.initializeMap(this);
|
||||
});
|
||||
$(".js-toggle-map").on({
|
||||
click: function() {
|
||||
App.Map.toggleMap();
|
||||
}
|
||||
});
|
||||
},
|
||||
initializeMap: function(element) {
|
||||
var addMarkerInvestments, clearFormfields, createMarker, editable, getPopupContent, latitudeInputSelector, longitudeInputSelector, map, mapAttribution, mapCenterLatLng, mapCenterLatitude, mapCenterLongitude, mapTilesProvider, marker, markerIcon, markerLatitude, markerLongitude, moveOrPlaceMarker, openMarkerPopup, removeMarker, removeMarkerSelector, updateFormfields, zoom, zoomInputSelector;
|
||||
App.Map.cleanInvestmentCoordinates(element);
|
||||
mapCenterLatitude = $(element).data("map-center-latitude");
|
||||
mapCenterLongitude = $(element).data("map-center-longitude");
|
||||
markerLatitude = $(element).data("marker-latitude");
|
||||
markerLongitude = $(element).data("marker-longitude");
|
||||
zoom = $(element).data("map-zoom");
|
||||
mapTilesProvider = $(element).data("map-tiles-provider");
|
||||
mapAttribution = $(element).data("map-tiles-provider-attribution");
|
||||
latitudeInputSelector = $(element).data("latitude-input-selector");
|
||||
longitudeInputSelector = $(element).data("longitude-input-selector");
|
||||
zoomInputSelector = $(element).data("zoom-input-selector");
|
||||
removeMarkerSelector = $(element).data("marker-remove-selector");
|
||||
addMarkerInvestments = $(element).data("marker-investments-coordinates");
|
||||
editable = $(element).data("marker-editable");
|
||||
marker = null;
|
||||
markerIcon = L.divIcon({
|
||||
className: "map-marker",
|
||||
iconSize: [30, 30],
|
||||
iconAnchor: [15, 40],
|
||||
html: '<div class="map-icon"></div>'
|
||||
});
|
||||
createMarker = function(latitude, longitude) {
|
||||
var markerLatLng;
|
||||
markerLatLng = new L.LatLng(latitude, longitude);
|
||||
marker = L.marker(markerLatLng, {
|
||||
icon: markerIcon,
|
||||
draggable: editable
|
||||
});
|
||||
if (editable) {
|
||||
marker.on("dragend", updateFormfields);
|
||||
}
|
||||
marker.addTo(map);
|
||||
return marker;
|
||||
};
|
||||
removeMarker = function(e) {
|
||||
e.preventDefault();
|
||||
if (marker) {
|
||||
map.removeLayer(marker);
|
||||
marker = null;
|
||||
}
|
||||
clearFormfields();
|
||||
};
|
||||
moveOrPlaceMarker = function(e) {
|
||||
if (marker) {
|
||||
marker.setLatLng(e.latlng);
|
||||
} else {
|
||||
marker = createMarker(e.latlng.lat, e.latlng.lng);
|
||||
}
|
||||
updateFormfields();
|
||||
};
|
||||
updateFormfields = function() {
|
||||
$(latitudeInputSelector).val(marker.getLatLng().lat);
|
||||
$(longitudeInputSelector).val(marker.getLatLng().lng);
|
||||
$(zoomInputSelector).val(map.getZoom());
|
||||
};
|
||||
clearFormfields = function() {
|
||||
$(latitudeInputSelector).val("");
|
||||
$(longitudeInputSelector).val("");
|
||||
$(zoomInputSelector).val("");
|
||||
};
|
||||
openMarkerPopup = function(e) {
|
||||
marker = e.target;
|
||||
$.ajax("/investments/" + marker.options.id + "/json_data", {
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
e.target.bindPopup(getPopupContent(data)).openPopup();
|
||||
}
|
||||
});
|
||||
};
|
||||
getPopupContent = function(data) {
|
||||
return "<a href='/budgets/" + data.budget_id + "/investments/" + data.investment_id + "'>" + data.investment_title + "</a>";
|
||||
};
|
||||
mapCenterLatLng = new L.LatLng(mapCenterLatitude, mapCenterLongitude);
|
||||
map = L.map(element.id).setView(mapCenterLatLng, zoom);
|
||||
L.tileLayer(mapTilesProvider, {
|
||||
attribution: mapAttribution
|
||||
}).addTo(map);
|
||||
if (markerLatitude && markerLongitude && !addMarkerInvestments) {
|
||||
marker = createMarker(markerLatitude, markerLongitude);
|
||||
}
|
||||
if (editable) {
|
||||
$(removeMarkerSelector).on("click", removeMarker);
|
||||
map.on("zoomend", updateFormfields);
|
||||
map.on("click", moveOrPlaceMarker);
|
||||
}
|
||||
if (addMarkerInvestments) {
|
||||
addMarkerInvestments.forEach(function(coordinates) {
|
||||
if (App.Map.validCoordinates(coordinates)) {
|
||||
marker = createMarker(coordinates.lat, coordinates.long);
|
||||
marker.options.id = coordinates.investment_id;
|
||||
marker.on("click", openMarkerPopup);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
toggleMap: function() {
|
||||
$(".map").toggle();
|
||||
$(".js-location-map-remove-marker").toggle();
|
||||
},
|
||||
cleanInvestmentCoordinates: function(element) {
|
||||
var clean_markers, markers;
|
||||
markers = $(element).attr("data-marker-investments-coordinates");
|
||||
if (markers != null) {
|
||||
clean_markers = markers.replace(/-?(\*+)/g, null);
|
||||
$(element).attr("data-marker-investments-coordinates", clean_markers);
|
||||
}
|
||||
},
|
||||
validCoordinates: function(coordinates) {
|
||||
return App.Map.isNumeric(coordinates.lat) && App.Map.isNumeric(coordinates.long);
|
||||
},
|
||||
isNumeric: function(n) {
|
||||
return !isNaN(parseFloat(n)) && isFinite(n);
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,120 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.Map =
|
||||
|
||||
initialize: ->
|
||||
$("*[data-map]").each ->
|
||||
App.Map.initializeMap(this)
|
||||
|
||||
$(".js-toggle-map").on
|
||||
click: ->
|
||||
App.Map.toggleMap()
|
||||
|
||||
initializeMap: (element) ->
|
||||
App.Map.cleanInvestmentCoordinates(element)
|
||||
|
||||
mapCenterLatitude = $(element).data("map-center-latitude")
|
||||
mapCenterLongitude = $(element).data("map-center-longitude")
|
||||
markerLatitude = $(element).data("marker-latitude")
|
||||
markerLongitude = $(element).data("marker-longitude")
|
||||
zoom = $(element).data("map-zoom")
|
||||
mapTilesProvider = $(element).data("map-tiles-provider")
|
||||
mapAttribution = $(element).data("map-tiles-provider-attribution")
|
||||
latitudeInputSelector = $(element).data("latitude-input-selector")
|
||||
longitudeInputSelector = $(element).data("longitude-input-selector")
|
||||
zoomInputSelector = $(element).data("zoom-input-selector")
|
||||
removeMarkerSelector = $(element).data("marker-remove-selector")
|
||||
addMarkerInvestments = $(element).data("marker-investments-coordinates")
|
||||
editable = $(element).data("marker-editable")
|
||||
marker = null
|
||||
markerIcon = L.divIcon(
|
||||
className: "map-marker"
|
||||
iconSize: [30, 30]
|
||||
iconAnchor: [15, 40]
|
||||
html: '<div class="map-icon"></div>'
|
||||
)
|
||||
|
||||
createMarker = (latitude, longitude) ->
|
||||
markerLatLng = new (L.LatLng)(latitude, longitude)
|
||||
marker = L.marker(markerLatLng, { icon: markerIcon, draggable: editable })
|
||||
if editable
|
||||
marker.on "dragend", updateFormfields
|
||||
marker.addTo(map)
|
||||
return marker
|
||||
|
||||
removeMarker = (e) ->
|
||||
e.preventDefault()
|
||||
if marker
|
||||
map.removeLayer(marker)
|
||||
marker = null
|
||||
clearFormfields()
|
||||
return
|
||||
|
||||
moveOrPlaceMarker = (e) ->
|
||||
if marker
|
||||
marker.setLatLng(e.latlng)
|
||||
else
|
||||
marker = createMarker(e.latlng.lat, e.latlng.lng)
|
||||
|
||||
updateFormfields()
|
||||
return
|
||||
|
||||
updateFormfields = ->
|
||||
$(latitudeInputSelector).val marker.getLatLng().lat
|
||||
$(longitudeInputSelector).val marker.getLatLng().lng
|
||||
$(zoomInputSelector).val map.getZoom()
|
||||
return
|
||||
|
||||
clearFormfields = ->
|
||||
$(latitudeInputSelector).val ""
|
||||
$(longitudeInputSelector).val ""
|
||||
$(zoomInputSelector).val ""
|
||||
return
|
||||
|
||||
openMarkerPopup = (e) ->
|
||||
marker = e.target
|
||||
|
||||
$.ajax "/investments/#{marker.options["id"]}/json_data",
|
||||
type: "GET"
|
||||
dataType: "json"
|
||||
success: (data) ->
|
||||
e.target.bindPopup(getPopupContent(data)).openPopup()
|
||||
|
||||
getPopupContent = (data) ->
|
||||
"<a href='/budgets/#{data["budget_id"]}/investments/#{data["investment_id"]}'>#{data["investment_title"]}</a>"
|
||||
|
||||
mapCenterLatLng = new (L.LatLng)(mapCenterLatitude, mapCenterLongitude)
|
||||
map = L.map(element.id).setView(mapCenterLatLng, zoom)
|
||||
L.tileLayer(mapTilesProvider, attribution: mapAttribution).addTo map
|
||||
|
||||
if markerLatitude && markerLongitude && !addMarkerInvestments
|
||||
marker = createMarker(markerLatitude, markerLongitude)
|
||||
|
||||
if editable
|
||||
$(removeMarkerSelector).on "click", removeMarker
|
||||
map.on "zoomend", updateFormfields
|
||||
map.on "click", moveOrPlaceMarker
|
||||
|
||||
if addMarkerInvestments
|
||||
addMarkerInvestments.forEach (coordinates) ->
|
||||
if App.Map.validCoordinates(coordinates)
|
||||
marker = createMarker(coordinates.lat, coordinates.long)
|
||||
marker.options["id"] = coordinates.investment_id
|
||||
|
||||
marker.on "click", openMarkerPopup
|
||||
|
||||
toggleMap: ->
|
||||
$(".map").toggle()
|
||||
$(".js-location-map-remove-marker").toggle()
|
||||
|
||||
cleanInvestmentCoordinates: (element) ->
|
||||
markers = $(element).attr("data-marker-investments-coordinates")
|
||||
if markers?
|
||||
clean_markers = markers.replace(/-?(\*+)/g, null)
|
||||
$(element).attr("data-marker-investments-coordinates", clean_markers)
|
||||
|
||||
validCoordinates: (coordinates) ->
|
||||
App.Map.isNumeric(coordinates.lat) && App.Map.isNumeric(coordinates.long)
|
||||
|
||||
isNumeric: (n) ->
|
||||
!isNaN(parseFloat(n)) && isFinite(n)
|
||||
51
app/assets/javascripts/markdown_editor.js
Normal file
51
app/assets/javascripts/markdown_editor.js
Normal file
@@ -0,0 +1,51 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.MarkdownEditor = {
|
||||
refresh_preview: function(element, md) {
|
||||
var result, textarea_content;
|
||||
textarea_content = App.MarkdownEditor.find_textarea(element).val();
|
||||
result = md.render(textarea_content);
|
||||
element.find(".markdown-preview").html(result);
|
||||
},
|
||||
// Multi-locale (translatable) form fields work by hiding inputs of locales
|
||||
// which are not "active".
|
||||
find_textarea: function(editor) {
|
||||
return editor.find("textarea");
|
||||
},
|
||||
initialize: function() {
|
||||
$(".markdown-editor").each(function() {
|
||||
var editor, md;
|
||||
md = window.markdownit({
|
||||
html: true,
|
||||
breaks: true,
|
||||
typographer: true
|
||||
});
|
||||
editor = $(this);
|
||||
editor.on("input", function() {
|
||||
App.MarkdownEditor.refresh_preview($(this), md);
|
||||
$(".legislation-draft-versions-edit .warning").show();
|
||||
});
|
||||
editor.find("textarea").on("scroll", function() {
|
||||
editor.find(".markdown-preview").scrollTop($(this).scrollTop());
|
||||
});
|
||||
editor.find(".fullscreen-toggle").on("click", function() {
|
||||
var span;
|
||||
editor.toggleClass("fullscreen");
|
||||
$(".fullscreen-container").toggleClass("medium-8", "medium-12");
|
||||
span = $(this).find("span");
|
||||
if (span.html() === span.data("open-text")) {
|
||||
span.html(span.data("closed-text"));
|
||||
} else {
|
||||
span.html(span.data("open-text"));
|
||||
}
|
||||
if (editor.hasClass("fullscreen")) {
|
||||
App.MarkdownEditor.find_textarea(editor).height($(window).height() - 100);
|
||||
App.MarkdownEditor.refresh_preview(editor, md);
|
||||
} else {
|
||||
App.MarkdownEditor.find_textarea(editor).height("10em");
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,47 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.MarkdownEditor =
|
||||
|
||||
refresh_preview: (element, md) ->
|
||||
textarea_content = App.MarkdownEditor.find_textarea(element).val()
|
||||
result = md.render(textarea_content)
|
||||
element.find(".markdown-preview").html(result)
|
||||
|
||||
# Multi-locale (translatable) form fields work by hiding inputs of locales
|
||||
# which are not "active".
|
||||
find_textarea: (editor) ->
|
||||
editor.find("textarea")
|
||||
|
||||
initialize: ->
|
||||
$(".markdown-editor").each ->
|
||||
md = window.markdownit({
|
||||
html: true,
|
||||
breaks: true,
|
||||
typographer: true,
|
||||
})
|
||||
|
||||
editor = $(this)
|
||||
|
||||
editor.on "input", ->
|
||||
App.MarkdownEditor.refresh_preview($(this), md)
|
||||
$(".legislation-draft-versions-edit .warning").show()
|
||||
return
|
||||
|
||||
editor.find("textarea").on "scroll", ->
|
||||
editor.find(".markdown-preview").scrollTop($(this).scrollTop())
|
||||
|
||||
editor.find(".fullscreen-toggle").on "click", ->
|
||||
editor.toggleClass("fullscreen")
|
||||
$(".fullscreen-container").toggleClass("medium-8", "medium-12")
|
||||
span = $(this).find("span")
|
||||
|
||||
if(span.html() == span.data("open-text"))
|
||||
span.html(span.data("closed-text"))
|
||||
else
|
||||
span.html(span.data("open-text"))
|
||||
|
||||
if editor.hasClass("fullscreen")
|
||||
App.MarkdownEditor.find_textarea(editor).height($(window).height() - 100)
|
||||
App.MarkdownEditor.refresh_preview(editor, md)
|
||||
else
|
||||
App.MarkdownEditor.find_textarea(editor).height("10em")
|
||||
14
app/assets/javascripts/modal_download.js
Normal file
14
app/assets/javascripts/modal_download.js
Normal file
@@ -0,0 +1,14 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.ModalDownload = {
|
||||
enableButton: function() {
|
||||
$("#js-download-modal-submit").attr("disabled", false);
|
||||
$("#js-download-modal-submit").removeClass("disabled");
|
||||
},
|
||||
initialize: function() {
|
||||
$("#js-download-modal-submit").on("click", function() {
|
||||
setTimeout(App.ModalDownload.enableButton, 2000);
|
||||
});
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,11 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.ModalDownload =
|
||||
|
||||
enableButton: ->
|
||||
$("#js-download-modal-submit").attr("disabled", false)
|
||||
$("#js-download-modal-submit").removeClass("disabled")
|
||||
|
||||
initialize: ->
|
||||
$("#js-download-modal-submit").on "click", ->
|
||||
setTimeout(App.ModalDownload.enableButton, 2000)
|
||||
12
app/assets/javascripts/moderator_budget_investments.js
Normal file
12
app/assets/javascripts/moderator_budget_investments.js
Normal file
@@ -0,0 +1,12 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.ModeratorBudgetInvestments = {
|
||||
add_class_faded: function(id) {
|
||||
$("#" + id).addClass("faded");
|
||||
$("#comments").addClass("faded");
|
||||
},
|
||||
hide_moderator_actions: function(id) {
|
||||
$("#" + id + " .js-moderator-investment-actions:first").hide();
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,10 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.ModeratorBudgetInvestments =
|
||||
|
||||
add_class_faded: (id) ->
|
||||
$("##{id}").addClass("faded")
|
||||
$("#comments").addClass("faded")
|
||||
|
||||
hide_moderator_actions: (id) ->
|
||||
$("##{id} .js-moderator-investment-actions:first").hide()
|
||||
11
app/assets/javascripts/moderator_comment.js
Normal file
11
app/assets/javascripts/moderator_comment.js
Normal file
@@ -0,0 +1,11 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.ModeratorComments = {
|
||||
add_class_faded: function(id) {
|
||||
$("#" + id + " .comment-body:first").addClass("faded");
|
||||
},
|
||||
hide_moderator_actions: function(id) {
|
||||
$("#" + id + " .js-moderator-comment-actions").hide();
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,9 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.ModeratorComments =
|
||||
|
||||
add_class_faded: (id) ->
|
||||
$("##{id} .comment-body:first").addClass("faded")
|
||||
|
||||
hide_moderator_actions: (id) ->
|
||||
$("##{id} .js-moderator-comment-actions").hide()
|
||||
12
app/assets/javascripts/moderator_debates.js
Normal file
12
app/assets/javascripts/moderator_debates.js
Normal file
@@ -0,0 +1,12 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.ModeratorDebates = {
|
||||
add_class_faded: function(id) {
|
||||
$("#" + id).addClass("faded");
|
||||
$("#comments").addClass("faded");
|
||||
},
|
||||
hide_moderator_actions: function(id) {
|
||||
$("#" + id + " .js-moderator-debate-actions:first").hide();
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,10 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.ModeratorDebates =
|
||||
|
||||
add_class_faded: (id) ->
|
||||
$("##{id}").addClass("faded")
|
||||
$("#comments").addClass("faded")
|
||||
|
||||
hide_moderator_actions: (id) ->
|
||||
$("##{id} .js-moderator-debate-actions:first").hide()
|
||||
11
app/assets/javascripts/moderator_proposal_notifications.js
Normal file
11
app/assets/javascripts/moderator_proposal_notifications.js
Normal file
@@ -0,0 +1,11 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.ModeratorProposalNotifications = {
|
||||
add_class_faded: function(id) {
|
||||
$("#" + id).addClass("faded");
|
||||
},
|
||||
hide_moderator_actions: function(id) {
|
||||
$("#" + id + " .js-moderator-proposal-notifications-actions:first").hide();
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,9 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.ModeratorProposalNotifications =
|
||||
|
||||
add_class_faded: (id) ->
|
||||
$("##{id}").addClass("faded")
|
||||
|
||||
hide_moderator_actions: (id) ->
|
||||
$("##{id} .js-moderator-proposal-notifications-actions:first").hide()
|
||||
12
app/assets/javascripts/moderator_proposals.js
Normal file
12
app/assets/javascripts/moderator_proposals.js
Normal file
@@ -0,0 +1,12 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.ModeratorProposals = {
|
||||
add_class_faded: function(id) {
|
||||
$("#" + id).addClass("faded");
|
||||
$("#comments").addClass("faded");
|
||||
},
|
||||
hide_moderator_actions: function(id) {
|
||||
$("#" + id + " .js-moderator-proposals-actions:first").hide();
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,10 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.ModeratorProposals =
|
||||
|
||||
add_class_faded: (id) ->
|
||||
$("##{id}").addClass("faded")
|
||||
$("#comments").addClass("faded")
|
||||
|
||||
hide_moderator_actions: (id) ->
|
||||
$("##{id} .js-moderator-proposals-actions:first").hide()
|
||||
46
app/assets/javascripts/polls.js
Normal file
46
app/assets/javascripts/polls.js
Normal file
@@ -0,0 +1,46 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.Polls = {
|
||||
generateToken: function() {
|
||||
var strings;
|
||||
strings = Array.apply(null, {
|
||||
length: 6
|
||||
}).map(function() {
|
||||
return Math.random().toString(36).substr(2); // remove `0.`
|
||||
});
|
||||
return strings.join("").substring(0, 64);
|
||||
},
|
||||
replaceToken: function(token) {
|
||||
$(".js-question-answer").each(function() {
|
||||
var token_param;
|
||||
token_param = this.search.slice(-6);
|
||||
if (token_param === "token=") {
|
||||
this.href = this.href + token;
|
||||
}
|
||||
});
|
||||
},
|
||||
initialize: function() {
|
||||
var token;
|
||||
token = App.Polls.generateToken();
|
||||
App.Polls.replaceToken(token);
|
||||
$(".zoom-link").on("click", function(event) {
|
||||
var answer;
|
||||
answer = $(event.target).closest("div.answer");
|
||||
|
||||
if ($(answer).hasClass("medium-6")) {
|
||||
$(answer).removeClass("medium-6");
|
||||
$(answer).addClass("answer-divider");
|
||||
if (!$(answer).hasClass("first")) {
|
||||
$(answer).insertBefore($(answer).prev("div.answer"));
|
||||
}
|
||||
} else {
|
||||
$(answer).addClass("medium-6");
|
||||
$(answer).removeClass("answer-divider");
|
||||
if (!$(answer).hasClass("first")) {
|
||||
$(answer).insertAfter($(answer).next("div.answer"));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,32 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.Polls =
|
||||
generateToken: ->
|
||||
strings = Array.apply(null, length: 6).map ->
|
||||
Math.random().toString(36).substr(2) # remove `0.`
|
||||
|
||||
strings.join("").substring(0, 64)
|
||||
|
||||
replaceToken: (token) ->
|
||||
$(".js-question-answer").each ->
|
||||
token_param = this.search.slice(-6)
|
||||
if token_param == "token="
|
||||
this.href = this.href + token
|
||||
|
||||
initialize: ->
|
||||
token = App.Polls.generateToken()
|
||||
App.Polls.replaceToken(token)
|
||||
|
||||
$(".zoom-link").on "click", (event) ->
|
||||
answer = $(event.target).closest("div.answer")
|
||||
|
||||
if $(answer).hasClass("medium-6")
|
||||
$(answer).removeClass("medium-6")
|
||||
$(answer).addClass("answer-divider")
|
||||
unless $(answer).hasClass("first")
|
||||
$(answer).insertBefore($(answer).prev("div.answer"))
|
||||
else
|
||||
$(answer).addClass("medium-6")
|
||||
$(answer).removeClass("answer-divider")
|
||||
unless $(answer).hasClass("first")
|
||||
$(answer).insertAfter($(answer).next("div.answer"))
|
||||
20
app/assets/javascripts/polls_admin.js
Normal file
20
app/assets/javascripts/polls_admin.js
Normal file
@@ -0,0 +1,20 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.PollsAdmin = {
|
||||
initialize: function() {
|
||||
$("select[class='js-poll-shifts']").on({
|
||||
change: function() {
|
||||
switch ($(this).val()) {
|
||||
case "vote_collection":
|
||||
$("select[class='js-shift-vote-collection-dates']").show();
|
||||
$("select[class='js-shift-recount-scrutiny-dates']").hide();
|
||||
break;
|
||||
case "recount_scrutiny":
|
||||
$("select[class='js-shift-recount-scrutiny-dates']").show();
|
||||
$("select[class='js-shift-vote-collection-dates']").hide();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,15 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.PollsAdmin =
|
||||
|
||||
initialize: ->
|
||||
$("select[class='js-poll-shifts']").on
|
||||
change: ->
|
||||
switch ($(this).val())
|
||||
when "vote_collection"
|
||||
$("select[class='js-shift-vote-collection-dates']").show()
|
||||
$("select[class='js-shift-recount-scrutiny-dates']").hide()
|
||||
break
|
||||
when "recount_scrutiny"
|
||||
$("select[class='js-shift-recount-scrutiny-dates']").show()
|
||||
$("select[class='js-shift-vote-collection-dates']").hide()
|
||||
48
app/assets/javascripts/prevent_double_submission.js
Normal file
48
app/assets/javascripts/prevent_double_submission.js
Normal file
@@ -0,0 +1,48 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.PreventDoubleSubmission = {
|
||||
disable_buttons: function(buttons) {
|
||||
setTimeout(function() {
|
||||
buttons.each(function() {
|
||||
var button, loading, ref;
|
||||
button = $(this);
|
||||
if (!button.hasClass("disabled")) {
|
||||
loading = (ref = button.data("loading")) != null ? ref : "...";
|
||||
button.addClass("disabled").attr("disabled", "disabled");
|
||||
button.data("text", button.val());
|
||||
button.val(loading);
|
||||
}
|
||||
});
|
||||
}, 1);
|
||||
},
|
||||
reset_buttons: function(buttons) {
|
||||
buttons.each(function() {
|
||||
var button, button_text;
|
||||
button = $(this);
|
||||
if (button.hasClass("disabled")) {
|
||||
button_text = button.data("text");
|
||||
button.removeClass("disabled").attr("disabled", null);
|
||||
if (button_text) {
|
||||
button.val(button_text);
|
||||
button.data("text", null);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
initialize: function() {
|
||||
$("form").on("submit", function(event) {
|
||||
var buttons;
|
||||
if (!(event.target.id === "new_officing_voter" || event.target.id === "admin_download_emails")) {
|
||||
buttons = $(this).find(":button, :submit");
|
||||
App.PreventDoubleSubmission.disable_buttons(buttons);
|
||||
}
|
||||
}).on("ajax:success", function(event) {
|
||||
var buttons;
|
||||
if (!(event.target.id === "new_officing_voter" || event.target.id === "admin_download_emails")) {
|
||||
buttons = $(this).find(":button, :submit");
|
||||
App.PreventDoubleSubmission.reset_buttons(buttons);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,38 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.PreventDoubleSubmission =
|
||||
disable_buttons: (buttons) ->
|
||||
setTimeout ->
|
||||
buttons.each ->
|
||||
button = $(this)
|
||||
unless button.hasClass("disabled")
|
||||
loading = button.data("loading") ? "..."
|
||||
button.addClass("disabled").attr("disabled", "disabled")
|
||||
button.data("text", button.val())
|
||||
button.val(loading)
|
||||
, 1
|
||||
|
||||
reset_buttons: (buttons) ->
|
||||
buttons.each ->
|
||||
button = $(this)
|
||||
if button.hasClass("disabled")
|
||||
button_text = button.data("text")
|
||||
button.removeClass("disabled").attr("disabled", null)
|
||||
if button_text
|
||||
button.val(button_text)
|
||||
button.data("text", null)
|
||||
|
||||
initialize: ->
|
||||
$("form").on("submit", (event) ->
|
||||
unless event.target.id == "new_officing_voter" ||
|
||||
event.target.id == "admin_download_emails"
|
||||
|
||||
buttons = $(this).find(":button, :submit")
|
||||
App.PreventDoubleSubmission.disable_buttons(buttons)
|
||||
).on("ajax:success", (event) ->
|
||||
unless event.target.id == "new_officing_voter" ||
|
||||
event.target.id == "admin_download_emails"
|
||||
|
||||
buttons = $(this).find(":button, :submit")
|
||||
App.PreventDoubleSubmission.reset_buttons(buttons)
|
||||
)
|
||||
13
app/assets/javascripts/questions.js
Normal file
13
app/assets/javascripts/questions.js
Normal file
@@ -0,0 +1,13 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.Questions = {
|
||||
nestedQuestions: function() {
|
||||
$(".js-questions").on("cocoon:after-insert", function(e, new_question) {
|
||||
App.Answers.initializeAnswers($(new_question).find(".js-answers"));
|
||||
});
|
||||
},
|
||||
initialize: function() {
|
||||
App.Questions.nestedQuestions();
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,10 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.Questions =
|
||||
|
||||
nestedQuestions: ->
|
||||
$(".js-questions").on "cocoon:after-insert", (e, new_question) ->
|
||||
App.Answers.initializeAnswers($(new_question).find(".js-answers"))
|
||||
|
||||
initialize: ->
|
||||
App.Questions.nestedQuestions()
|
||||
32
app/assets/javascripts/registration_form.js
Normal file
32
app/assets/javascripts/registration_form.js
Normal file
@@ -0,0 +1,32 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.RegistrationForm = {
|
||||
initialize: function() {
|
||||
var clearUsernameMessage, showUsernameMessage, usernameInput, validateUsername;
|
||||
usernameInput = $("form#new_user[action=\"/users\"] input#user_username");
|
||||
clearUsernameMessage = function() {
|
||||
$("small").remove();
|
||||
};
|
||||
showUsernameMessage = function(response) {
|
||||
var klass;
|
||||
klass = response.available ? "no-error" : "error";
|
||||
usernameInput.after($("<small class=\"" + klass + "\" style=\"margin-top: -16px;\">" + response.message + "</small>"));
|
||||
};
|
||||
validateUsername = function(username) {
|
||||
var request;
|
||||
request = $.get("/user/registrations/check_username?username=" + username);
|
||||
request.done(function(response) {
|
||||
showUsernameMessage(response);
|
||||
});
|
||||
};
|
||||
usernameInput.on("focusout", function() {
|
||||
var username;
|
||||
clearUsernameMessage();
|
||||
username = usernameInput.val();
|
||||
if (username !== "") {
|
||||
validateUsername(username);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,24 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.RegistrationForm =
|
||||
|
||||
initialize: ->
|
||||
usernameInput = $("form#new_user[action=\"/users\"] input#user_username")
|
||||
|
||||
clearUsernameMessage = ->
|
||||
$("small").remove()
|
||||
|
||||
showUsernameMessage = (response) ->
|
||||
klass = if response.available then "no-error" else "error"
|
||||
usernameInput.after $("<small class=\"#{klass}\" style=\"margin-top: -16px;\">#{response.message}</small>")
|
||||
|
||||
validateUsername = (username) ->
|
||||
request = $.get "/user/registrations/check_username?username=#{username}"
|
||||
request.done (response) ->
|
||||
showUsernameMessage(response)
|
||||
|
||||
|
||||
usernameInput.on "focusout", ->
|
||||
clearUsernameMessage()
|
||||
username = usernameInput.val()
|
||||
validateUsername(username) if username != ""
|
||||
10
app/assets/javascripts/send_admin_notification_alert.js
Normal file
10
app/assets/javascripts/send_admin_notification_alert.js
Normal file
@@ -0,0 +1,10 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.SendAdminNotificationAlert = {
|
||||
initialize: function() {
|
||||
$("#js-send-admin_notification-alert").on("click", function() {
|
||||
return confirm(this.dataset.alert);
|
||||
});
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,6 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.SendAdminNotificationAlert =
|
||||
initialize: ->
|
||||
$("#js-send-admin_notification-alert").on "click", ->
|
||||
confirm(this.dataset.alert)
|
||||
10
app/assets/javascripts/send_newsletter_alert.js
Normal file
10
app/assets/javascripts/send_newsletter_alert.js
Normal file
@@ -0,0 +1,10 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.SendNewsletterAlert = {
|
||||
initialize: function() {
|
||||
$("#js-send-newsletter-alert").on("click", function() {
|
||||
return confirm(this.dataset.alert);
|
||||
});
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,6 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.SendNewsletterAlert =
|
||||
initialize: ->
|
||||
$("#js-send-newsletter-alert").on "click", ->
|
||||
confirm(this.dataset.alert)
|
||||
17
app/assets/javascripts/settings.js
Normal file
17
app/assets/javascripts/settings.js
Normal file
@@ -0,0 +1,17 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.Settings = {
|
||||
initialize: function() {
|
||||
$("#settings-tabs").on("change.zf.tabs", function() {
|
||||
var map_container;
|
||||
if ($("#tab-map-configuration:visible").length) {
|
||||
map_container = L.DomUtil.get("admin-map");
|
||||
if (map_container !== null) {
|
||||
map_container._leaflet_id = null;
|
||||
}
|
||||
App.Map.initialize();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,12 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.Settings =
|
||||
|
||||
initialize: ->
|
||||
|
||||
$("#settings-tabs").on "change.zf.tabs", ->
|
||||
if $("#tab-map-configuration:visible").length
|
||||
map_container = L.DomUtil.get "admin-map"
|
||||
unless map_container is null
|
||||
map_container._leaflet_id = null
|
||||
App.Map.initialize()
|
||||
10
app/assets/javascripts/social_share.js
Normal file
10
app/assets/javascripts/social_share.js
Normal file
@@ -0,0 +1,10 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.SocialShare = {
|
||||
initialize: function() {
|
||||
$(".social-share-button a").each(function() {
|
||||
$(this).append("<span class='show-for-sr'>" + ($(this).data("site")) + "</span>");
|
||||
});
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
@@ -1,7 +0,0 @@
|
||||
"use strict"
|
||||
|
||||
App.SocialShare =
|
||||
|
||||
initialize: ->
|
||||
$(".social-share-button a").each ->
|
||||
$(this).append("<span class='show-for-sr'>#{$(this).data("site")}</span>")
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user