app/views/myreplicator/exports/_form.html.erb in myreplicator-0.0.16 vs app/views/myreplicator/exports/_form.html.erb in myreplicator-0.0.17

- old
+ new

@@ -1,11 +1,10 @@ <% #rather than yaml arrays of the drop downs export_to = ["destination_db","s3","both"] export_type = ["incremental","fulldump"] %> - <%= form_for(@export) do |f| %> <% if @export.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@export.errors.count, "error") %> prohibited this export from being saved:</h2> @@ -16,15 +15,15 @@ </ul> </div> <% end %> <div class="form-section"> <label>Source Schema</label> -<%= f.text_field :source_schema %> +<%= f.select :source_schema, @dbs %> <label>Destination Schema</label> -<%= f.text_field :destination_schema %> +<%= f.select :destination_schema, @dbs %> <label>Table Name</label> -<%= f.text_field :table_name %> +<%= f.select :table_name, [] %> <label>Incremental Column</label> <%= f.text_field :incremental_column %> <label>Maximum Incremental Value</label> <%= f.text_field :max_incremental_value %> <label>S3 Path</label> @@ -91,27 +90,52 @@ </div> <% end %> <%= javascript_include_tag "myreplicator/chosen.jquery.min" %> <%= javascript_include_tag "myreplicator/cronwtf.min" %> <script> +var dbs = { +<% @tables.each do |key,values| %> + "<%= key %>":[ + <% values.each do |table| %> + "<%= table %>", + <% end %> + ], +<% end %> +} $(function(){ CronUI.translate(); $(".chosen").chosen(); + $("#export_destination_schema,#export_table_name").chosen(); $(".cron").chosen().change(function(){CronUI.translate()}); + $("#export_source_schema").chosen().change(function(){ + exportSchemaSelect($(this).val()) + }); + exportSchemaSelect($("#export_source_schema").val()); +<%- if @edit -%> + editInit(); +<%- end -%> +}) - <%- if @edit -%> function editInit(){ var cron = "<%= @export.cron %>"; var displays = ["#min","#hour","#day","#month","#dow"]; var cron_vals = cron.split(" "); for(i=0;i<cron_vals.length; i++){ //console.log(displays[i]+" val: "+cron_vals[i]) $(displays[i]).val(cron_vals[i]).trigger("liszt:updated"); } CronUI.translate(); + $("#export_table_name").val("<%= @export.table_name %>").trigger("liszt:updated"); } -editInit(); - <%- end -%> - -}) +function exportSchemaSelect(val){ + var target = $("#export_table_name"); + var tables = dbs[val]; + var l = tables.length; + var options = ""; + for(i=0;i<l;i++){ + options += "<option value='"+tables[i]+"'>"+tables[i]+"</option>"; + } + target.val('').find("option").remove().trigger("liszt:updated"); + target.append(options).trigger("liszt:updated"); +} </script>