Merge pull request #3651 from consul/simplify_coffeescript
Clean up CoffeeScript code
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.AdvancedSearch =
|
||||
|
||||
advanced_search_terms: ->
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.AllowParticipation =
|
||||
|
||||
initialize: ->
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
"use strict"
|
||||
|
||||
App.Answers =
|
||||
|
||||
initializeAnswers: (answers) ->
|
||||
$(answers).on 'cocoon:after-insert', (e, new_answer) ->
|
||||
$(answers).on "cocoon:after-insert", (e, new_answer) ->
|
||||
given_order = App.Answers.maxGivenOrder(answers) + 1
|
||||
$(new_answer).find("[name$='[given_order]']").val(given_order)
|
||||
|
||||
@@ -13,7 +15,7 @@ App.Answers =
|
||||
return max_order
|
||||
|
||||
nestedAnswers: ->
|
||||
$('.js-answers').each (index, answers) ->
|
||||
$(".js-answers").each (index, answers) ->
|
||||
App.Answers.initializeAnswers(answers)
|
||||
|
||||
initialize: ->
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
"use strict"
|
||||
|
||||
window.App = {}
|
||||
|
||||
@@ -88,6 +88,8 @@
|
||||
//= require votations
|
||||
|
||||
var initialize_modules = function() {
|
||||
"use strict";
|
||||
|
||||
App.Answers.initialize();
|
||||
App.Questions.initialize();
|
||||
App.Comments.initialize();
|
||||
@@ -133,7 +135,7 @@ 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 )
|
||||
@@ -141,6 +143,8 @@ var initialize_modules = function() {
|
||||
};
|
||||
|
||||
$(function(){
|
||||
"use strict";
|
||||
|
||||
Turbolinks.enableProgressBar();
|
||||
|
||||
$(document).ready(initialize_modules);
|
||||
|
||||
@@ -1,28 +1,20 @@
|
||||
"use strict"
|
||||
|
||||
App.Banners =
|
||||
|
||||
update_banner: (selector, text) ->
|
||||
$(selector).html(text)
|
||||
|
||||
update_background_color: (selector, background_color) ->
|
||||
$(selector).css("background-color", background_color)
|
||||
|
||||
update_font_color: (selector, font_color) ->
|
||||
$(selector).css("color", font_color)
|
||||
|
||||
initialize: ->
|
||||
$("[data-js-banner-title]").on
|
||||
change: ->
|
||||
App.Banners.update_banner("#js-banner-title", $(this).val())
|
||||
$("#js-banner-title").html($(this).val())
|
||||
|
||||
$("[data-js-banner-description]").on
|
||||
change: ->
|
||||
App.Banners.update_banner("#js-banner-description", $(this).val())
|
||||
$("#js-banner-description").html($(this).val())
|
||||
|
||||
$("[name='banner[background_color]']").on
|
||||
change: ->
|
||||
App.Banners.update_background_color("#js-banner-background", $(this).val())
|
||||
$("#js-banner-background").css("background-color", $(this).val())
|
||||
|
||||
$("[name='banner[font_color]']").on
|
||||
change: ->
|
||||
App.Banners.update_font_color("#js-banner-title", $(this).val())
|
||||
App.Banners.update_font_color("#js-banner-description", $(this).val())
|
||||
$("#js-banner-title").css("color", $(this).val())
|
||||
$("#js-banner-description").css("color", $(this).val())
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.BudgetEditAssociations =
|
||||
|
||||
set_text: (response)->
|
||||
@@ -19,7 +21,6 @@ App.BudgetEditAssociations =
|
||||
$(".js-budget-show-users-list").on
|
||||
click: ->
|
||||
div_id = $(this).data().toggle
|
||||
for list in $(".js-budget-users-list")
|
||||
do ->
|
||||
if (list.id != div_id)
|
||||
$(list).addClass("is-hidden") if !$(list).hasClass("is-hidden")
|
||||
$(".js-budget-users-list").each ->
|
||||
if this.id != div_id && !$(this).hasClass("is-hidden")
|
||||
$(this).addClass("is-hidden")
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.CheckAllNone =
|
||||
|
||||
initialize: ->
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
"use strict"
|
||||
|
||||
App.CheckboxToggle =
|
||||
|
||||
initialize: ->
|
||||
$("[data-checkbox-toggle]").on "change", ->
|
||||
$this = $(this)
|
||||
$target = $($this.data("checkbox-toggle"))
|
||||
if $this.is(":checked")
|
||||
$target = $($(this).data("checkbox-toggle"))
|
||||
if $(this).is(":checked")
|
||||
$target.show()
|
||||
else
|
||||
$target.hide()
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
//= require ckeditor/init
|
||||
|
||||
CKEDITOR.config.customConfig = "<%= javascript_path 'ckeditor/config.js' %>";
|
||||
CKEDITOR.config.customConfig = "<%= javascript_path "ckeditor/config.js" %>";
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.ColumnsSelector =
|
||||
|
||||
initColums: () ->
|
||||
@@ -9,15 +11,14 @@ App.ColumnsSelector =
|
||||
App.Cookies.saveCookie($("#js-columns-selector").data("cookie"), c_value, 30)
|
||||
columns = c_value.split(",")
|
||||
|
||||
for column in columns
|
||||
do ->
|
||||
$("[data-field=" + column + "]").removeClass("hidden")
|
||||
$("#column_selector_" + column).prop("checked", true)
|
||||
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 = $.trim($(this).text())
|
||||
text = $(this).text().trim()
|
||||
item = $("#column_selector_item_template").clone()
|
||||
item.prop("id", "column_selector_item_" + field)
|
||||
input = item.find("input")
|
||||
@@ -40,12 +41,10 @@ App.ColumnsSelector =
|
||||
$(".column-selector-item input").prop("checked", false)
|
||||
|
||||
toggleColumn: (event) ->
|
||||
column = $(event.target).data("column")
|
||||
App.ColumnsSelector.displayColumn(column)
|
||||
App.ColumnsSelector.displayColumn($(event.target).data("column"))
|
||||
|
||||
displayColumn: (column) ->
|
||||
item = $("#column_selector_" + column)
|
||||
if item.prop("checked")
|
||||
if $("#column_selector_" + column).prop("checked")
|
||||
$("[data-field=" + column + "]").removeClass("hidden")
|
||||
else
|
||||
$("[data-field=" + column + "]").addClass("hidden")
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.Comments =
|
||||
|
||||
add_comment: (parent_id, response_html) ->
|
||||
@@ -40,12 +42,9 @@ App.Comments =
|
||||
|
||||
initialize: ->
|
||||
$("body .js-add-comment-link").each ->
|
||||
$this = $(this)
|
||||
|
||||
unless $this.data("initialized") is "yes"
|
||||
$this.on("click", ->
|
||||
id = $(this).data().id
|
||||
App.Comments.toggle_form(id)
|
||||
unless $(this).data("initialized") is "yes"
|
||||
$(this).on("click", ->
|
||||
App.Comments.toggle_form($(this).data().id)
|
||||
false
|
||||
).data "initialized", "yes"
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.Cookies =
|
||||
|
||||
saveCookie: (name, value, days) ->
|
||||
@@ -5,19 +7,19 @@ App.Cookies =
|
||||
if days
|
||||
date = new Date
|
||||
date.setTime date.getTime() + days * 24 * 60 * 60 * 1000
|
||||
expires = '; expires=' + date.toGMTString()
|
||||
expires = "; expires=" + date.toGMTString()
|
||||
else
|
||||
expires = ''
|
||||
document.cookie = name + '=' + value + expires + '; path=/'
|
||||
expires = ""
|
||||
document.cookie = name + "=" + value + expires + "; path=/"
|
||||
return
|
||||
|
||||
getCookie: (name) ->
|
||||
if document.cookie.length > 0
|
||||
c_start = document.cookie.indexOf(name + '=')
|
||||
c_start = document.cookie.indexOf(name + "=")
|
||||
if c_start != -1
|
||||
c_start = c_start + name.length + 1
|
||||
c_end = document.cookie.indexOf(';', c_start)
|
||||
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))
|
||||
''
|
||||
""
|
||||
|
||||
@@ -5,7 +5,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(){
|
||||
'use strict';
|
||||
"use strict";
|
||||
|
||||
var ProposalGraph = function(url) {
|
||||
this.url = url;
|
||||
@@ -15,9 +15,9 @@
|
||||
this.groupBy = null;
|
||||
this.proposalSuccess = null;
|
||||
this.maximumValue = 0;
|
||||
this.progressLabel = 'Progress';
|
||||
this.supportsLabel = 'Supports';
|
||||
this.successLabel = 'Success';
|
||||
this.progressLabel = "Progress";
|
||||
this.supportsLabel = "Supports";
|
||||
this.successLabel = "Success";
|
||||
this.goals = null;
|
||||
this.achievements = null;
|
||||
this.xColumnValues = null;
|
||||
@@ -44,15 +44,12 @@
|
||||
};
|
||||
|
||||
ProposalGraph.prototype.parseGoals = function(data) {
|
||||
var i, l;
|
||||
|
||||
this.goals = [];
|
||||
for (i = 0, l = data.length; i < l; i += 1) {
|
||||
this.goals.push({
|
||||
value: data[i].required_supports,
|
||||
text: data[i].title
|
||||
});
|
||||
}
|
||||
this.goals = data.map(function(item) {
|
||||
return {
|
||||
value: item.required_supports,
|
||||
text: item.title
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
ProposalGraph.prototype.refreshData = function () {
|
||||
@@ -135,7 +132,7 @@
|
||||
this.achievements.push({
|
||||
value: this.formatGroup(group),
|
||||
text: data[group].title,
|
||||
position: 'start'
|
||||
position: "start"
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -153,13 +150,13 @@
|
||||
|
||||
this.formatXColumnValues();
|
||||
|
||||
colors[this.progressColumnValues[0]] = '#004a83';
|
||||
colors[this.successfulColumnValues[0]] = '#ff7f0e';
|
||||
colors[this.progressColumnValues[0]] = "#004a83";
|
||||
colors[this.successfulColumnValues[0]] = "#ff7f0e";
|
||||
|
||||
c3.generate({
|
||||
bindto: '#' + this.targetId,
|
||||
bindto: "#" + this.targetId,
|
||||
data: {
|
||||
x: 'x',
|
||||
x: "x",
|
||||
columns: [
|
||||
this.xColumnValues,
|
||||
this.progressColumnValues,
|
||||
@@ -169,7 +166,7 @@
|
||||
color: function (color, d) {
|
||||
var achievement;
|
||||
|
||||
if (d.id === this.successfulColumnValues[0] || !Object.prototype.hasOwnProperty.call(d, 'x')) {
|
||||
if (d.id === this.successfulColumnValues[0] || !Object.prototype.hasOwnProperty.call(d, "x")) {
|
||||
return color;
|
||||
}
|
||||
|
||||
@@ -178,7 +175,7 @@
|
||||
}.bind(this));
|
||||
|
||||
if (achievement !== undefined) {
|
||||
return '#ff0000';
|
||||
return "#ff0000";
|
||||
}
|
||||
|
||||
return color;
|
||||
@@ -193,11 +190,11 @@
|
||||
max: maximumValue,
|
||||
label: {
|
||||
text: this.supportsLabel,
|
||||
position: 'outer-middle'
|
||||
position: "outer-middle"
|
||||
}
|
||||
},
|
||||
x: {
|
||||
type: 'category',
|
||||
type: "category",
|
||||
tick: {
|
||||
values: this.tickXValues(),
|
||||
centered: true
|
||||
@@ -220,7 +217,7 @@
|
||||
}.bind(this));
|
||||
|
||||
if (achievement !== undefined) {
|
||||
return this.xColumnValues[d + 1] + ': ' + achievement.text;
|
||||
return this.xColumnValues[d + 1] + ": " + achievement.text;
|
||||
}
|
||||
|
||||
return this.xColumnValues[d + 1];
|
||||
@@ -273,7 +270,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
this.xColumnValues.unshift('x');
|
||||
this.xColumnValues.unshift("x");
|
||||
};
|
||||
|
||||
ProposalGraph.prototype.formatGroup = function(group) {
|
||||
@@ -286,21 +283,21 @@
|
||||
};
|
||||
|
||||
ProposalGraph.prototype.isDailyGrouped = function() {
|
||||
return this.groupBy === undefined || this.groupBy === '' || this.groupBy === null;
|
||||
return this.groupBy === undefined || this.groupBy === "" || this.groupBy === null;
|
||||
};
|
||||
|
||||
$(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');
|
||||
graph.targetId = $(this).attr('id');
|
||||
graph.groupBy = $(this).data('proposal-graph-group-by');
|
||||
graph.progressLabel = $(this).data('proposal-graph-progress-label');
|
||||
graph.supportsLabel = $(this).data('proposal-graph-supports-label');
|
||||
graph.successLabel = $(this).data('proposal-graph-success-label');
|
||||
graph.proposalSuccess = parseInt($(this).data('proposal-success'), 10);
|
||||
graph.resourcesUrl = $(this).data('proposal-resources-url');
|
||||
$("[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");
|
||||
graph.targetId = $(this).attr("id");
|
||||
graph.groupBy = $(this).data("proposal-graph-group-by");
|
||||
graph.progressLabel = $(this).data("proposal-graph-progress-label");
|
||||
graph.supportsLabel = $(this).data("proposal-graph-supports-label");
|
||||
graph.successLabel = $(this).data("proposal-graph-success-label");
|
||||
graph.proposalSuccess = parseInt($(this).data("proposal-success"), 10);
|
||||
graph.resourcesUrl = $(this).data("proposal-resources-url");
|
||||
|
||||
graph.refresh();
|
||||
});
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
"use strict"
|
||||
|
||||
App.Documentable =
|
||||
|
||||
initialize: ->
|
||||
|
||||
inputFiles = $(".js-document-attachment")
|
||||
$.each inputFiles, (index, input) ->
|
||||
App.Documentable.initializeDirectUploadInput(input)
|
||||
$(".js-document-attachment").each ->
|
||||
App.Documentable.initializeDirectUploadInput(this)
|
||||
|
||||
$("#nested-documents").on "cocoon:after-remove", ->
|
||||
App.Documentable.unlockUploads()
|
||||
@@ -17,9 +17,9 @@ App.Documentable =
|
||||
|
||||
initializeDirectUploadInput: (input) ->
|
||||
|
||||
inputData = @buildData([], input)
|
||||
inputData = this.buildData([], input)
|
||||
|
||||
@initializeRemoveCachedDocumentLink(input, inputData)
|
||||
this.initializeRemoveCachedDocumentLink(input, inputData)
|
||||
|
||||
$(input).fileupload
|
||||
|
||||
@@ -28,13 +28,13 @@ App.Documentable =
|
||||
formData: null
|
||||
|
||||
add: (e, data) ->
|
||||
data = App.Documentable.buildFileUploadData(e, data)
|
||||
App.Documentable.clearProgressBar(data)
|
||||
App.Documentable.setProgressBar(data, "uploading")
|
||||
data.submit()
|
||||
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) ->
|
||||
$.each data.files, (index, file) ->
|
||||
data.files.forEach (file) ->
|
||||
App.Documentable.setFilename(inputData, file.name)
|
||||
|
||||
fail: (e, data) ->
|
||||
@@ -72,10 +72,6 @@ App.Documentable =
|
||||
$(data.progressBar).find(".loading-bar").css "width", "#{progress}%"
|
||||
return
|
||||
|
||||
buildFileUploadData: (e, data) ->
|
||||
data = @buildData(data, e.target)
|
||||
return data
|
||||
|
||||
buildData: (data, input) ->
|
||||
wrapper = $(input).closest(".direct-upload")
|
||||
data.input = input
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.EmbedVideo =
|
||||
|
||||
initialize: ->
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.FixedBar =
|
||||
initialize: ->
|
||||
$("[data-fixed-bar]").each ->
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.Flaggable =
|
||||
|
||||
update: (resource_id, button) ->
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.Followable =
|
||||
|
||||
update: (followable_id, button, notice) ->
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
"use strict"
|
||||
|
||||
App.Forms =
|
||||
|
||||
disableEnter: ->
|
||||
$("form.js-enter-disabled").on("keyup keypress", (event) ->
|
||||
if event.which == 13
|
||||
e.preventDefault()
|
||||
event.preventDefault()
|
||||
)
|
||||
|
||||
submitOnChange: ->
|
||||
@@ -25,9 +27,7 @@ App.Forms =
|
||||
|
||||
synchronizeInputs: ->
|
||||
progress_bar = "[name='progress_bar[percentage]']"
|
||||
process_background = "[name='legislation_process[background_color]']"
|
||||
process_font = ", [name='legislation_process[font_color]']"
|
||||
processes = process_background + process_font
|
||||
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}")
|
||||
|
||||
@@ -1,24 +1,23 @@
|
||||
"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"
|
||||
|
||||
clearSticky = ->
|
||||
$("[data-sticky]").foundation("destroy") if $("[data-sticky]").length
|
||||
|
||||
$(document).on("page:before-unload", clearSticky)
|
||||
|
||||
window.addEventListener("popstate", clearSticky, false)
|
||||
|
||||
mobile_ui_init = ->
|
||||
$(window).trigger "load.zf.sticky"
|
||||
|
||||
desktop_ui_init = ->
|
||||
$(window).trigger "init.zf.sticky"
|
||||
$(document).on("page:before-unload", this.clearSticky)
|
||||
window.addEventListener("popstate", this.clearSticky, false)
|
||||
|
||||
$ ->
|
||||
if $(window).width() < 620
|
||||
do mobile_ui_init
|
||||
App.FoundationExtras.mobile_ui_init()
|
||||
else
|
||||
do desktop_ui_init
|
||||
App.FoundationExtras.desktop_ui_init()
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
i18n = {
|
||||
es: {
|
||||
"Comments": "Comentarios",
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.Globalize =
|
||||
|
||||
selected_language: ->
|
||||
@@ -87,17 +89,13 @@ App.Globalize =
|
||||
App.Globalize.update_description()
|
||||
|
||||
$(".js-select-language").on "change", ->
|
||||
locale = $(this).val()
|
||||
App.Globalize.display_translations(locale)
|
||||
App.Globalize.display_translations($(this).val())
|
||||
|
||||
$(".js-delete-language").on "click", (e) ->
|
||||
e.preventDefault()
|
||||
locale = $(this).data("locale")
|
||||
App.Globalize.remove_language($(this).data("locale"))
|
||||
$(this).hide()
|
||||
App.Globalize.remove_language(locale)
|
||||
|
||||
$(".js-add-fields-container").on "cocoon:after-insert", ->
|
||||
$.each(
|
||||
App.Globalize.enabled_locales(),
|
||||
(index, locale) -> App.Globalize.enable_locale(locale)
|
||||
)
|
||||
App.Globalize.enabled_locales().forEach (locale) ->
|
||||
App.Globalize.enable_locale(locale)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.IeAlert =
|
||||
set_cookie_and_hide: (event) ->
|
||||
event.preventDefault()
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
"use strict"
|
||||
|
||||
App.Imageable =
|
||||
|
||||
initialize: ->
|
||||
inputFiles = $(".js-image-attachment")
|
||||
$.each inputFiles, (index, input) ->
|
||||
App.Imageable.initializeDirectUploadInput(input)
|
||||
$(".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", ->
|
||||
if $(".js-image-attachment").length > 0
|
||||
$(".js-image-attachment").closest(".image").remove()
|
||||
$(".js-image-attachment").closest(".image").remove()
|
||||
|
||||
$("#nested-image").on "cocoon:after-insert", (e, nested_image) ->
|
||||
$("#new_image_link").addClass("hide")
|
||||
@@ -19,9 +19,9 @@ App.Imageable =
|
||||
|
||||
initializeDirectUploadInput: (input) ->
|
||||
|
||||
inputData = @buildData([], input)
|
||||
inputData = this.buildData([], input)
|
||||
|
||||
@initializeRemoveCachedImageLink(input, inputData)
|
||||
this.initializeRemoveCachedImageLink(input, inputData)
|
||||
|
||||
$(input).fileupload
|
||||
|
||||
@@ -30,13 +30,13 @@ App.Imageable =
|
||||
formData: null
|
||||
|
||||
add: (e, data) ->
|
||||
data = App.Imageable.buildFileUploadData(e, data)
|
||||
App.Imageable.clearProgressBar(data)
|
||||
App.Imageable.setProgressBar(data, "uploading")
|
||||
data.submit()
|
||||
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) ->
|
||||
$.each data.files, (index, file) ->
|
||||
data.files.forEach (file) ->
|
||||
App.Imageable.setFilename(inputData, file.name)
|
||||
|
||||
fail: (e, data) ->
|
||||
@@ -73,10 +73,6 @@ App.Imageable =
|
||||
$(data.progressBar).find(".loading-bar").css "width", "#{progress}%"
|
||||
return
|
||||
|
||||
buildFileUploadData: (e, data) ->
|
||||
data = @buildData(data, e.target)
|
||||
return data
|
||||
|
||||
buildData: (data, input) ->
|
||||
wrapper = $(input).closest(".direct-upload")
|
||||
data.input = input
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.InvestmentReportAlert =
|
||||
initialize: ->
|
||||
$("#js-investment-report-alert").on "click", ->
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.Legislation =
|
||||
|
||||
initialize: ->
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.LegislationAdmin =
|
||||
|
||||
initialize: ->
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.LegislationAllegations =
|
||||
|
||||
toggle_comments: ->
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.LegislationAnnotatable =
|
||||
|
||||
makeEditableAndHighlight: (colour) ->
|
||||
@@ -18,7 +20,7 @@ App.LegislationAnnotatable =
|
||||
try
|
||||
if !document.execCommand("BackColor", false, colour)
|
||||
App.LegislationAnnotatable.makeEditableAndHighlight colour
|
||||
catch ex
|
||||
catch
|
||||
App.LegislationAnnotatable.makeEditableAndHighlight colour
|
||||
|
||||
return
|
||||
@@ -85,7 +87,7 @@ App.LegislationAnnotatable =
|
||||
return
|
||||
|
||||
customShow: (position) ->
|
||||
$(@element).html ""
|
||||
$(this.element).html ""
|
||||
# Clean comments section and open it
|
||||
$("#comments-box").html ""
|
||||
App.LegislationAllegations.show_comments()
|
||||
@@ -96,8 +98,8 @@ App.LegislationAnnotatable =
|
||||
method: "GET"
|
||||
url: "#{annotation_url}/annotations/new"
|
||||
dataType: "script").done (->
|
||||
$("#new_legislation_annotation #legislation_annotation_quote").val(@annotation.quote)
|
||||
$("#new_legislation_annotation #legislation_annotation_ranges").val(JSON.stringify(@annotation.ranges))
|
||||
$("#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
|
||||
@@ -158,7 +160,7 @@ App.LegislationAnnotatable =
|
||||
|
||||
checkExist = setInterval((->
|
||||
if $("span[data-annotation-id='#{last_annotation.id}']").length
|
||||
for annotation in annotations
|
||||
annotations.forEach (annotation) ->
|
||||
ann_weight = App.LegislationAnnotatable.propotionalWeight(annotation.weight, max_weight)
|
||||
el = $("span[data-annotation-id='#{annotation.id}']")
|
||||
el.addClass("weight-#{ann_weight}")
|
||||
@@ -180,9 +182,8 @@ App.LegislationAnnotatable =
|
||||
current_user_id = $("html").data("current-user-id")
|
||||
|
||||
$(".legislation-annotatable").each ->
|
||||
$this = $(this)
|
||||
ann_id = $this.data("legislation-draft-version-id")
|
||||
base_url = $this.data("legislation-annotatable-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 ->
|
||||
@@ -201,7 +202,4 @@ App.LegislationAnnotatable =
|
||||
|
||||
App.LegislationAnnotatable.app.start().then ->
|
||||
App.LegislationAnnotatable.app.ident.identity = current_user_id
|
||||
|
||||
options = {}
|
||||
options["legislation_draft_version_id"] = ann_id
|
||||
App.LegislationAnnotatable.app.annotations.load(options)
|
||||
App.LegislationAnnotatable.app.annotations.load(legislation_draft_version_id: ann_id)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.LocationChanger =
|
||||
|
||||
initialize: ->
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
"use strict"
|
||||
|
||||
App.Managers =
|
||||
|
||||
generatePassword: ->
|
||||
chars = "aAbcdeEfghiJkmnpqrstuUvwxyz23456789"
|
||||
pass = ""
|
||||
x = 0
|
||||
while x < 12
|
||||
i = Math.floor(Math.random() * chars.length)
|
||||
pass += chars.charAt(i)
|
||||
x++
|
||||
return pass
|
||||
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", ->
|
||||
password = App.Managers.generatePassword()
|
||||
$("#user_password").val(password)
|
||||
$("#user_password").val(App.Managers.generatePassword())
|
||||
|
||||
$(".show-password").on "click", ->
|
||||
if $("#user_password").is("input[type='password']")
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
"use strict"
|
||||
|
||||
App.Map =
|
||||
|
||||
initialize: ->
|
||||
maps = $("*[data-map]")
|
||||
|
||||
if maps.length > 0
|
||||
$.each maps, (index, map) ->
|
||||
App.Map.initializeMap map
|
||||
$("*[data-map]").each ->
|
||||
App.Map.initializeMap(this)
|
||||
|
||||
$(".js-toggle-map").on
|
||||
click: ->
|
||||
@@ -82,8 +81,7 @@ App.Map =
|
||||
e.target.bindPopup(getPopupContent(data)).openPopup()
|
||||
|
||||
getPopupContent = (data) ->
|
||||
content = "<a href='/budgets/#{data["budget_id"]}/investments/#{data["investment_id"]}'>#{data["investment_title"]}</a>"
|
||||
return content
|
||||
"<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)
|
||||
@@ -98,10 +96,10 @@ App.Map =
|
||||
map.on "click", moveOrPlaceMarker
|
||||
|
||||
if addMarkerInvestments
|
||||
for i in addMarkerInvestments
|
||||
if App.Map.validCoordinates(i)
|
||||
marker = createMarker(i.lat, i.long)
|
||||
marker.options["id"] = i.investment_id
|
||||
addMarkerInvestments.forEach (coordinates) ->
|
||||
if App.Map.validCoordinates(coordinates)
|
||||
marker = createMarker(coordinates.lat, coordinates.long)
|
||||
marker.options["id"] = coordinates.investment_id
|
||||
|
||||
marker.on "click", openMarkerPopup
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.MarkdownEditor =
|
||||
|
||||
refresh_preview: (element, md) ->
|
||||
@@ -32,8 +34,8 @@ App.MarkdownEditor =
|
||||
editor.toggleClass("fullscreen")
|
||||
$(".fullscreen-container").toggleClass("medium-8", "medium-12")
|
||||
span = $(this).find("span")
|
||||
current_html = span.html()
|
||||
if(current_html == span.data("open-text"))
|
||||
|
||||
if(span.html() == span.data("open-text"))
|
||||
span.html(span.data("closed-text"))
|
||||
else
|
||||
span.html(span.data("open-text"))
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
"use strict"
|
||||
|
||||
App.ModalDownload =
|
||||
|
||||
enableButton: ->
|
||||
$("#js-download-modal-submit").attr("disabled", false)
|
||||
$("#js-download-modal-submit").removeClass('disabled')
|
||||
$("#js-download-modal-submit").removeClass("disabled")
|
||||
|
||||
initialize: ->
|
||||
$("#js-download-modal-submit").on "click", ->
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.ModeratorBudgetInvestments =
|
||||
|
||||
add_class_faded: (id) ->
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.ModeratorComments =
|
||||
|
||||
add_class_faded: (id) ->
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.ModeratorDebates =
|
||||
|
||||
add_class_faded: (id) ->
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.ModeratorProposalNotifications =
|
||||
|
||||
add_class_faded: (id) ->
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.ModeratorProposals =
|
||||
|
||||
add_class_faded: (id) ->
|
||||
|
||||
@@ -1,27 +1,24 @@
|
||||
"use strict"
|
||||
|
||||
App.Polls =
|
||||
generateToken: ->
|
||||
token = ""
|
||||
rand = ""
|
||||
for n in [0..5]
|
||||
rand = Math.random().toString(36).substr(2) # remove `0.`
|
||||
token = token + rand
|
||||
strings = Array.apply(null, length: 6).map ->
|
||||
Math.random().toString(36).substr(2) # remove `0.`
|
||||
|
||||
token = token.substring(0, 64)
|
||||
return token
|
||||
strings.join("").substring(0, 64)
|
||||
|
||||
replaceToken: ->
|
||||
for link in $(".js-question-answer")
|
||||
token_param = link.search.slice(-6)
|
||||
replaceToken: (token) ->
|
||||
$(".js-question-answer").each ->
|
||||
token_param = this.search.slice(-6)
|
||||
if token_param == "token="
|
||||
link.href = link.href + @token
|
||||
this.href = this.href + token
|
||||
|
||||
initialize: ->
|
||||
@token = App.Polls.generateToken()
|
||||
App.Polls.replaceToken()
|
||||
token = App.Polls.generateToken()
|
||||
App.Polls.replaceToken(token)
|
||||
|
||||
$(".zoom-link").on "click", (event) ->
|
||||
element = event.target
|
||||
answer = $(element).closest("div.answer")
|
||||
answer = $(event.target).closest("div.answer")
|
||||
|
||||
if $(answer).hasClass("medium-6")
|
||||
$(answer).removeClass("medium-6")
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.PollsAdmin =
|
||||
|
||||
initialize: ->
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.PreventDoubleSubmission =
|
||||
disable_buttons: (buttons) ->
|
||||
setTimeout ->
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
"use strict"
|
||||
|
||||
App.Questions =
|
||||
|
||||
nestedQuestions: ->
|
||||
$('.js-questions').on 'cocoon:after-insert', (e, new_question) ->
|
||||
App.Answers.initializeAnswers($(new_question).find('.js-answers'))
|
||||
$(".js-questions").on "cocoon:after-insert", (e, new_question) ->
|
||||
App.Answers.initializeAnswers($(new_question).find(".js-answers"))
|
||||
|
||||
initialize: ->
|
||||
App.Questions.nestedQuestions()
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
"use strict"
|
||||
|
||||
App.RegistrationForm =
|
||||
|
||||
initialize: ->
|
||||
|
||||
registrationForm = $("form#new_user[action=\"/users\"]")
|
||||
usernameInput = $("input#user_username")
|
||||
usernameInput = $("form#new_user[action=\"/users\"] input#user_username")
|
||||
|
||||
clearUsernameMessage = ->
|
||||
$("small").remove()
|
||||
@@ -18,8 +18,7 @@ App.RegistrationForm =
|
||||
showUsernameMessage(response)
|
||||
|
||||
|
||||
if registrationForm.length > 0
|
||||
usernameInput.on "focusout", ->
|
||||
clearUsernameMessage()
|
||||
username = usernameInput.val()
|
||||
validateUsername(username) if username != ""
|
||||
usernameInput.on "focusout", ->
|
||||
clearUsernameMessage()
|
||||
username = usernameInput.val()
|
||||
validateUsername(username) if username != ""
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.SendAdminNotificationAlert =
|
||||
initialize: ->
|
||||
$("#js-send-admin_notification-alert").on "click", ->
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.SendNewsletterAlert =
|
||||
initialize: ->
|
||||
$("#js-send-newsletter-alert").on "click", ->
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.Settings =
|
||||
|
||||
initialize: ->
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use strict"
|
||||
|
||||
App.SocialShare =
|
||||
|
||||
initialize: ->
|
||||
$(".social-share-button a").each ->
|
||||
element = $(this)
|
||||
site = element.data("site")
|
||||
element.append("<span class='show-for-sr'>#{site}</span>")
|
||||
$(this).append("<span class='show-for-sr'>#{$(this).data("site")}</span>")
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.Sortable =
|
||||
initialize: ->
|
||||
$(".sortable").sortable
|
||||
|
||||
@@ -4,10 +4,14 @@
|
||||
//= require stats
|
||||
|
||||
var initialize_stats_modules = function() {
|
||||
"use strict";
|
||||
|
||||
App.Stats.initialize();
|
||||
};
|
||||
|
||||
$(function(){
|
||||
"use strict";
|
||||
|
||||
$(document).ready(initialize_stats_modules);
|
||||
$(document).on("page:load", initialize_stats_modules);
|
||||
$(document).on("ajax:complete", initialize_stats_modules);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
# Helper for generate C3.js graphs
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
@@ -8,4 +10,4 @@ buildGraph = (el) ->
|
||||
|
||||
App.Stats =
|
||||
initialize: ->
|
||||
buildGraph(g) for g in $("[data-graph]")
|
||||
$("[data-graph]").each -> buildGraph(this)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.Suggest =
|
||||
|
||||
initialize: ->
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.TableSortable =
|
||||
getCellValue: (row, index) ->
|
||||
$(row).children("td").eq(index).text()
|
||||
@@ -11,12 +13,12 @@ App.TableSortable =
|
||||
initialize: ->
|
||||
$("table.sortable th").click ->
|
||||
table = $(this).parents("table").eq(0)
|
||||
rows = table.find("tr:gt(0)").not("tfoot tr").toArray().sort(App.TableSortable.comparer($(this).index()))
|
||||
@asc = !@asc
|
||||
if !@asc
|
||||
rows = rows.reverse()
|
||||
i = 0
|
||||
while i < rows.length
|
||||
table.append rows[i]
|
||||
i++
|
||||
rows = table.find("tbody tr").toArray().sort(App.TableSortable.comparer($(this).index()))
|
||||
this.asc = !this.asc
|
||||
|
||||
if this.asc
|
||||
table.append rows
|
||||
else
|
||||
table.append rows.reverse()
|
||||
|
||||
return
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.TagAutocomplete =
|
||||
|
||||
split: ( val ) ->
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
"use strict"
|
||||
|
||||
App.Tags =
|
||||
|
||||
initialize: ->
|
||||
$tag_input = $("input.js-tag-list")
|
||||
|
||||
$("body .js-add-tag-link").each ->
|
||||
$this = $(this)
|
||||
|
||||
unless $this.data("initialized") is "yes"
|
||||
$this.on("click", ->
|
||||
unless $(this).data("initialized") is "yes"
|
||||
$(this).on("click", ->
|
||||
name = "\"#{$(this).text()}\""
|
||||
current_tags = $tag_input.val().split(",").filter(Boolean)
|
||||
|
||||
if $.inArray(name, current_tags) >= 0
|
||||
current_tags.splice($.inArray(name, current_tags), 1)
|
||||
if current_tags.indexOf(name) >= 0
|
||||
current_tags.splice(current_tags.indexOf(name), 1)
|
||||
else
|
||||
current_tags.push name
|
||||
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
"use strict"
|
||||
|
||||
App.TreeNavigator =
|
||||
setNodes: (nodes) ->
|
||||
children = nodes.children("ul")
|
||||
|
||||
if(children.length == 0)
|
||||
return
|
||||
|
||||
children.each ->
|
||||
nodes.children("ul").each ->
|
||||
link = $(this).prev("a")
|
||||
$('<span class="open"></span>').insertBefore(link)
|
||||
App.TreeNavigator.setNodes($(this).children())
|
||||
@@ -21,16 +18,16 @@ App.TreeNavigator =
|
||||
|
||||
$("[data-tree-navigator] span").on
|
||||
click: ->
|
||||
elem = $(this)
|
||||
if(elem.hasClass("open"))
|
||||
elem.removeClass("open").addClass("closed")
|
||||
elem.siblings("ul").hide()
|
||||
else if(elem.hasClass("closed"))
|
||||
elem.removeClass("closed").addClass("open")
|
||||
elem.siblings("ul").show()
|
||||
if($(this).hasClass("open"))
|
||||
$(this).removeClass("open").addClass("closed")
|
||||
$(this).siblings("ul").hide()
|
||||
else if($(this).hasClass("closed"))
|
||||
$(this).removeClass("closed").addClass("open")
|
||||
$(this).siblings("ul").show()
|
||||
|
||||
if anchor = $(location).attr("hash")
|
||||
if link = elem.find("a[href='#{anchor}']")
|
||||
link.parents("ul").each ->
|
||||
$(this).show()
|
||||
$(this).siblings("span").removeClass("closed").addClass("open")
|
||||
anchor = $(location).attr("hash")
|
||||
|
||||
if anchor
|
||||
elem.find("a[href='#{anchor}']").parents("ul").each ->
|
||||
$(this).show()
|
||||
$(this).siblings("span").removeClass("closed").addClass("open")
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.Users =
|
||||
|
||||
initialize: ->
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.ValuationBudgetInvestmentForm =
|
||||
|
||||
showFeasibleFields: ->
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.Votations =
|
||||
|
||||
checkMaxVotes: ->
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
App.Votes =
|
||||
|
||||
hoverize: (votes) ->
|
||||
|
||||
@@ -1,28 +1,27 @@
|
||||
"use strict"
|
||||
|
||||
App.WatchFormChanges =
|
||||
forms: ->
|
||||
return $("form[data-watch-changes]")
|
||||
|
||||
msg: ->
|
||||
if($("[data-watch-form-message]").length)
|
||||
return $("[data-watch-form-message]").data("watch-form-message")
|
||||
return $("[data-watch-form-message]").data("watch-form-message")
|
||||
|
||||
hasChanged: ->
|
||||
App.WatchFormChanges.forms().is ->
|
||||
$(this).serialize() != $(this).data("watchChanges")
|
||||
|
||||
checkChanges: ->
|
||||
changes = false
|
||||
App.WatchFormChanges.forms().each ->
|
||||
form = $(this)
|
||||
if form.serialize() != form.data("watchChanges")
|
||||
changes = true
|
||||
if changes
|
||||
return confirm(App.WatchFormChanges.msg())
|
||||
if App.WatchFormChanges.hasChanged()
|
||||
confirm(App.WatchFormChanges.msg())
|
||||
else
|
||||
return true
|
||||
true
|
||||
|
||||
initialize: ->
|
||||
if App.WatchFormChanges.forms().length == 0 || App.WatchFormChanges.msg() == undefined
|
||||
return
|
||||
|
||||
$(document).off("page:before-change").on("page:before-change", -> App.WatchFormChanges.checkChanges())
|
||||
$(document).off("page:before-change").on("page:before-change", App.WatchFormChanges.checkChanges)
|
||||
|
||||
App.WatchFormChanges.forms().each ->
|
||||
form = $(this)
|
||||
form.data("watchChanges", form.serialize())
|
||||
$(this).data("watchChanges", $(this).serialize())
|
||||
|
||||
Reference in New Issue
Block a user