Listing for Module-apps

This commit is contained in:
Matthew Fu 2012-01-12 14:13:41 +08:00
parent 3d9fd359ed
commit c0efb5d1bc
4 changed files with 83 additions and 38 deletions

View File

@ -4,14 +4,15 @@ class Admin::AppAuthsController < ApplicationController
before_filter :is_admin? before_filter :is_admin?
def index def index
@roles = Role.all.entries # @roles = Role.all.entries
apps = Purchase.where(:type =>"App") # apps = Purchase.where(:type =>"App")
@app_auth_data = apps.entries.map do |app| # @app_auth_data = apps.entries.map do |app|
app_c = eval(app.app_controller) # app_c = eval(app.app_controller)
obj = app_c.new # obj = app_c.new
obj_auth = obj.send "auth" # obj_auth = obj.send "auth"
[:app_obj => app,:auth_field => obj_auth] # [:app_obj => app,:auth_field => obj_auth]
end # end
@module_apps = ModuleApp.all
end end
end end

View File

@ -12,4 +12,22 @@ class Admin::ModuleAppsController < ApplicationController
format.js {} format.js {}
end end
end end
def edit
@module_app = ModuleApp.find(params[:id])
end
def update
@module_app = ModuleApp.find(params[:id])
unless params['module_app']['enable_frontend'].nil?
@module_app.update_attribute('enable_frontend',params['module_app']['enable_frontend'])
@module_app.save!
end
@attribute = @module_app
respond_to do |format|
format.html { redirect_to :action => :index }
format.js { render 'admin/attributes/toggle_enable' }
end
end
end end

View File

@ -0,0 +1,6 @@
module Admin::AppAuthHelper
def on_off_switch(attribute,attribute_type)
link_to t(:enable), eval("admin_#{attribute_type}_path(attribute, :authenticity_token => form_authenticity_token, :#{attribute_type} => {:disabled => true})"), :remote => true, :method => :put, :id => "disable_#{attribute.id}", :style => "display:#{attribute.is_disabled? ? 'none' : ''}", :class => 'switch'
link_to t(:disable), eval("admin_#{attribute_type}_path(attribute, :authenticity_token => form_authenticity_token, :#{attribute_type} => {:disabled => false})"), :remote => true, :method => :put, :id => "enable_#{attribute.id}", :style => "display:#{attribute.is_disabled? ? '' : 'none'}", :class => 'switch'
end
end

View File

@ -1,32 +1,52 @@
<% content_for :secondary do %> <% content_for :secondary do %>
<div id='user_list'> <% #render 'side_bar' %>
<div class="role_list"> <% end %>
<h1>User Role</h1>
<ul class="list">
<% @roles.each do |role| %>
<li class="set_1"><%= link_to content_tag(:span, "Role") %></li>
<% end -%>
</ul>
</div>
</div>
<% end -%>
<h1><%= t('admin.list_app_auths') %></h1>
<div class="main_list">
<%= flash_messages %>
<div class="button_bar up">
<% #link_to t('admin.new_user'), new_admin_user_path, :class => 'new' %>
</div>
<table> <table>
<thead>
<tr> <tr>
<th><%= t('admin.app.name') %></th> <td><%= t('admin.app.title') %></td>
<th><%= t('admin.description') %></th> <td><%= t('admin.app.description') %></td>
<td><%= t('admin.app.use_status') %></td>
<td><%= t('admin.app.autdor') %></td>
<td><%= t('admin.app.organization') %></td>
<td><%= t('admin.app.version') %></td>
<td class="action"><%= t('admin.action') %></td>
</tr> </tr>
</thead>
<% @app_auth_data.each do |app| %> <tbody>
<tr> <% @module_apps.each do |module_app| %>
<td><%= app[0][:app_obj].title %></td> <tr class="have" id="attribute_<%= module_app.id %>" class="have <%= "#{module_app.enable_frontend? ? 'disable' : ''}" %>">
<% app[0][:auth_field].each do |unit| %> <td class="name"><%= module_app.title %></td>
<td class="name"><%= module_app.intro %></td>
<td> <td>
<%= render :partial => "auth_unit",:locals => {:unit => unit } %> <% attribute_type = "module_app" %>
<% attribute = module_app %>
<%= link_to t(:enable), admin_module_app_path(attribute, :authenticity_token => form_authenticity_token, :module_app => {:enable_frontend => true}), :remote => true, :method => :put, :id => "disable_#{attribute.id}", :style => "display:#{attribute.enable_frontend ? 'none' : ''}", :class => 'switch' %>
<%= link_to t(:disable), admin_module_app_path(attribute, :authenticity_token => form_authenticity_token, :module_app => {:enable_frontend => false}), :remote => true, :method => :put, :id => "enable_#{attribute.id}", :style => "display:#{attribute.enable_frontend ? '' : 'none'}", :class => 'switch' %>
</td> </td>
<%end%> <td class="email"><%= module_app.author %></td>
<td class="email"><%= module_app.organization %></td>
<td class="admin"><%= module_app.version %></td>
<td class="action">
<%= link_to t(:show), admin_module_app_path(module_app), :class => 'show' %>
<%= link_to t(:edit), edit_admin_module_app_path(module_app), :class => 'edit' %>
<%= link_to t(:delete), admin_module_app_path(module_app), :class => 'delete', :confirm => t('sure?'), :method => :delete %>
</td>
</tr>
<tr>
<td colspan="5"></td>
</tr> </tr>
<% end %> <% end %>
</tbody>
</table> </table>
<div class="button_bar">
<%# link_to t('admin.new_user'), new_admin_user_path, :class => 'new' %>
</div>
</div>