diff --git a/assets/javascripts/reporting/controls.js b/assets/javascripts/reporting/controls.js new file mode 100644 index 0000000000..192c979ede --- /dev/null +++ b/assets/javascripts/reporting/controls.js @@ -0,0 +1,62 @@ +/*jslint white: false, nomen: true, devel: true, on: true, debug: false, evil: true, onevar: false, browser: true, white: false, indent: 2 */ +/*global window, $, $$, Reporting, Effect, Ajax, Element */ + +Reporting.Controls = { + query_name_editor: function (target_id) { + var target = $(target_id); + var isPublic = target.getAttribute("data-is_public") === "true"; + var updateUrl = target.getAttribute("data-update_url"); + var translations = target.getAttribute("data-translations"); + if (translations.isJSON()) { + translations = translations.evalJSON(true); + } else { + translations = {}; + } + + Ajax.InPlaceEditor(target_id, updateUrl, { + callback: function (form, value) { + return 'query_is_public=' + (form.query_is_public.checked === true) + '&query_name=' + encodeURIComponent(value); + }, + okControl: 'button', + cancelControl: 'button', + externalControl: 'query-name-edit-button', + okText: translations.rename === undefined ? 'ok' : translations.rename, + cancelText: translations.cancel === undefined ? 'cancel' : translations.cancel, + savingText: translations.saving === undefined ? 'Saving...' : translations.saving, + loadingText: translations.loading === undefined ? 'Loading...' : translations.loading, + clickToEditText: translations.clickToEdit === undefined ? 'Click to edit' : translations.clickToEdit, + onFormCustomization: function (ipe, ipeForm) { + var label; + var checkbox; + var chk_id = 'rename_query_is_public'; + + checkbox = document.createElement('input'); + checkbox.value = 1; + checkbox.type = 'checkbox'; + checkbox.id = chk_id; + checkbox.name = 'query_is_public'; + checkbox.checked = isPublic; + + label = document.createElement('label'); + label.id = 'in_place_save_is_public_question'; + label.htmlFor = chk_id; + label.appendChild(document.createTextNode(translations.isPublic === undefined ? 'public?' : translations.isPublic)); + + ipeForm.insert(label); + ipeForm.insert(checkbox); + } + }); + }, + + toggle_delete_form: function () { + var offset = $('query-icon-delete').positionedOffset().left; + $('delete_form').setStyle("left: " + offset + "px").toggle(); + } +}; + +Reporting.onload(function () { + Reporting.Controls.query_name_editor('query_saved_name'); + $("query-icon-delete").observe("click", Reporting.Controls.toggle_delete_form); +}); + + diff --git a/lib/widget/controls.rb b/lib/widget/controls.rb new file mode 100644 index 0000000000..b8d8b9c516 --- /dev/null +++ b/lib/widget/controls.rb @@ -0,0 +1,3 @@ +class Widget::Controls < Widget::Base + extend ProactiveAutoloader +end diff --git a/lib/widget/controls/apply.rb b/lib/widget/controls/apply.rb new file mode 100644 index 0000000000..f718a4b9bd --- /dev/null +++ b/lib/widget/controls/apply.rb @@ -0,0 +1,17 @@ +class Widget::Controls::Apply < Widget::Base + def render + link_to({}, {:href => "#", + :onclick => " + selectAllOptions('group_by_rows'); + selectAllOptions('group_by_columns'); + new Ajax.Updater('result-table', + '#{url_for(:action => 'index', :set_filter => '1')}', + { asynchronous:true, + evalScripts:true, + postBody: Form.serialize('query_form') + '\\n' + $('filters').innerHTML }); + return false;".html_safe, + :class => 'button apply'}) do + content_tag(:span, content_tag(:em, l(:button_apply))) + end + end +end diff --git a/lib/widget/controls/delete.rb b/lib/widget/controls/delete.rb new file mode 100644 index 0000000000..a0fcf37e66 --- /dev/null +++ b/lib/widget/controls/delete.rb @@ -0,0 +1,25 @@ +class Widget::Controls::Delete < Widget::Base + def render + return "" if @query.new_record? + content_tag :span do + + button = link_to_function l(:button_delete), "toggle_delete_form();", + :class => 'breadcrumb_icon icon-delete', + :id => 'query-icon-delete', + :title => l(:button_delete) + + popup = content_tag :div, :id => "delete_form", :class => "button_form", + :style => "display:none" do + question = content_tag :p, l(:label_really_delete_question) + options = content_tag :p do + opt1 = link_to l(:button_delete), url_for(:action => 'delete', :id => @query.id) + opt2 = link_to_function l(:button_cancel), "toggle_delete_form();", :class => 'icon icon-cancel' + opt1 + opt2 + end + question + options + end + + button + popup + end + end +end diff --git a/lib/widget/controls/query_name.rb b/lib/widget/controls/query_name.rb new file mode 100644 index 0000000000..8ae0b14f46 --- /dev/null +++ b/lib/widget/controls/query_name.rb @@ -0,0 +1,29 @@ +class Widget::Controls::QueryName < Widget::Base + def render + options = { "data-translations" => translations } + if @query.new_record? + name = l(:label_save_this_query) + icon = "" + else + name = @query.name + icon = content_tag :a, :href => "#", :class => 'breadcrumb_icon icon-edit', + :id => "query-name-edit-button", :title => "#{l(:button_rename)}" do + l(:button_rename) + end + options["data-is_public"] = @query.is_public + options["data-update-url"] = url_for(:action => "update", + :controller => @engine.name.underscore.pluralize, + :id => @query.id).html_safe + end + content_tag(:span, name, :id => "query_saved_name") + icon + end + + def translations + { :rename => l(:button_rename), + :cancel => l(:button_cancel), + :loading => l(:label_loading), + :clickToEdit => l(:label_click_to_edit), + :isPublic => l(:field_is_public), + :saving => l(:label_saving) }.to_json.html_safe + end +end diff --git a/lib/widget/controls/reset.rb b/lib/widget/controls/reset.rb new file mode 100644 index 0000000000..d4afdcd7c4 --- /dev/null +++ b/lib/widget/controls/reset.rb @@ -0,0 +1,5 @@ +class Widget::Controls::Reset < Widget::Base + def render + link_to_function l(:button_reset), "restore_query_inputs();", :class => 'icon icon-reload' + end +end diff --git a/lib/widget/controls/save.rb b/lib/widget/controls/save.rb new file mode 100644 index 0000000000..343fbc5486 --- /dev/null +++ b/lib/widget/controls/save.rb @@ -0,0 +1,22 @@ +class Widget::Controls::Save < Widget::Base + def render + unless @query.new_record? + link_to({}, {:href => "#", + :onclick => " + selectAllOptions('group_by_rows'); + selectAllOptions('group_by_columns'); + new Ajax.Updater('result-table', + '#{url_for(:action => 'update', :id => @query.id, :set_filter => '1')}', + { asynchronous: true, + evalScripts: true, + postBody: Form.serialize('query_form') }); + return false;", + :class => 'breadcrumb_icon icon-save', + :title => l(:button_save)}) do + content_tag(:span, content_tag(:em, l(:button_save))) + end + else + "" + end + end +end diff --git a/lib/widget/controls/save_as.rb b/lib/widget/controls/save_as.rb new file mode 100644 index 0000000000..0b6fe34a0d --- /dev/null +++ b/lib/widget/controls/save_as.rb @@ -0,0 +1,5 @@ +class Widget::Controls::SaveAs < Widget::Base + def render + "TODO: Save as" + end +end diff --git a/lib/widget/settings.rb b/lib/widget/settings.rb index 3eddf53777..e0751b5df9 100644 --- a/lib/widget/settings.rb +++ b/lib/widget/settings.rb @@ -11,24 +11,15 @@ class Widget::Settings < Widget::Base render_widget Widget::GroupBys, @query end - buttons = content_tag :p, :class => "buttons form_controls" do - p = link_to({}, {:href => "#", - :onclick => " - selectAllOptions('group_by_rows'); - selectAllOptions('group_by_columns'); - new Ajax.Updater('result-table', - '#{url_for(:action => 'index', :set_filter => '1')}', - { asynchronous:true, - evalScripts:true, - postBody: Form.serialize('query_form') + '\\n' + $('filters').innerHTML }); - return false;".html_safe, - :class => 'button apply'}) do - content_tag(:span, content_tag(:em, l(:button_apply))) - end - p += link_to_function l(:button_reset), "restore_query_inputs();", :class => 'icon icon-reload' + controls = content_tag :p, :class => "buttons form_controls" do + widgets = render_widget(Widget::Controls::Apply, @query) + render_widget(Widget::Controls::Save, @query, :to => widgets) + render_widget(Widget::Controls::SaveAs, @query, :to => widgets) + render_widget(Widget::Controls::Reset, @query, :to => widgets) + render_widget(Widget::Controls::Delete, @query, :to => widgets) end - fieldsets + buttons + fieldsets + controls end end end