diff options
Diffstat (limited to 'public/javascripts/admin_interface.js')
| -rw-r--r-- | public/javascripts/admin_interface.js | 230 |
1 files changed, 161 insertions, 69 deletions
diff --git a/public/javascripts/admin_interface.js b/public/javascripts/admin_interface.js index 9da5d28..b7bdc10 100644 --- a/public/javascripts/admin_interface.js +++ b/public/javascripts/admin_interface.js | |||
| @@ -1,15 +1,3 @@ | |||
| 1 | function hide_all() { | ||
| 2 | $('#recent_changes_toggle').attr("class", "unselected"); | ||
| 3 | $('#my_work_toggle').attr("class", "unselected"); | ||
| 4 | $('#current_drafts_toggle').attr("class", "unselected"); | ||
| 5 | $('#admin_sitemap_toggle').attr("class", "unselected"); | ||
| 6 | |||
| 7 | $('#current_drafts_table').hide(); | ||
| 8 | $('#my_work_table').hide(); | ||
| 9 | $('#recent_changes_table').hide(); | ||
| 10 | $('#admin_sitemap_table').hide(); | ||
| 11 | } | ||
| 12 | |||
| 13 | $(document).ready(function () { | 1 | $(document).ready(function () { |
| 14 | admin_search.initialize(); | 2 | admin_search.initialize(); |
| 15 | 3 | ||
| @@ -19,15 +7,29 @@ $(document).ready(function () { | |||
| 19 | promotion: false, | 7 | promotion: false, |
| 20 | menubar: false, | 8 | menubar: false, |
| 21 | plugins: 'code link lists visualblocks', | 9 | plugins: 'code link lists visualblocks', |
| 22 | toolbar: 'bold italic underline | bullist numlist | link unlink | blocks | code', | 10 | toolbar: 'bold italic underline | bullist numlist | link unlink | insertpageimage | blocks | code', |
| 23 | extended_valid_elements: 'aggregate[children|tags|limit|order_by|order_direction|partial|conditions]', | 11 | extended_valid_elements: 'aggregate[children|tags|limit|order_by|order_direction|partial|conditions],a[href|target|rel|class|data-gallery],img[class|src|alt|title|width|height|style|border]', |
| 24 | relative_urls: false, | 12 | relative_urls: false, |
| 25 | entity_encoding: 'raw', | 13 | entity_encoding: 'raw', |
| 26 | valid_classes: { '*': '' }, | 14 | content_style: '.inline-image--full { width: 100%; margin: 1rem 0; } .inline-image--half { width: 48%; margin-bottom: 1rem; } .inline-image--left { float: left; margin-right: 1rem; } .inline-image--right { float: right; margin-left: 1rem; }', |
| 15 | valid_classes: { | ||
| 16 | '*': '', | ||
| 17 | 'img': 'inline-image inline-image--full inline-image--half inline-image--left inline-image--right', | ||
| 18 | 'a': 'glightbox' | ||
| 19 | }, | ||
| 27 | setup: function(editor) { | 20 | setup: function(editor) { |
| 28 | editor.on('init', function() { | 21 | editor.on('init', function() { |
| 29 | cccms.setup_autosave(); | 22 | cccms.setup_autosave(); |
| 30 | }); | 23 | }); |
| 24 | |||
| 25 | editor.ui.registry.addButton('insertpageimage', { | ||
| 26 | icon: 'image', | ||
| 27 | text: 'Insert image', | ||
| 28 | tooltip: "Insert one of this page's attached images", | ||
| 29 | onAction: function() { | ||
| 30 | cccms.inline_images.open(editor); | ||
| 31 | } | ||
| 32 | }); | ||
| 31 | } | 33 | } |
| 32 | }); | 34 | }); |
| 33 | 35 | ||
| @@ -55,6 +57,10 @@ $(document).ready(function () { | |||
| 55 | move_to_search.initialize_search(); | 57 | move_to_search.initialize_search(); |
| 56 | } | 58 | } |
| 57 | 59 | ||
| 60 | if ($("#restore_search_term").length != 0) { | ||
| 61 | restore_search.initialize_search(); | ||
| 62 | } | ||
| 63 | |||
| 58 | if ($("#event_node_search_term").length != 0) { | 64 | if ($("#event_node_search_term").length != 0) { |
| 59 | event_search.initialize_search(); | 65 | event_search.initialize_search(); |
| 60 | } | 66 | } |
| @@ -71,63 +77,13 @@ $(document).ready(function () { | |||
| 71 | cccms.preview.initialize(); | 77 | cccms.preview.initialize(); |
| 72 | } | 78 | } |
| 73 | 79 | ||
| 74 | if ($('#recent_changes_toggle').length != 0) { | ||
| 75 | hide_all(); | ||
| 76 | $('#recent_changes_toggle').attr("class", "selected"); | ||
| 77 | $('#recent_changes_table').show(); | ||
| 78 | |||
| 79 | $('#recent_changes_toggle').bind("click", function(){ | ||
| 80 | hide_all(); | ||
| 81 | $('#recent_changes_toggle').attr("class", "selected"); | ||
| 82 | $('#recent_changes_table').show(); | ||
| 83 | return false; | ||
| 84 | }); | ||
| 85 | |||
| 86 | $('#my_work_toggle').bind("click", function(){ | ||
| 87 | hide_all(); | ||
| 88 | $('#my_work_toggle').attr("class", "selected"); | ||
| 89 | $('#my_work_table').show(); | ||
| 90 | return false; | ||
| 91 | }); | ||
| 92 | |||
| 93 | $('#admin_wizard_my_work').bind("click", function(){ | ||
| 94 | hide_all(); | ||
| 95 | $('#my_work_toggle').attr("class", "selected"); | ||
| 96 | $('#my_work_table').show(); | ||
| 97 | return false; | ||
| 98 | }); | ||
| 99 | |||
| 100 | $('#current_drafts_toggle').bind("click", function(){ | ||
| 101 | hide_all(); | ||
| 102 | $('#current_drafts_toggle').attr("class", "selected"); | ||
| 103 | $('#current_drafts_table').show(); | ||
| 104 | return false; | ||
| 105 | }); | ||
| 106 | |||
| 107 | $('#admin_sitemap_toggle').bind("click", function(){ | ||
| 108 | hide_all(); | ||
| 109 | $('#admin_sitemap_toggle').attr("class", "selected"); | ||
| 110 | $('#admin_sitemap_table').show(); | ||
| 111 | return false; | ||
| 112 | }); | ||
| 113 | |||
| 114 | $('#admin_wizard_create_page').bind("click", function(){ | ||
| 115 | hide_all(); | ||
| 116 | $('#admin_sitemap_toggle').attr("class", "selected"); | ||
| 117 | $('#admin_sitemap_table').show(); | ||
| 118 | return false; | ||
| 119 | }); | ||
| 120 | } | ||
| 121 | |||
| 122 | jQuery.ajaxSetup({ | 80 | jQuery.ajaxSetup({ |
| 123 | 'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript");} | 81 | 'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript");} |
| 124 | }); | 82 | }); |
| 125 | 83 | ||
| 126 | $(document).ajaxSend(function(event, request, settings) { | 84 | $(document).ajaxSend(function(event, request, settings) { |
| 127 | if (typeof(AUTH_TOKEN) == "undefined") return; | 85 | var meta = document.querySelector("meta[name='csrf-token']"); |
| 128 | // settings.data is a serialized string like "foo=bar&baz=boink" (or null) | 86 | if (meta) request.setRequestHeader("X-CSRF-Token", meta.content); |
| 129 | settings.data = settings.data || ""; | ||
| 130 | settings.data += (settings.data ? "&" : "") + "authenticity_token=" + encodeURIComponent(AUTH_TOKEN); | ||
| 131 | }); | 87 | }); |
| 132 | 88 | ||
| 133 | }); | 89 | }); |
| @@ -172,6 +128,10 @@ cccms = { | |||
| 172 | options = options || {}; | 128 | options = options || {}; |
| 173 | if (options.force || page.title_has_changed() || page.abstract_has_changed() || page.body_has_changed()) { | 129 | if (options.force || page.title_has_changed() || page.abstract_has_changed() || page.body_has_changed()) { |
| 174 | 130 | ||
| 131 | elements.body.find('a.glightbox').each(function() { | ||
| 132 | if ($(this).find('img').length === 0) { $(this).remove(); } | ||
| 133 | }); | ||
| 134 | |||
| 175 | tinymce.triggerSave(); | 135 | tinymce.triggerSave(); |
| 176 | page.cached_title = elements.title.val(); | 136 | page.cached_title = elements.title.val(); |
| 177 | page.cached_abstract = elements.abstract.val(); | 137 | page.cached_abstract = elements.abstract.val(); |
| @@ -252,6 +212,96 @@ cccms = { | |||
| 252 | refresh_if_open : function() { | 212 | refresh_if_open : function() { |
| 253 | if (cccms.preview.is_open) cccms.preview.refresh(); | 213 | if (cccms.preview.is_open) cccms.preview.refresh(); |
| 254 | } | 214 | } |
| 215 | }, | ||
| 216 | |||
| 217 | inline_images: { | ||
| 218 | ensure_overlay: function() { | ||
| 219 | if ($('#inline_image_picker').length) return; | ||
| 220 | |||
| 221 | var overlay = $( | ||
| 222 | '<div id="inline_image_picker" style="display:none">' + | ||
| 223 | '<div id="inline_image_picker_grid"></div>' + | ||
| 224 | '<div id="inline_image_picker_actions">' + | ||
| 225 | '<button type="button" data-placement="full">Insert full width</button>' + | ||
| 226 | '<button type="button" data-placement="left">Insert, align left</button>' + | ||
| 227 | '<button type="button" data-placement="right">Insert, align right</button>' + | ||
| 228 | '<button type="button" id="inline_image_picker_cancel">Cancel</button>' + | ||
| 229 | '</div>' + | ||
| 230 | '</div>' | ||
| 231 | ); | ||
| 232 | $('body').append(overlay); | ||
| 233 | |||
| 234 | overlay.on('click', '#inline_image_picker_grid img', function() { | ||
| 235 | overlay.find('#inline_image_picker_grid img').removeClass('selected'); | ||
| 236 | $(this).addClass('selected'); | ||
| 237 | cccms.inline_images.selected_index = $(this).data('index'); | ||
| 238 | }); | ||
| 239 | |||
| 240 | overlay.on('click', '[data-placement]', function() { | ||
| 241 | cccms.inline_images.insert($(this).data('placement')); | ||
| 242 | }); | ||
| 243 | |||
| 244 | overlay.on('click', '#inline_image_picker_cancel', function() { | ||
| 245 | overlay.hide(); | ||
| 246 | }); | ||
| 247 | }, | ||
| 248 | |||
| 249 | open: function(editor) { | ||
| 250 | cccms.inline_images.ensure_overlay(); | ||
| 251 | cccms.inline_images.editor = editor; | ||
| 252 | |||
| 253 | var showUrl = $("#page_editor > form").attr("data-show-url") || ""; | ||
| 254 | var match = showUrl.match(/(\d+)$/); | ||
| 255 | cccms.inline_images.node_id = match ? match[1] : ""; | ||
| 256 | |||
| 257 | var items = $('#related_asset_list li').map(function() { | ||
| 258 | return { | ||
| 259 | thumb: $(this).find('img').attr('src'), | ||
| 260 | large: $(this).data('large-url'), | ||
| 261 | original: $(this).data('original-url'), | ||
| 262 | name: $(this).data('name') | ||
| 263 | }; | ||
| 264 | }).get(); | ||
| 265 | cccms.inline_images.items = items; | ||
| 266 | |||
| 267 | var grid = $('#inline_image_picker_grid').empty(); | ||
| 268 | if (items.length === 0) { | ||
| 269 | grid.append('<p>No images are attached to this page yet -- attach one from the Images section first.</p>'); | ||
| 270 | cccms.inline_images.selected_index = null; | ||
| 271 | } else { | ||
| 272 | items.forEach(function(item, i) { | ||
| 273 | var wrapper = $('<div class="inline_image_picker_item"></div>'); | ||
| 274 | wrapper.append($('<img>').attr('src', item.thumb).attr('data-index', i)); | ||
| 275 | if (i === 0) { | ||
| 276 | wrapper.append($('<span>', { "class": "inline_image_picker_headline_badge" }).text("Headline")); | ||
| 277 | } | ||
| 278 | grid.append(wrapper); | ||
| 279 | }); | ||
| 280 | cccms.inline_images.selected_index = 0; | ||
| 281 | grid.find('img').first().addClass('selected'); | ||
| 282 | } | ||
| 283 | |||
| 284 | $('#inline_image_picker').show(); | ||
| 285 | }, | ||
| 286 | |||
| 287 | escape_attr: function(str) { | ||
| 288 | return String(str || '').replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>'); | ||
| 289 | }, | ||
| 290 | |||
| 291 | insert: function(placement) { | ||
| 292 | var item = cccms.inline_images.items[cccms.inline_images.selected_index]; | ||
| 293 | if (!item) return; | ||
| 294 | |||
| 295 | var classes = placement === 'full' | ||
| 296 | ? 'inline-image inline-image--full' | ||
| 297 | : 'inline-image inline-image--half inline-image--' + placement; | ||
| 298 | |||
| 299 | var html = '<a href="' + item.original + '" class="glightbox" data-gallery="page-' + cccms.inline_images.node_id + '">' + | ||
| 300 | '<img src="' + item.large + '" class="' + classes + '" alt="' + cccms.inline_images.escape_attr(item.name) + '"></a>'; | ||
| 301 | |||
| 302 | cccms.inline_images.editor.insertContent(html); | ||
| 303 | $('#inline_image_picker').hide(); | ||
| 304 | } | ||
| 255 | } | 305 | } |
| 256 | } | 306 | } |
| 257 | 307 | ||
| @@ -367,8 +417,10 @@ rrule_builder = { | |||
| 367 | }); | 417 | }); |
| 368 | $("#rrule_monthly_ordinal").bind("change", function() { | 418 | $("#rrule_monthly_ordinal").bind("change", function() { |
| 369 | $("#rrule_ordinal_fields").toggle($(this).is(":checked")); | 419 | $("#rrule_ordinal_fields").toggle($(this).is(":checked")); |
| 420 | rrule_builder.toggle_custom_ordinal_fields(); | ||
| 370 | rrule_builder.sync(); | 421 | rrule_builder.sync(); |
| 371 | }); | 422 | }); |
| 423 | $("#rrule_ordinal").bind("change", rrule_builder.toggle_custom_ordinal_fields); | ||
| 372 | $("#rrule_exclude_month").bind("change", function() { | 424 | $("#rrule_exclude_month").bind("change", function() { |
| 373 | $("#rrule_excluded_month").toggle($(this).is(":checked")); | 425 | $("#rrule_excluded_month").toggle($(this).is(":checked")); |
| 374 | rrule_builder.sync(); | 426 | rrule_builder.sync(); |
| @@ -385,6 +437,12 @@ rrule_builder = { | |||
| 385 | $("#rrule_monthly_options").show(); | 437 | $("#rrule_monthly_options").show(); |
| 386 | }, | 438 | }, |
| 387 | 439 | ||
| 440 | toggle_custom_ordinal_fields : function() { | ||
| 441 | $("#rrule_custom_ordinal_fields").toggle( | ||
| 442 | $("#rrule_monthly_ordinal").is(":checked") && $("#rrule_ordinal").val() === "custom" | ||
| 443 | ); | ||
| 444 | }, | ||
| 445 | |||
| 388 | sync : function() { | 446 | sync : function() { |
| 389 | var freq = $("input[name='rrule_freq']:checked").val(); | 447 | var freq = $("input[name='rrule_freq']:checked").val(); |
| 390 | var parts = []; | 448 | var parts = []; |
| @@ -400,7 +458,16 @@ rrule_builder = { | |||
| 400 | } else { | 458 | } else { |
| 401 | parts.push("FREQ=MONTHLY"); | 459 | parts.push("FREQ=MONTHLY"); |
| 402 | if ($("#rrule_monthly_ordinal").is(":checked")) { | 460 | if ($("#rrule_monthly_ordinal").is(":checked")) { |
| 403 | parts.push("BYDAY=" + $("#rrule_ordinal").val() + $("#rrule_ordinal_day").val()); | 461 | var ordinal = $("#rrule_ordinal").val(); |
| 462 | if (ordinal === "custom") { | ||
| 463 | var customDays = []; | ||
| 464 | $("input[id^='rrule_custom_ordinal_']:checked").each(function() { | ||
| 465 | customDays.push($(this).attr("id").replace("rrule_custom_ordinal_", "") + $("#rrule_ordinal_day").val()); | ||
| 466 | }); | ||
| 467 | if (customDays.length > 0) parts.push("BYDAY=" + customDays.join(",")); | ||
| 468 | } else { | ||
| 469 | parts.push("BYDAY=" + ordinal + $("#rrule_ordinal_day").val()); | ||
| 470 | } | ||
| 404 | } | 471 | } |
| 405 | } | 472 | } |
| 406 | 473 | ||
| @@ -435,8 +502,33 @@ rrule_builder = { | |||
| 435 | } else if (parts.FREQ === "MONTHLY") { | 502 | } else if (parts.FREQ === "MONTHLY") { |
| 436 | $("input[name='rrule_freq'][value='monthly']").prop("checked", true); | 503 | $("input[name='rrule_freq'][value='monthly']").prop("checked", true); |
| 437 | rrule_builder.show_monthly_options(); | 504 | rrule_builder.show_monthly_options(); |
| 505 | var ordinalDays = parts.BYDAY && parts.BYDAY.split(","); | ||
| 506 | var customOrdinalDay = null; | ||
| 507 | var customOrdinals = []; | ||
| 508 | var customOrdinalsValid = ordinalDays && ordinalDays.length > 0; | ||
| 509 | if (customOrdinalsValid) { | ||
| 510 | ordinalDays.forEach(function(value) { | ||
| 511 | var customMatch = value.match(/^([1-5])([A-Z]{2})$/); | ||
| 512 | if (!customMatch || (customOrdinalDay && customOrdinalDay !== customMatch[2])) { | ||
| 513 | customOrdinalsValid = false; | ||
| 514 | return; | ||
| 515 | } | ||
| 516 | customOrdinalDay = customMatch[2]; | ||
| 517 | customOrdinals.push(customMatch[1]); | ||
| 518 | }); | ||
| 519 | } | ||
| 520 | |||
| 438 | var match = parts.BYDAY && parts.BYDAY.match(/^(-?\d+)([A-Z]{2})$/); | 521 | var match = parts.BYDAY && parts.BYDAY.match(/^(-?\d+)([A-Z]{2})$/); |
| 439 | if (match) { | 522 | if (customOrdinalsValid && (customOrdinals.length > 1 || customOrdinals[0] === "5")) { |
| 523 | $("#rrule_monthly_ordinal").prop("checked", true); | ||
| 524 | $("#rrule_ordinal_fields").show(); | ||
| 525 | $("#rrule_ordinal").val("custom"); | ||
| 526 | $("#rrule_ordinal_day").val(customOrdinalDay); | ||
| 527 | customOrdinals.forEach(function(ordinal) { | ||
| 528 | $("#rrule_custom_ordinal_" + ordinal).prop("checked", true); | ||
| 529 | }); | ||
| 530 | rrule_builder.toggle_custom_ordinal_fields(); | ||
| 531 | } else if (match) { | ||
| 440 | $("#rrule_monthly_ordinal").prop("checked", true); | 532 | $("#rrule_monthly_ordinal").prop("checked", true); |
| 441 | $("#rrule_ordinal_fields").show(); | 533 | $("#rrule_ordinal_fields").show(); |
| 442 | $("#rrule_ordinal").val(match[1]); | 534 | $("#rrule_ordinal").val(match[1]); |
