diff --git a/plugins/custom_forms/public/field.js b/plugins/custom_forms/public/field.js new file mode 100644 index 0000000..9ea9c40 --- /dev/null +++ b/plugins/custom_forms/public/field.js @@ -0,0 +1,141 @@ +jQuery('.icon-edit').live('click', function() { + elem = this; + jQuery.fn.colorbox({ + overlayClose: false, + escKey: false, + inline: true, + href: function(){ + id = jQuery(elem).attr('field_id'); + type = jQuery('#fields_'+id+'_type').val().split('_')[0]; + selector = '#edit-'+type+'-'+id + jQuery(selector).show(); + return selector + } + }); + return false; +}); + +jQuery('.remove-field').live('click', function(){ + id = jQuery(this).attr('field_id'); + jQuery('#field-'+id).slideDown(function(){ + jQuery('#field-'+id).remove(); + }); + return false +}); + +jQuery('.remove-option').live('click', function(){ + field_id = jQuery(this).attr('field_id'); + option_id = jQuery(this).attr('option_id'); + selector = '#field-'+field_id+'-option-'+option_id + jQuery(selector).slideDown(function(){ + jQuery(selector).remove(); + jQuery.colorbox.resize(); + }); + return false +}); + +function updateEditText(id){ + new_id = id+1 + jQuery('#edit-text-'+id).attr('id', 'edit-text-'+new_id); + input = jQuery('#edit-text-'+new_id+' input'); + jQuery('#edit-text-'+new_id+' .colorbox-ok-button').attr('div_id', 'edit-text-'+new_id); + input.attr('id', input.attr('id').replace(id,new_id)); + input.attr('name', input.attr('name').replace(id,new_id)); + label = jQuery('#edit-text-'+new_id+' label'); + label.attr('for', label.attr('for').replace(id,new_id)); +} + +function updateEditSelect(id){ + new_id = id+1 + jQuery('#edit-select-'+id).attr('id', 'edit-select-'+new_id); + jQuery('#edit-select-'+new_id+' .colorbox-ok-button').attr('div_id', 'edit-select-'+new_id); + jQuery('tr[id^=field-'+id+'-option').each(function(id, element){ + jQuery(element).attr('id', jQuery(element).attr('id').replace('field-'+id,'field-'+new_id)); + }); + jQuery('#edit-select-'+new_id+' label').each(function(index, element){ + label = jQuery(element); + label.attr('for', label.attr('for').replace(id,new_id)); + }); + jQuery('#edit-select-'+new_id+' input').each(function(index, element){ + input = jQuery(element); + input.attr('id', input.attr('id').replace(id,new_id)); + input.attr('name', input.attr('name').replace(id,new_id)); + }); + jQuery('#edit-select-'+new_id+' .remove-option').each(function(index, element){ + jQuery(element).attr('field_id',new_id); + }); + jQuery('#edit-select-'+new_id+' .new-option').attr('field_id',new_id); + jQuery('#edit-select-'+new_id+' #empty-option-'+id).attr('id','empty-option-'+new_id); +} + +function updateEmptyField(id){ + id = parseInt(id); + empty_field = jQuery('#empty-field'); + empty_field.attr('last_id', (id + 1).toString()); + jQuery('#empty-field input').each(function(index, element){ + new_id = jQuery(element).attr('id').replace(id,id+1); + jQuery(element).attr('id', new_id); + new_name = jQuery(element).attr('name').replace(id,id+1); + jQuery(element).attr('name', new_name); + }); + jQuery('#empty-field select').each(function(index, element){ + new_id = jQuery(element).attr('id').replace(id,id+1); + jQuery(element).attr('id', new_id); + new_name = jQuery(element).attr('name').replace(id,id+1); + jQuery(element).attr('name', new_name); + }); + jQuery('#empty-field a').each(function(index, element){ + jQuery(element).attr('field_id', id+1); + }); + updateEditText(id); + updateEditSelect(id); +} + +function updateEmptyOption(field_id, option_id){ + field_id = parseInt(field_id); + option_id = parseInt(option_id); + new_option_id = option_id+1; + empty_option = jQuery('#empty-option-'+field_id); + empty_option.attr('option_id',new_option_id); + jQuery('#empty-option-'+field_id+' .remove-option').attr('option_id', new_option_id); + + name_id = ' #fields_'+field_id+'_choices_'+option_id+'_name'; + jQuery('#empty-option-'+field_id+name_id).attr('name', 'fields['+field_id+'][choices]['+new_option_id+'][name]'); + jQuery('#empty-option-'+field_id+name_id).attr('id', 'fields_'+field_id+'_choices_'+new_option_id+'_name'); + + value_id = ' #fields_'+field_id+'_choices_'+option_id+'_value'; + jQuery('#empty-option-'+field_id+value_id).attr('name', 'fields['+field_id+'][choices]['+new_option_id+'][value]'); + jQuery('#empty-option-'+field_id+value_id).attr('id', 'fields_'+field_id+'_choices_'+new_option_id+'_value'); +} + +jQuery('#new-field').live('click', function(){ + empty_field = jQuery('#empty-field'); + id = empty_field.attr('last_id'); + edit_text = jQuery('#edit-text-'+id); + edit_select = jQuery('#edit-select-'+id); + new_field = empty_field.clone(); + new_field.attr('id','field-'+id); + new_field.insertBefore(empty_field).slideDown(); + edit_text.clone().insertAfter(edit_text); + edit_select.clone().insertAfter(edit_select); + updateEmptyField(id); + return false +}); + +jQuery('.new-option').live('click', function(){ + field_id = jQuery(this).attr('field_id'); + empty_option = jQuery('#empty-option-'+field_id); + option_id = empty_option.attr('option_id'); + new_option = empty_option.clone(); + new_option.attr('id','field-'+field_id+'-option-'+option_id); + new_option.insertBefore(empty_option).slideDown(); + jQuery.colorbox.resize(); + updateEmptyOption(field_id, option_id); + return false +}); + +jQuery('.colorbox-ok-button').live('click', function(){ + jQuery('#'+jQuery(this).attr('div_id')).hide(); + jQuery.colorbox.close(); + return false +}); diff --git a/plugins/custom_forms/public/icons/custom-forms.png b/plugins/custom_forms/public/icons/custom-forms.png new file mode 100644 index 0000000..51122ee Binary files /dev/null and b/plugins/custom_forms/public/icons/custom-forms.png differ diff --git a/plugins/custom_forms/public/style.css b/plugins/custom_forms/public/style.css new file mode 100644 index 0000000..a5b48bc --- /dev/null +++ b/plugins/custom_forms/public/style.css @@ -0,0 +1,30 @@ +.controller-profile_editor a.control-panel-custom-forms, +.controller-profile_editor .msie6 a.control-panel-custom-forms { + background-image: url(/plugins/custom_forms/icons/custom-forms.png) +} + +.action-table { + width: 100%; + overflow: hidden; +} + +.action-table th, +.action-table td{ + text-align: center; +} + +.action-table td{ + cursor: move; +} + +.action-table .actions{ + white-space: nowrap; +} + +.action-table .new-item{ + background-color: #EEE; +} + +.edit-information { + display: none; +} diff --git a/plugins/custom_forms/views/custom_forms_plugin_myprofile/_edit_select.html.erb b/plugins/custom_forms/views/custom_forms_plugin_myprofile/_edit_select.html.erb new file mode 100644 index 0000000..7f1c96b --- /dev/null +++ b/plugins/custom_forms/views/custom_forms_plugin_myprofile/_edit_select.html.erb @@ -0,0 +1,33 @@ +<% elem_id = "edit-select-#{counter}" %> +
<%= _('Name') %> | +<%= _('Value') %> | +<%= _('Actions') %> | +
---|---|---|
<%= link_to(_('NEW OPTION'), '#', :class => 'new-option', :field_id => counter)%> | +
<%= _('Name') %> | +<%= _('Type') %> | +<%= _('Mandatory') %> | +<%= _('Actions') %> | +|
---|---|---|---|---|
<%= link_to(_('NEW FIELD'), '#', :id => 'new-field')%> | +
<%= _('Name') %> | +<%= _('Period') %> | +<%= _('Submissions') %> | +<%= _('Access') %> | +<%= _('Actions') %> | +
---|---|---|---|---|
<%= form.name %> | +<%= period_range(form) %> | +<%= form.submissions.count > 0 ? link_to(form.submissions.count, {:action => 'submissions', :id => form.id}) : 0 %> | +<%= access_text(form) %> | ++ <%= button_without_text :edit, _('Edit'), :action => 'edit', :id => form.id %> + <%= button_without_text :remove, _('Remove'), {:action => 'remove', :id => form.id}, :confirm => _('Are you sure you want to remove this form?') %> | +
<%= link_to(_('NEW FORM'), :action => 'create')%> | +
<%= @form.description %>
+ +<% fields_for :submission, @submission do |f| %> + <%= render :partial => 'shared/form_submission', :locals => {:f => f} %> +<% end %> + +<% button_bar do %> + <%= button :back, _('Back to submissions'), :action => 'submissions', :id => @form.id %> +<% end %> diff --git a/plugins/custom_forms/views/custom_forms_plugin_myprofile/submissions.html.erb b/plugins/custom_forms/views/custom_forms_plugin_myprofile/submissions.html.erb new file mode 100644 index 0000000..e03b7e4 --- /dev/null +++ b/plugins/custom_forms/views/custom_forms_plugin_myprofile/submissions.html.erb @@ -0,0 +1,25 @@ +<% self.extend CustomFormsPlugin::Helper %> + +<%= _('Author') %> | +<%= _('Time') %> | +
---|---|
<%= link_to(author, {:action => 'show_submission', :id => submission.id}) %> | +<%= time_format(submission.created_at) %> | +
<%= @form.description %>
+ +<% if @submission.id.nil? %> + <%= error_messages_for :submission %> + + <% form_for :submission, @submission do |f| %> + <% if !user %> + <%= required labelled_form_field _('Author name'), text_field_tag(:author_name, @submission.author_name) %> + <%= required labelled_form_field _('Author email'), text_field_tag(:author_email, @submission.author_email) %> + <% end %> + + <%= render :partial => 'shared/form_submission', :locals => {:f => f} %> + + <% button_bar do %> + <%= submit_button :save, _('Save'), :cancel => {:action => 'index'} %> + <% end %> + <% end %> +<% else %> + <% fields_for :submission, @submission do |f| %> + <%= render :partial => 'shared/form_submission', :locals => {:f => f} %> + <% end %> +<% end %> diff --git a/plugins/custom_forms/views/shared/_form_submission.html.erb b/plugins/custom_forms/views/shared/_form_submission.html.erb new file mode 100644 index 0000000..ec2f336 --- /dev/null +++ b/plugins/custom_forms/views/shared/_form_submission.html.erb @@ -0,0 +1,5 @@ +<% self.extend(CustomFormsPlugin::Helper) %> + +<% @form.fields.each do |field| %> + <%= display_custom_field(field, @submission, f.object_name) %> +<% end %> diff --git a/plugins/custom_forms/views/tasks/_membership_survey_accept_details.html.erb b/plugins/custom_forms/views/tasks/_membership_survey_accept_details.html.erb new file mode 100644 index 0000000..d07b23b --- /dev/null +++ b/plugins/custom_forms/views/tasks/_membership_survey_accept_details.html.erb @@ -0,0 +1 @@ +<%= f.object_name.to_s %> diff --git a/plugins/custom_forms/views/tasks/custom_forms_plugin/_membership_survey_accept_details.html.erb b/plugins/custom_forms/views/tasks/custom_forms_plugin/_membership_survey_accept_details.html.erb new file mode 100644 index 0000000..0c802be --- /dev/null +++ b/plugins/custom_forms/views/tasks/custom_forms_plugin/_membership_survey_accept_details.html.erb @@ -0,0 +1,10 @@ +<% @form = CustomFormsPlugin::Form.find(task.form_id) %> +<% @submission = CustomFormsPlugin::Submission.new(:form_id => @form.id, :profile_id => user.id) %> + +<%= @form.description %>
+ +<% f.fields_for :submission do |fi| %> + <%#= fi.error_messages_for :submission %> + <%= render :partial => 'shared/form_submission', :locals => {:f => fi} %> +<% end %> -- libgit2 0.21.2