added mechanism to write description and upload photos
This commit is contained in:
parent
172b1332dd
commit
d609bcb817
|
@ -13,6 +13,12 @@ class Admin::AdminModulesController < OrbitAdminController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def uploadfiles
|
||||||
|
@rm = RegisteredModule.find(params[:module_id])
|
||||||
|
@categories = @module_app.categories.enabled
|
||||||
|
@tags = @module_app.tags
|
||||||
|
end
|
||||||
|
|
||||||
def approve_modules
|
def approve_modules
|
||||||
@rm = RegisteredModule.find(params[:module_id])
|
@rm = RegisteredModule.find(params[:module_id])
|
||||||
@categories = @module_app.categories.enabled
|
@categories = @module_app.categories.enabled
|
||||||
|
@ -52,9 +58,19 @@ class Admin::AdminModulesController < OrbitAdminController
|
||||||
|
|
||||||
def update
|
def update
|
||||||
rm = RegisteredModule.find(params[:id])
|
rm = RegisteredModule.find(params[:id])
|
||||||
rm.update_attributes(registered_module_params)
|
p = registered_module_params
|
||||||
|
p[:module_show_files] = rm.module_show_files + p[:module_show_files]
|
||||||
|
rm.update_attributes(p)
|
||||||
rm.save
|
rm.save
|
||||||
|
if !params[:images_to_destroy].blank?
|
||||||
|
images = ModuleShowFile.where(:id.in => params[:images_to_destroy])
|
||||||
|
images.destroy_all
|
||||||
|
end
|
||||||
|
if request.xhr?
|
||||||
render :json => {"success" => true}.to_json
|
render :json => {"success" => true}.to_json
|
||||||
|
else
|
||||||
|
redirect_to admin_admin_modules_path
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def install_module
|
def install_module
|
||||||
|
@ -104,9 +120,18 @@ class Admin::AdminModulesController < OrbitAdminController
|
||||||
render :json=>{"success" => true}.to_json
|
render :json=>{"success" => true}.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def upload_module_image
|
||||||
|
file = ModuleShowFile.create(show_file_params)
|
||||||
|
render :json => {"success" => true,"id" => file.id.to_s}.to_json
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def show_file_params
|
||||||
|
params.require(:module_show_file).permit!
|
||||||
|
end
|
||||||
|
|
||||||
def site_list_without_module(rm)
|
def site_list_without_module(rm)
|
||||||
registered_sites = []
|
registered_sites = []
|
||||||
if !rm.nil?
|
if !rm.nil?
|
||||||
|
@ -143,7 +168,16 @@ class Admin::AdminModulesController < OrbitAdminController
|
||||||
|
|
||||||
|
|
||||||
def registered_module_params
|
def registered_module_params
|
||||||
params.require(:registered_module).permit!
|
p = params.require(:registered_module).permit!
|
||||||
|
if p[:module_show_files].present?
|
||||||
|
images = []
|
||||||
|
p[:module_show_files].each do |id|
|
||||||
|
image = ModuleShowFile.find(id) rescue nil
|
||||||
|
images << image if !image.nil?
|
||||||
|
end
|
||||||
|
p[:module_show_files] = images
|
||||||
|
end
|
||||||
|
p
|
||||||
end
|
end
|
||||||
|
|
||||||
def table_fields
|
def table_fields
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
class ModuleShowFile
|
||||||
|
include Mongoid::Document
|
||||||
|
include Mongoid::Timestamps
|
||||||
|
|
||||||
|
mount_uploader :image, ImageUploader
|
||||||
|
|
||||||
|
belongs_to :registered_module
|
||||||
|
end
|
|
@ -8,6 +8,7 @@ class RegisteredModule
|
||||||
field :module_key
|
field :module_key
|
||||||
field :git_path
|
field :git_path
|
||||||
field :name, as: :slug_title, localize: true
|
field :name, as: :slug_title, localize: true
|
||||||
|
field :description, localize: true
|
||||||
field :create_user_id, type: BSON::ObjectId
|
field :create_user_id, type: BSON::ObjectId
|
||||||
field :update_user_id, type: BSON::ObjectId
|
field :update_user_id, type: BSON::ObjectId
|
||||||
field :approved, type: Boolean, :default => false
|
field :approved, type: Boolean, :default => false
|
||||||
|
@ -17,6 +18,7 @@ class RegisteredModule
|
||||||
|
|
||||||
mount_uploader :template, TemplateUploader
|
mount_uploader :template, TemplateUploader
|
||||||
|
|
||||||
|
has_many :module_show_files, :dependent => :destroy
|
||||||
|
|
||||||
def reject
|
def reject
|
||||||
self.completed = false
|
self.completed = false
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
<a class="btn btn-small btn-danger action-btns" data-id="<%= rm.id.to_s %>" href="/admin/admin_modules/uninstall_site_list?id=<%= rm.id.to_s %>" for="uninstallation">Uninstall</a>
|
<a class="btn btn-small btn-danger action-btns" data-id="<%= rm.id.to_s %>" href="/admin/admin_modules/uninstall_site_list?id=<%= rm.id.to_s %>" for="uninstallation">Uninstall</a>
|
||||||
<a class="btn btn-small btn-warning action-btns" data-id="<%= rm.id.to_s %>" href="/admin/admin_modules/revokelist?id=<%= rm.id.to_s %>" for="revoke_access">Revoke Access</a>
|
<a class="btn btn-small btn-warning action-btns" data-id="<%= rm.id.to_s %>" href="/admin/admin_modules/revokelist?id=<%= rm.id.to_s %>" for="revoke_access">Revoke Access</a>
|
||||||
<a class="btn btn-small btn-success action-btns" data-id="<%= rm.id.to_s %>" href="/admin/admin_modules/grantlist?id=<%= rm.id.to_s %>" for="grant_access">Grant Access</a>
|
<a class="btn btn-small btn-success action-btns" data-id="<%= rm.id.to_s %>" href="/admin/admin_modules/grantlist?id=<%= rm.id.to_s %>" for="grant_access">Grant Access</a>
|
||||||
<a class="btn btn-small edit-btn" href="/admin/admin_modules/approve?module_id=<%= rm.id.to_s %>">Edit</a>
|
<a class="btn btn-small" href="/admin/admin_modules/uploadfiles?module_id=<%= rm.id.to_s %>">Edit</a>
|
||||||
</td>
|
</td>
|
||||||
<% else %>
|
<% else %>
|
||||||
<td>
|
<td>
|
||||||
|
|
|
@ -0,0 +1,257 @@
|
||||||
|
<% content_for :page_specific_css do %>
|
||||||
|
<%= stylesheet_link_tag "lib/main-forms" %>
|
||||||
|
<%= stylesheet_link_tag "lib/main-list" %>
|
||||||
|
<%= stylesheet_link_tag "lib/dropzone" %>
|
||||||
|
<%= stylesheet_link_tag "//maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" %>
|
||||||
|
<%= stylesheet_link_tag "//cdnjs.cloudflare.com/ajax/libs/animate.css/3.2.6/animate.min.css" %>
|
||||||
|
<% end %>
|
||||||
|
<% content_for :page_specific_javascript do %>
|
||||||
|
<%= javascript_include_tag "lib/dropzone" %>
|
||||||
|
<%= 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 %>
|
||||||
|
<style>
|
||||||
|
.message{
|
||||||
|
float: right;
|
||||||
|
text-align: center;
|
||||||
|
width: 125px;
|
||||||
|
padding: 25px;
|
||||||
|
background-color: #7a7a7a;
|
||||||
|
color: #fff;
|
||||||
|
font-size: 18px;
|
||||||
|
border-radius: 50px 0 0 50px;
|
||||||
|
}
|
||||||
|
.message .upload-text{
|
||||||
|
margin-left: 5px;
|
||||||
|
}
|
||||||
|
.group-clear-4{
|
||||||
|
display: inline-block;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
.group-clear-4 .group-item{
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
.group-clear-4 img{
|
||||||
|
width: 150px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<%= form_for @rm, url: admin_admin_module_path(@rm.id), html: {class: "form-horizontal main-forms previewable", id: "module_edit_form"} do |f| %>
|
||||||
|
<fieldset>
|
||||||
|
<div class="message hide">
|
||||||
|
<i class="fa fa-refresh fa-spin"></i>
|
||||||
|
<span class="upload-text">Uploading...</span>
|
||||||
|
</div>
|
||||||
|
<!-- 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>
|
||||||
|
<li><a href="#upload" data-toggle="tab"><%= t(:images) %></a></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<!-- Module -->
|
||||||
|
<div class="tab-content module-area">
|
||||||
|
|
||||||
|
<!-- Basic Module -->
|
||||||
|
<div class="tab-pane fade in active" id="basic">
|
||||||
|
|
||||||
|
<!-- Category -->
|
||||||
|
<div class="control-group">
|
||||||
|
<label class="control-label muted"><%= t(:category) %></label>
|
||||||
|
<div class="controls">
|
||||||
|
<%= select_category(f, @module_app) %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Git Path -->
|
||||||
|
<div class="control-group">
|
||||||
|
<label class="control-label muted"><%= t("register_module.git_path") %></label>
|
||||||
|
<div class="controls col-5">
|
||||||
|
<%= f.text_field :git_path, :class => "input-xxlarge" %>
|
||||||
|
</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 class="tab-pane fade" id="upload">
|
||||||
|
<div class="control-group">
|
||||||
|
<label class="control-label muted"><%= t(:images) %></label>
|
||||||
|
<div class="controls">
|
||||||
|
<div class="group group-clear-4 clearfix">
|
||||||
|
<% @rm.module_show_files.each do |image| %>
|
||||||
|
<div class="group-item col-md-3">
|
||||||
|
<div class="group-item-inner">
|
||||||
|
<img class="group-img" src="<%= image.image.thumb.url %>">
|
||||||
|
<div class="group-actions">
|
||||||
|
<label class="group-label" for="image_<%= image.id.to_s %>">
|
||||||
|
<input class="group-checkbox" id="image_<%= image.id.to_s %>" type="checkbox" name="images_to_destroy[]" value="<%= image.id.to_s %>" />
|
||||||
|
Delete Image
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<div class="dropzone dropzone-pool" id="module-files">
|
||||||
|
<div class="dropzone-previews" id="module-files-container"></div>
|
||||||
|
</div>
|
||||||
|
<button class="remove_image_btn btn btn-warning">
|
||||||
|
<i class="fa fa-ban"></i>
|
||||||
|
<span>Remove all images</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div id="image_ids">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</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" : '' %>">
|
||||||
|
|
||||||
|
<!-- 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 => (@rm.description_translations[locale] rescue nil) %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-actions">
|
||||||
|
<%= f.submit t('submit'), class: 'btn btn-primary', :id => "module-form-btn" %>
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
<% end %>
|
||||||
|
<script>
|
||||||
|
Dropzone.autoDiscover = false;
|
||||||
|
var image_id_panel = $("#image_ids"),
|
||||||
|
total_images = 0;
|
||||||
|
var subUnitImageDropzone = new Dropzone("div#module-files", {
|
||||||
|
url : "/admin/admin_modules/upload_module_image",
|
||||||
|
previewsContainer : "#module-files-container",
|
||||||
|
paramName : "module_show_file[image]",
|
||||||
|
clickable : true,
|
||||||
|
autoProcessQueue : false,
|
||||||
|
maxFilesize : 2,
|
||||||
|
addRemoveLinks : true,
|
||||||
|
uploadMultiple : false,
|
||||||
|
accept: function(file, done) {
|
||||||
|
var regex = new RegExp(/(\.|\/)(gif|jpe?g|png)$/i)
|
||||||
|
if(regex.test(file.name)){
|
||||||
|
total_images++;
|
||||||
|
done();
|
||||||
|
}else{
|
||||||
|
this.removeFile(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
$(".remove_image_btn").on("click",function(){
|
||||||
|
subUnitImageDropzone.removeAllFiles();
|
||||||
|
return false;
|
||||||
|
})
|
||||||
|
|
||||||
|
subUnitImageDropzone.on("success",function(file,data){
|
||||||
|
image_id_panel.append("<input type='hidden' name='registered_module[module_show_files][]' value='" + data.id + "' />");
|
||||||
|
total_images--;
|
||||||
|
if(total_images == 0){
|
||||||
|
submitForm();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
subUnitImageDropzone.on("sending",function(file,xhr,obj){
|
||||||
|
obj.append("authenticity_token",$("form#module_edit_form input[name=authenticity_token]").val());
|
||||||
|
})
|
||||||
|
|
||||||
|
var doImagesUpload = function(){
|
||||||
|
subUnitImageDropzone.processQueue();
|
||||||
|
subUnitImageDropzone.on("complete", function(file) {
|
||||||
|
var filesCount = subUnitImageDropzone.getQueuedFiles().length;
|
||||||
|
if(filesCount > 0){
|
||||||
|
doImagesUpload();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#module-form-btn").on("click",function(){
|
||||||
|
if(subUnitImageDropzone.getQueuedFiles().length > 0){
|
||||||
|
doImagesUpload();
|
||||||
|
}else{
|
||||||
|
submitForm();
|
||||||
|
}
|
||||||
|
// uploading all the files
|
||||||
|
$(".message")
|
||||||
|
.removeClass("hide")
|
||||||
|
.addClass("animated slideInRight");
|
||||||
|
return false;
|
||||||
|
})
|
||||||
|
|
||||||
|
var submitForm = function(){
|
||||||
|
if(subUnitImageDropzone.getQueuedFiles().length > 0){
|
||||||
|
return false;
|
||||||
|
}else{
|
||||||
|
$(".upload-status-notice span.upload-text").text("Submitting");
|
||||||
|
$("form#module_edit_form").submit();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function equalHeight(items) {
|
||||||
|
if (typeof items === 'string' && items.length > 0) {
|
||||||
|
var $items = $(items);
|
||||||
|
var $this = null;
|
||||||
|
var maxHeight = -1;
|
||||||
|
|
||||||
|
// when images are loaded
|
||||||
|
$items.find('img').load(function() {
|
||||||
|
console.log('g')
|
||||||
|
$.each($items, function(i, val) {
|
||||||
|
$this = $(this);
|
||||||
|
if ($this.outerHeight() > maxHeight) {
|
||||||
|
maxHeight = $this.outerHeight();
|
||||||
|
}
|
||||||
|
console.log($this)
|
||||||
|
}).css('min-height', maxHeight + 'px');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
equalHeight('.group-item-inner');
|
||||||
|
|
||||||
|
</script>
|
|
@ -20,4 +20,5 @@ en:
|
||||||
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
|
||||||
|
git_path: Git Path
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ zh_tw:
|
||||||
admin_area: Admin Area
|
admin_area: Admin Area
|
||||||
new_module: Register Module
|
new_module: Register Module
|
||||||
new_widget: Register Widget
|
new_widget: Register Widget
|
||||||
|
git_path: Git Path
|
||||||
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
|
||||||
|
|
|
@ -14,6 +14,8 @@ 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 "/admin_modules/uploadfiles" => "admin_modules#uploadfiles"
|
||||||
|
post "/admin_modules/upload_module_image" => "admin_modules#upload_module_image"
|
||||||
get "/register_desktop_widgets/approve_widget" => "register_desktop_widgets#approve_widget"
|
get "/register_desktop_widgets/approve_widget" => "register_desktop_widgets#approve_widget"
|
||||||
resources :register_modules
|
resources :register_modules
|
||||||
resources :admin_modules
|
resources :admin_modules
|
||||||
|
|
Loading…
Reference in New Issue