category and tags added and also edit page

This commit is contained in:
Harry Bomrah 2014-12-02 20:21:20 +08:00
parent f73ca8846b
commit 40e007de85
6 changed files with 197 additions and 8 deletions

View File

@ -1,16 +1,37 @@
# encoding: utf-8
class Admin::RegisteredSitesController < OrbitAdminController
before_action ->(module_app = @app_title) { set_variables module_app }
def index
@registeredsites = RegisteredSite.all
@registeredsites = RegisteredSite.all.order_by(sort)
.with_categories(filters("category"))
.with_tags(filters("tag"))
@table_fields = table_fields
@filter_fields = {}
@registeredsites = @registeredsites.page(params[:page]).per(10)
@tags = @module_app.tags
@categories = @module_app.categories.enabled
@filter_fields = filter_fields_without_status(@categories, @tags)
@registeredsites = search_data(@registeredsites,[:title]).page(params[:page]).per(10)
if request.xhr?
render :partial => "index"
end
end
def edit
@registered_site = RegisteredSite.find(params[:id])
if can_edit_or_delete?(@registered_site)
else
render_401
end
end
def update
uid = params[:id].split('-').last
registered_site = RegisteredSite.find_by(:uid => uid)
registered_site.update_attributes(registered_site_params)
registered_site.save
redirect_to params['referer_url']
end
def change_access_status
status = params[:status]
site = RegisteredSite.find_by(:uid => params[:uid])
@ -29,6 +50,10 @@ class Admin::RegisteredSitesController < OrbitAdminController
private
def table_fields
[:domain, :admin_email, :status, :permission]
[:domain, :admin_email, :status, :category, :tags, :permission]
end
def registered_site_params
params.require(:registered_site).permit!
end
end

View File

@ -1,9 +1,13 @@
class RegisteredSite
include Mongoid::Document
include Mongoid::Timestamps
include OrbitTag::Taggable
include OrbitCategory::Categorizable
include Slug
field :site_domain
field :title, as: :slug_title, localize: true
field :description, localize: true
field :access_granted, type: Boolean, :default => false
field :admin_email
field :site_confirmed, type: Boolean, :default => false
@ -20,4 +24,8 @@ class RegisteredSite
self.save
end
def active?
return self.access_granted && self.site_confirmed
end
end

View File

@ -0,0 +1,123 @@
<% content_for :page_specific_css do %>
<%= stylesheet_link_tag "lib/main-forms" %>
<%= stylesheet_link_tag "lib/fileupload" %>
<%= stylesheet_link_tag "lib/main-list" %>
<% end %>
<% content_for :page_specific_javascript do %>
<%= javascript_include_tag "lib/bootstrap-fileupload" %>
<%= javascript_include_tag "lib/bootstrap-datetimepicker" %>
<%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %>
<%= javascript_include_tag "lib/file-type" %>
<%= javascript_include_tag "lib/module-area" %>
<% end %>
<!-- Input Area -->
<div class="input-area">
<!-- Module Tabs -->
<div class="nav-name"><strong><%= t(:module) %></strong></div>
<ul class="nav nav-pills module-nav">
<li class="active"><a href="#basic" data-toggle="tab"><%= t(:basic) %></a></li>
<li><a href="#tag" data-toggle="tab"><%= t(:tags) %></a></li>
</ul>
<!-- Module -->
<div class="tab-content module-area">
<!-- Basic Module -->
<div class="tab-pane fade in active" id="basic">
<!-- Site domain -->
<div class="control-group">
<label class="control-label muted"><%= t(:domain) %></label>
<div class="controls">
<a href="http://<%= @registered_site.site_domain %>" target="_blank"><%= @registered_site.site_domain %></a>
</div>
</div>
<!-- Category -->
<div class="control-group">
<label class="control-label muted"><%= t(:category) %></label>
<div class="controls">
<%= select_category(f, @module_app) %>
</div>
</div>
<!-- Admin email -->
<div class="control-group">
<label class="control-label muted"><%= t(:email) %></label>
<div class="controls">
<%= f.text_field :admin_email %>
</div>
</div>
</div>
<!-- Tag Module -->
<div class="tab-pane fade" id="tag">
<div class="control-group">
<label class="control-label muted"><%= t(:tags) %></label>
<%= select_tags(f, @module_app) %>
</div>
</div>
</div>
<!-- Language Tabs -->
<div class="nav-name"><strong><%= t(:language) %></strong></div>
<ul class="nav nav-pills language-nav">
<% @site_in_use_locales.each_with_index do |locale, i| %>
<li class="<%= 'active' if i == 0 %>">
<a data-toggle="tab" href=".<%= locale %>"><%= t(locale) %></a>
</li>
<% end %>
</ul>
<!-- Language -->
<div class="tab-content language-area">
<% @site_in_use_locales.each_with_index do |locale, i| %>
<div class="<%= locale %> tab-pane fade <%= ( i == 0 ) ? "in active" : '' %>">
<!-- Title-->
<div class="control-group input-title">
<label class="control-label muted"><%= t(:title) %></label>
<div class="controls">
<%= f.fields_for :title_translations do |f| %>
<%= f.text_field locale, class: "input-block-level", placeholder: t(:title), value: (@registered_site.title_translations[locale] rescue nil) %>
<% end %>
</div>
</div>
<!-- Content -->
<div class="control-group input-content">
<label class="control-label muted"><%= t(:content) %></label>
<div class="controls">
<div class="textarea">
<%= f.fields_for :description_translations do |f| %>
<%= f.cktext_area locale, rows: 5, class: "input-block-level", :value => (@registered_site.description_translations[locale] rescue nil) %>
<% end %>
</div>
</div>
</div>
</div>
<% end %>
</div>
</div>
<!-- Form Actions -->
<div class="form-actions">
<%= get_referer_url[:action] rescue "" %>
<%= f.submit t('submit'), class: 'btn btn-primary' %>
<input type="hidden" name="referer_url" value="<%= get_referer_url %>">
<%= link_to t('cancel'), admin_registered_sites_path, :class=>"btn" %>
</div>

View File

@ -10,19 +10,36 @@
<tbody>
<% @registeredsites.each do |site| %>
<tr>
<td><a href="http://<%= site.site_domain %>/" target="_blank"><%= site.site_domain %></a></td>
<td>
<a href="http://<%= site.site_domain %>/" target="_blank"><%= site.title.nil? ? site.site_domain : site.title %></a>
<div class="quick-edit">
<ul class="nav nav-pills">
<% if can_edit_or_delete?(site) %>
<li><a href="/admin/registered_sites/<%= site.id.to_s %>/edit"><%= t(:edit) %></a></li>
<% end %>
</ul>
</div>
</td>
<td><%= site.admin_email %></td>
<td>
<% if !site.site_confirmed %>
<span class="label label-important"><%= t("registered_sites.site_inactive") %></span><br />
<span class="badge badge-important"><%= t("registered_sites.site_inactive") %></span><br />
<%= t("registered_sites.email_not_confirmed") %>
<% elsif !site.access_granted %>
<span class="label label-important"><%= t("registered_sites.site_inactive") %></span><br />
<span class="badge badge-important"><%= t("registered_sites.site_inactive") %></span><br />
<%= t("registered_sites.site_permission_revoked") %>
<% else %>
<span class="label label-success"><%= t("registered_sites.site_active") %></span><br />
<span class="badge badge-success"><%= t("registered_sites.site_active") %></span><br />
<% end %>
</td>
<td><%= site.category.nil? ? "Category not assigned" : "<span class='label label-info'>#{site.category.title}</span>".html_safe %></td>
<td>
<% site.tags.each do |tag| %>
<span class="label">
<%= tag.name %>
</span>
<% end %>
</td>
<td>
<% if !site.site_confirmed %>
<a class="btn btn-success" disabled="disabled"> Grant </a>

View File

@ -0,0 +1,6 @@
<%= form_for @registered_site, url: admin_registered_site_path(@registered_site), html: {class: "form-horizontal main-forms previewable"} do |f| %>
<fieldset>
<div class="line" style="width:auto; height:2px; background-color:<%= @registered_site.active? ? "green" : "red" %>;"></div>
<%= render :partial => 'form', locals: {f: f} %>
</fieldset>
<% end %>

View File

@ -5,6 +5,8 @@ module RegisteredSites
module_label "registered_sites.registered_sites"
base_url File.expand_path File.dirname(__FILE__)
authorizable
taggable "RegisteredSite"
categorizable
side_bar do
head_label_i18n 'registered_sites.registered_sites', icon_class: "icons-earth"
@ -17,6 +19,14 @@ module RegisteredSites
:priority=>1,
:active_for_action=>{'admin/registered_sites'=>"index"},
:available_for => 'users'
context_link 'categories',
:link_path=>"admin_module_app_categories_path" ,
:link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'registered_site').id}",
:priority=>2,
:active_for_action=>{'admin/registered_sites'=>'categories'},
:active_for_category => 'RegisteredSite',
:available_for => 'managers'
end
end
end