]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4100 Put overall & project notifs in the same form
authorFabrice Bellingard <fabrice.bellingard@sonarsource.com>
Wed, 20 Feb 2013 14:50:01 +0000 (15:50 +0100)
committerFabrice Bellingard <fabrice.bellingard@sonarsource.com>
Wed, 20 Feb 2013 15:00:45 +0000 (16:00 +0100)
sonar-server/src/main/webapp/WEB-INF/app/controllers/account_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/views/account/_global_notifications.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/account/_per_project_notifications.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/account/index.html.erb

index 6277b81c0cdc1ad3668b27b80f44f324ace30ddf..36afe854939c524ab44d4f6feaa049da03ed449b 100644 (file)
@@ -62,17 +62,16 @@ class AccountController < ApplicationController
   end
 
   def update_notifications
-    notifications = params[:notifications]
+    # Global notifs
+    global_notifs = params[:global_notifs]
     Property.delete_all(['prop_key like ? AND user_id = ? AND resource_id IS NULL', 'notification.%', current_user.id])
-    notifications.each_key { |key| current_user.add_property(:prop_key => 'notification.' + key, :text_value => 'true') } if notifications
-    redirect_to :action => 'index'
-  end
+    global_notifs.each_key { |key| current_user.add_property(:prop_key => 'notification.' + key, :text_value => 'true') } if global_notifs
 
-  def update_per_project_notifications
-    notifications = params[:notifications]
+    # Per project notifs
+    project_notifs = params[:project_notifs]
     Property.delete_all(['prop_key like ? AND user_id = ? AND resource_id IS NOT NULL', 'notification.%', current_user.id])
-    if notifications
-      notifications.each do |r_id, per_project_notif|
+    if project_notifs
+      project_notifs.each do |r_id, per_project_notif|
         per_project_notif.each do |dispatch, channels|
           channels.each do |channel|
             current_user.add_property(:prop_key => 'notification.' + dispatch + '.' + channel, :text_value => 'true', :resource_id => r_id)
@@ -81,6 +80,7 @@ class AccountController < ApplicationController
       end
     end
     
+    # New project added
     new_params = {}
     unless params[:new_project].blank?
       new_params[:new_project] = params[:new_project]
index 5332657ffd67374cb0ca1d9149a527774fffeee3..dbad8b052d3a8f613c453228888a0798a340a53e 100644 (file)
@@ -1,7 +1,5 @@
 <h2><%= message('my_profile.overall_notifications.title') -%></h2>
 
-<div class="admin marginbottom10">
-  <% form_tag({:action => 'update_notifications'}, {:method => 'post'}) do %>
     <table class="form">
       <tr>
         <td></td>
@@ -15,7 +13,7 @@
           <%
                for channel in @channels
                  notification_id = dispatcher + '.' + channel.getKey()
-                 check_box_id = 'notifications[' + notification_id + ']'
+                 check_box_id = 'global_notifs[' + notification_id + ']'
                  check_box_checked = @global_notifications[notification_id]
           %>
           <td class="center">
@@ -24,9 +22,4 @@
           <% end %>
         </tr>
       <% end %>
-      <tr>
-        <td style="padding-top: 10px" colspan="<%= @global_dispatchers.size + 1 -%>"><%= submit_tag message('my_profile.notifications.submit') %></td>
-      </tr>
     </table>
-  <% end %>
-</div>
\ No newline at end of file
index 94a9d5d8e1c6d8c209e0c1028400227dd6b90aeb..38d7a3a53ddca01b44cbc7e4d98524395a2ad739 100644 (file)
@@ -1,7 +1,4 @@
 <h2><%= message('my_profile.per_project_notifications.title') -%></h2>
-
-<div class="admin marginbottom10">
-  <% form_tag({:action => 'update_per_project_notifications'}, {:method => 'post', :id => 'per_project_notif_form'}) do %>
     
     <table class="form">
       <tr>
@@ -16,7 +13,7 @@
                 var id = event.target.value;
                 if (id != null) {
                   //window.location = '<%= ApplicationController.root_context -%>/account/index?new_project=' + id;
-                  $j('#per_project_notif_form').submit();
+                  $j('#notif_form').submit();
                 }
               });
           </script>
@@ -57,7 +54,7 @@
              select_id = index.to_s + "_" + dispatcher
         %>
           <td>
-            <select id="<%= select_id -%>" name="notifications[<%= r_id.to_s -%>][<%= dispatcher-%>][]" multiple style="width: 100%">
+            <select id="<%= select_id -%>" name="project_notifs[<%= r_id.to_s -%>][<%= dispatcher-%>][]" multiple style="width: 100%">
               <% @channels.each do |channel| -%>
                 <option value="<%= channel.getKey() -%>" <%= 'selected' if per_project_notif[dispatcher].include?(channel.getKey()) || (r_id==@new_project_id && channel.getKey()=='EmailNotificationChannel') -%>><%= message('notification.channel.' + channel.getKey()) -%></option>
               <% end %>
       
            <% end %>
       
-      <tr>
-        <td style="padding-top: 10px" colspan="<%= @per_project_dispatchers.size + 1 -%>"><%= submit_tag message('my_profile.notifications.submit') %></td>
-      </tr>
       <% end %>
       
     </table>
-  <% end %>
-</div>
\ No newline at end of file
index 4b630101a9e332025ca4aca57956d8a3e07eb9db..ff23f8a1f25682b8b82f511ad8cc4a98ecbc10f3 100644 (file)
@@ -1,3 +1,11 @@
+<% content_for :style do %>
+  <style>
+    h2 {
+      padding-bottom: 10px;
+    }
+  </style>
+<% end %>
+
 <div id="content">
   <h1 class="marginbottom10"><%= message('my_profile.page') -%></h1>
 
@@ -23,9 +31,9 @@
   </div>
 
   <% if User.editable_password? %>
-    <h2><%= message('my_profile.password.title') -%></h2>
-
     <div class="admin marginbottom10">
+      <h2><%= message('my_profile.password.title') -%></h2>
+      
       <% form_tag({:action => 'change_password'}, :id => 'pass_form_tag', :name => 'pass_form_tag') do -%>
         <table class="form">
           <tr>
     </div>
   <% end -%>
 
-  <% unless @global_dispatchers.empty? -%>
-    <%= render "account/global_notifications" -%>
-  <% end %>
+  <div class="admin marginbottom10">
+    <% form_tag({:action => 'update_notifications'}, {:method => 'post', :id => 'notif_form'}) do %>
+    
+      <% unless @global_dispatchers.empty? -%>
+        <%= render "account/global_notifications" -%>
+        <br/><br/>
+      <% end %>
 
-  <% unless @per_project_dispatchers.empty? -%>
-    <%= render "account/per_project_notifications" -%>  
-  <% end %>
+      <% unless @per_project_dispatchers.empty? -%>
+        <%= render "account/per_project_notifications" -%>  
+      <% end %>
+      
+      <br/><br/>
+      <%= submit_tag message('my_profile.notifications.submit') %>
+    <% end %>
+  </div>
   
 </div>
\ No newline at end of file