added desktop widget mechanism

This commit is contained in:
Harry Bomrah 2015-02-02 16:06:45 +05:30
parent 3a1d0e6c4e
commit e6917a2e37
8 changed files with 255 additions and 2 deletions

View File

@ -0,0 +1,43 @@
class Admin::RegisterDesktopWidgetsController < OrbitAdminController
def index
@table_fields = table_fields
if current_user.is_admin?
@registered_widgets = RegisteredDesktopWidget.all.desc(:created_at)
else
@registered_widgets = RegisteredDesktopWidget.where(:create_user_id => current_user.id).desc(:created_at)
end
if request.xhr?
render :partial => "my_registered_widget"
end
end
def create
rdw = RegisteredDesktopWidget.new(registered_desktop_widget_params)
rdw.create_user_id = current_user.id
rdw.save
render :json => {"success" => true}.to_json
end
def table_fields
[:widget_name_, :widget_uid, :status, :actions]
end
def update
rdw = RegisteredDesktopWidget.find(params[:id]) rescue nil
if !rdw.nil?
rdw.update_attributes(registered_desktop_widget_params)
rdw.save
end
render :json => {"success" => true}.to_json
end
def approve_widget
rdw = RegisteredDesktopWidget.find(params[:id]) rescue nil
if !rdw.nil?
rdw.approved = true
rdw.save
end
redirect_to admin_register_desktop_widgets_path(:page => params[:page])
end
private
def registered_desktop_widget_params
params.require(:registered_widget).permit!
end
end

View File

@ -0,0 +1,24 @@
class RegisteredDesktopWidget
include Mongoid::Document
include Mongoid::Timestamps
include OrbitCategory::Categorizable
include OrbitTag::Taggable
include Slug
field :name, as: :slug_title, localize: true
field :widget_key
field :create_user_id, type: BSON::ObjectId
field :update_user_id, type: BSON::ObjectId
field :approved, type: Boolean, :default => false
scope :approve, ->{ where(approved: true) }
mount_uploader :widget, TemplateUploader
mount_uploader :icon, ImageUploader
after_create :save_widget_key
def save_widget_key
self.widget_key = self.name.parameterize + "-" + self.uid
self.save
end
end

View File

@ -0,0 +1,119 @@
<table class="table main-list">
<thead>
<tr class="sort-header">
<% @table_fields.each_with_index do |f,i| %>
<%= thead(f) %>
<% end %>
</tr>
</thead>
<tbody>
<% @registered_widgets.each do |rw| %>
<tr>
<td><%= rw.name rescue "" %></td>
<td><%= rw.widget_key %></td>
<% if rw.approved %>
<td>Approved</td>
<% else %>
<td>
<% if !rw.approved && current_user.is_admin? %>
<a class="btn btn-primary approve_btn" href="/admin/register_desktop_widgets/approve_widget?id=<%= rw.id.to_s %>">Approve</a>
<% elsif !rw.approved && !current_user.is_admin? %>
Approval Pending
<% else %>
Approved
<% end %>
</td>
<% end %>
<td>
<form class="register-form inline_forms form-inline pull-right" action="/admin/register_desktop_widgets/<%= rw.id.to_s %>" method="post" enctype="multipart/form-data">
<label>Widget :
<span class="btn btn-small">
<span class="fileupload-new">
<i class="icons-upload-2"></i>
<span class="file-name"></span>
</span>
<input type="file" class="hide registered-module-upload" name="registered_widget[widget]" data-fv-validation="zipfilecheck;" data-fv-messages="Only Zip file allowed.;" />
</span>
</label>
<label>Icon :
<span class="btn btn-small">
<span class="fileupload-new">
<i class="icons-docs"></i>
<span class="file-name"></span>
</span>
<input type="file" class="hide registered-module-upload" name="registered_widget[icon]" data-fv-validation="imagefilecheck;" data-fv-messages="Only images allowed.;" />
</span>
</label>
<input type="hidden" value="patch" name="_method">
<input type="submit" disabled="disabled" value="Save" class="btn btn-small" />
</form>
</td>
</tr>
<% end %>
</tbody>
</table>
<script type="text/javascript">
$('.registered-module-upload').on('change', function(event) {
$(this).prev('span').find('.file-name').text(event.target.files[0].name);
$(this).parents(".inline_forms").find("input[type=submit]").removeAttr("disabled");
$(this).next('.validator_error_class').remove();
})
$(".approve_btn").on("click",function(){
})
$(".inline_forms").on("submit",function(){
var form_el = $(this),
formv = new FormValidator(form_el);
formv.validate_functions.zipfilecheck = function(value,element){
if(value == "") return true;
var ext = value.split(".");
return (ext[ext.length - 1] == "zip" ? true : false);
}
formv.validate_functions.imagefilecheck = function(value,element){
if(value == "") return true;
var ext = value.split(".");
ext = ext[ext.length - 1];
return (ext == "png" || ext == "jpg" ? true : false);
}
var v = formv.isFormValidated();
if(v){
$(this).ajaxSubmit({
success : function(){
form_el.resetForm();
form_el.find(".file-name").text("");
form_el.find("input[type=submit]").attr("disabled","disabled");
}
});
}
return false;
})
</script>
<style type="text/css">
.register-form {
margin: 0 20px 0 0;
}
.register-form label {
float: left;
margin-right: 5px;
margin-bottom: 0;
}
.validator_error_class {
display: inline-block;
}
.file-name {
position: relative;
top: 4px;
left: 4px;
display: inline-block;
max-width: 120px;
line-height: 1.2;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.fileupload-new:before {
display: inline-block;
}
</style>

View File

@ -0,0 +1,51 @@
<%= javascript_include_tag 'validator' %>
<%= javascript_include_tag "plugin/jquery.form.min" %>
<%#= render_filter @filter_fields, "index_table" %>
<span id="index_table">
<%= render 'my_registered_widgets'%>
</span>
<div class="bottomnav clearfix" style="left: 81px;">
<div class="action pull-right">
<a class="btn btn-primary" id="registerNewWidgetBtn">
<%= t("register_module.new_widget") %>
</a>
</div>
<div class="pagination pagination-centered"></div>
</div>
<div id="register_widget" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Register Widget</h3>
</div>
<div class="modal-body" style="padding:15px 0 0;">
<div id="step1" style="padding:15px;" class="step">
<form action="/admin/register_desktop_widgets" method="post" enctype="multipart/form-data" class="form-horizontal" id="desktop_widget_register_form">
<% @site_valid_locales.each do |locale| %>
<div class="control-group">
<label class="control-label" for="inputName<%= locale.capitalize.to_s %>">Widget Name (<%= t(locale.to_s) %>): </label>
<div class="controls">
<input type="text" id="inputName<%= locale.capitalize.to_s %>" name="registered_widget[name_translations][<%= locale.to_s %>]" data-fv-validation="required;" data-fv-messages="Cannot be empty;">
</div>
</div>
<% end %>
</form>
</div>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button class="btn btn-primary" id="registerDesktopWidget">Register</button>
</div>
</div>
<script type="text/javascript">
$("#registerNewWidgetBtn").on("click",function(){
$("#register_widget").modal("show");
})
$("#registerDesktopWidget").on("click",function(){
$("form#desktop_widget_register_form").ajaxSubmit({
success : function(){
window.location.reload();
}
});
})
</script>

View File

@ -4,14 +4,18 @@ en:
status: Status status: Status
permission: Access permission: Access
module_name_: Module Name module_name_: Module Name
widget_name_: Widget Name
widget_uid: Widget UID
developed_by: Developed By developed_by: Developed By
actions: Actions actions: Actions
register_module: register_module:
customization_log: Customization Log customization_log: Customization Log
desktop_widgets: Desktop Widgets
register_module: Registered Modules register_module: Registered Modules
admin_area: Admin Area admin_area: Admin Area
all: All all: All
new_module: Register Module new_module: Register Module
new_widget: Register Widget
my: My Modules my: My Modules
email_not_confirmed: Email not confirmed. email_not_confirmed: Email not confirmed.
site_permission_revoked: Site permission revoked. site_permission_revoked: Site permission revoked.

View File

@ -3,17 +3,21 @@ zh_tw:
admin_email: Admin Email admin_email: Admin Email
status: Status status: Status
permission: Access permission: Access
module_name_: Module Name module_name_: Module Name
widget_name_: Widget Name
widget_uid: Widget UID
developed_by: Developed By developed_by: Developed By
actions: Actions actions: Actions
register_module: register_module:
customization_log: Customization Log customization_log: Customization Log
register_module: Registered Modules register_module: Registered Modules
desktop_widgets: Desktop Widgets
all: All all: All
my: My Modules my: My Modules
admin_area: Admin Area admin_area: Admin Area
new_module: Register Module new_module: Register Module
new_widget: Register Widget
email_not_confirmed: Email not confirmed. email_not_confirmed: Email not confirmed.
site_permission_revoked: Site permission revoked. site_permission_revoked: Site permission revoked.
site_active: Site Active site_active: Site Active

View File

@ -14,8 +14,10 @@ Rails.application.routes.draw do
post "/admin_modules/uninstall" => "admin_modules#uninstall_module" post "/admin_modules/uninstall" => "admin_modules#uninstall_module"
post "/admin_modules/revoke" => "admin_modules#revoke_module" post "/admin_modules/revoke" => "admin_modules#revoke_module"
post "/admin_modules/grant" => "admin_modules#grant_module" post "/admin_modules/grant" => "admin_modules#grant_module"
get "/register_desktop_widgets/approve_widget" => "register_desktop_widgets#approve_widget"
resources :register_modules resources :register_modules
resources :admin_modules resources :admin_modules
resources :register_desktop_widgets
end end
end end

View File

@ -20,9 +20,15 @@ module RegisterModules
:active_for_action=>{'admin/register_modules'=>"index"}, :active_for_action=>{'admin/register_modules'=>"index"},
:available_for => 'users' :available_for => 'users'
context_link 'register_module.desktop_widgets',
:link_path=>"admin_register_desktop_widgets_path" ,
:priority=>2,
:active_for_action=>{'admin/register_desktop_widgets'=>"index"},
:available_for => 'users'
context_link 'register_module.admin_area', context_link 'register_module.admin_area',
:link_path=>"admin_admin_modules_path" , :link_path=>"admin_admin_modules_path" ,
:priority=>2, :priority=>3,
:active_for_action=>{'admin/admin_modules'=>"index"}, :active_for_action=>{'admin/admin_modules'=>"index"},
:available_for => 'managers' :available_for => 'managers'