parent
59d5d21a73
commit
dbc1fc11c8
@ -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); |
||||||
|
}); |
||||||
|
|
||||||
|
|
@ -0,0 +1,3 @@ |
|||||||
|
class Widget::Controls < Widget::Base |
||||||
|
extend ProactiveAutoloader |
||||||
|
end |
@ -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 |
@ -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 |
@ -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 |
@ -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 |
@ -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 |
@ -0,0 +1,5 @@ |
|||||||
|
class Widget::Controls::SaveAs < Widget::Base |
||||||
|
def render |
||||||
|
"TODO: Save as" |
||||||
|
end |
||||||
|
end |
Loading…
Reference in new issue