Merge branch 'master' into ydu

This commit is contained in:
Harry Bomrah 2014-10-29 21:29:40 +08:00
commit 8f903ede08
18 changed files with 388 additions and 145 deletions

View File

@ -0,0 +1,191 @@
var StoreManager = function(section){
var storeArea = $("#store-area"),
loadingArea = storeArea.find(".loading-store"),
loadingAreaStatus = loadingArea.find(".loading-status"),
waitForStoreResponseCount = 0,
section = section,
formArea = storeArea.find(".form-area");
var initialize = function(){
loadingArea.find("img").show();
loadingAreaStatus.text("Contacting Ruling Store.");
loadingArea.find("p").eq(1).html("Please wait...");
setTimeout(step1,1000);
}
var step1 = function(){
$.ajax({
"type" : "get",
"dataType" : "json",
"url" : "/admin/store/check_credentials"
}).done(function(status){
if(status.success == true){
loadingAreaStatus.text("Checking permissions.");
setTimeout(step2,1000);
}else if(status.success == false){
setTimeout(loadRegisterForm,1000);
}
}).fail(showError);
}
var step2 = function(){
$.ajax({
"type" : "get",
"dataType" : "json",
"url" : "/admin/store/check_permissions"
}).done(function(data){
if(data.success){
loadingAreaStatus.text("Fetching store data.");
if(section == "templates"){
setTimeout(loadTemplateStore,1000);
}else if(section == "apps"){
setTimeout(loadAppStore,1000);
}
}else if(!data.success){
loadingArea.find("img").hide();
loadingAreaStatus.text(data.message);
if(data.error == "SITE_NOT_CONFIRMED"){
var resentBtn = $("<a href=''>Resend Email</a>");
resentBtn.on("click",function(){
resendEmail();
return false;
})
loadingArea.find("p").eq(1).html(resentBtn);
}else if(data.error == "SITE_PERMISSION_DENIED"){
loadingArea.find("p").eq(1).html("Please contact <a href='http://www.rulingcom.com/'>www.rulingcom.com</a>.");
}else{
loadingArea.find("p").eq(1).html("Please contact <a href='http://www.rulingcom.com/'>www.rulingcom.com</a>.");
}
}
}).fail(showError);
}
var loadTemplateStore = function(){
$.ajax({
"type" : "get",
"dataType" : "html",
"url" : "/admin/store/template_store"
}).done(function(html){
storeArea.html(html);
}).fail(showError);
}
var loadAppStore = function(){
$.ajax({
"type" : "get",
"dataType" : "html",
"url" : "/admin/store/app_store"
}).done(function(html){
storeArea.html(html);
}).fail(showError);
}
var loadTemplateStore = function(){
$.ajax({
"type" : "get",
"dataType" : "html",
"url" : "/admin/store/template_store"
}).done(function(html){
storeArea.html(html);
}).fail(showError);
}
var loadRegisterForm = function(){
loadingAreaStatus.text("Loading registeration form.")
$.ajax({
"type" : "get",
"dataType" : "html",
"url" : "/admin/store/register_form"
}).done(function(html){
loadingArea.hide();
formArea.html(html);
var form = formArea.find("form");
new FormValidator(form);
form.on("submit",function(){
var email = form.find("#inputEmail").val();
if(email){
loadingAreaStatus.text("Registering with Orbit Store.")
formArea.hide();
loadingArea.show();
$.ajax({
"type" : "post",
"url" : form.attr("action"),
"dataType" : "json",
"data" : {"email" : email}
}).done(function(data){
if(data.success){
loadingAreaStatus.text("Waiting for Store.");
setTimeout(waitForStoreResponse,500);
}else{
loadingArea.find("img").hide();
loadingAreaStatus.text(data.message);
loadingArea.find("p").eq(1).html("Please contact <a href='http://www.rulingcom.com/'>www.rulingcom.com</a>.");
}
}).fail(showError)
}
return false;
})
})
}
var waitForStoreResponse = function(){
$.ajax({
"type" : "get",
"dataType" : "json",
"url" : "/admin/store/check_credentials"
}).done(function(status){
if(status.success == true){
resendEmail();
}else if(status.success == false){
waitForStoreResponseCount++;
if(waitForStoreResponseCount > 5){
loadingArea.find("img").hide();
loadingAreaStatus.text("Orbit Store couldn't contact your server.");
loadingArea.find("p").eq(1).html("Please try again later or contact <a href='http://www.rulingcom.com/'>www.rulingcom.com</a>.");
}else{
setTimeout(waitForStoreResponse,500);
}
}
}).fail(showError);
}
var resendEmail = function(){
loadingArea.find("img").show();
loadingAreaStatus.text("Sending verification email.");
loadingArea.find("p").eq(1).html("Please wait...");
$.ajax({
"url" : "/admin/store/send_email",
"dataType" : "json",
"type" : "get"
}).done(function(data){
if(data.success){
loadingArea.find("img").hide();
loadingAreaStatus.text("Email sent. Please confirm and click on link below or refresh the page.");
var checkAgainBtn = $("<a href=''>Check Again</a>");
checkAgainBtn.on("click",function(){
initialize();
return false;
})
loadingArea.find("p").eq(1).html(checkAgainBtn);
}else{
loadingArea.find("img").hide();
loadingAreaStatus.text("Email couldn't be sent. You can try again or contact <a href='http://www.rulingcom.com'>www.rulingcom.com</a>");
loadingArea.find("p").eq(1).html("Please contact <a href='http://www.rulingcom.com/'>www.rulingcom.com</a>.");
}
}).fail(showError);
}
var showError = function(){
loadingArea.find("img").hide();
loadingAreaStatus.text("There was some unknown error.");
loadingArea.find("p").eq(1).html("Please try again later or contact <a href='http://www.rulingcom.com/'>www.rulingcom.com</a>.");
}
initialize();
}
// step 1 -> check connection to store server
// step 2 -> check for site confirmation and access permission

View File

@ -25,8 +25,9 @@ var FormValidator = function(form){
nospace : function(value){
return (/\s/.test(value) ? false : true);
},
email : function(){
email : function(value){
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(value);
}
}

View File

@ -3,20 +3,21 @@ class Admin::ModuleStoreController < OrbitAdminController
def index
@extensions = []
if current_site.site_token?
if current_site.store_confirmation
@extensions = get_extensions
@store_confirmation = true
else
@extensions = []
@store_confirmation = false
end
@downloaded_extensions = get_downloaded_extension
else
@store_confirmation = true
@extensions = []
@downloaded_extensions = get_downloaded_extension
end
@downloaded_extensions = get_downloaded_extension
# if current_site.site_token?
# if current_site.store_confirmation
# @extensions = get_extensions
# @store_confirmation = true
# else
# @extensions = []
# @store_confirmation = false
# end
# else
# @store_confirmation = true
# @extensions = []
# @downloaded_extensions = get_downloaded_extension
# end
end
def show

View File

@ -0,0 +1,69 @@
require "uri"
require "net/http"
class Admin::StoreController < OrbitAdminController
layout false
before_action :store_url
def check_credentials
if current_site.store_token.nil?
render :json => {"success" => false}.to_json
else
render :json => {"success" => true}.to_json
end
end
def register_form
end
def template_store
end
def app_store
end
def send_email
params_to_send = {'store_token' => current_site.store_token}
uri = URI.parse(@store_url)
http = Net::HTTP.new(uri.host,uri.port)
request = Net::HTTP::Get.new("/site/send_email")
request.body = params_to_send.to_query
response = http.request(request)
data = JSON.parse(response.body)
render :json => data.to_json
end
def check_permissions
params_to_send = {'store_token' => current_site.store_token}
uri = URI.parse(@store_url)
http = Net::HTTP.new(uri.host,uri.port)
request = Net::HTTP::Get.new("/site/permissions")
request.body = params_to_send.to_query
response = http.request(request)
data = JSON.parse(response.body)
if !data["success"] && data["error"] == "INVALID_SITE_TOKEN"
current_site.store_token = nil
current_site.save
end
render :json => data.to_json
end
def register_site
params_to_send = {'site_domain' => request.host_with_port, 'admin_email' => params["email"], "site_token" => current_site.uid}
uri = URI.parse(@store_url)
http = Net::HTTP.new(uri.host,uri.port)
request = Net::HTTP::Post.new("/register/site")
request.body = params_to_send.to_query
response = http.request(request)
data = JSON.parse(response.body)
render :json => data.to_json
end
private
def store_url
@store_url = "http://store.tp.rulingcom.com"
# @store_url = "http://localhost:3000"
end
end

View File

@ -29,7 +29,7 @@ class ApplicationController < ActionController::Base
if !params[:locale] and !session[:locale]
if current_site.enable_language_detection
browser_locale = request.env['HTTP_ACCEPT_LANGUAGE'].split(',').first.underscore rescue nil
session[:locale] = in_use_locales.include?(browser_locale.to_sym) ? browser_locale : nil
session[:locale] = (in_use_locales.include?(browser_locale.to_sym) ? browser_locale : nil) rescue nil
elsif current_site.default_locale
session[:locale] = current_site.default_locale
end

View File

@ -157,6 +157,7 @@ class MembersController < ApplicationController
def member_data(member, fields_to_show)
profile_data = []
fields_to_show.each do |field|
# debugger
case field['type']
when 'profile'
field_data = member.get_attribute_data(field) rescue {}
@ -166,7 +167,7 @@ class MembersController < ApplicationController
field_data = member.attribute_values.find_by(:key=>field['key']).get_field_value rescue {}
end
next if field_data.blank? or field_data['value'].blank?
if field['sort_order']
field_data['sort_value'] = field_data['val'].blank? ? field_data['value'] : field_data['val']
field_data['sort_value'] = (field_data['sort_value'].is_i? ? field_data['sort_value'].to_i : field_data['sort_value'] rescue field_data['sort_value'])

View File

@ -0,0 +1,14 @@
class StoreApiController < ApplicationController
def confirmation
site_token = params[:site_token]
store_token = params[:store_token]
puts current_site.to_s
if current_site.uid.eql?(site_token)
current_site.store_token = store_token
current_site.save
render :json => {"success" => true}.to_json
else
render :json => {"success" => false}.to_json
end
end
end

View File

@ -101,8 +101,16 @@ class AttributeField
if field_status.eql?(true)
@attribute_field_counter = role.attribute_fields.count rescue nil
@attribute_field = self.find(attribute_field_id) rescue nil
old_key = @attribute_field.key
@attribute_field.update(role_param)
@attribute_field.save
attribute_values = @attribute_field.attribute_values
if attribute_values.count > 0
attribute_values.each do |av|
av.key = role_param["key"]
av.save
end
end
@attribute_field[:af_count] = @attribute_field_counter
else
@attribute_field_counter = role.attribute_fields.count rescue nil

View File

@ -199,7 +199,7 @@ def unset_all_lang_values
end #of data_proc
def check_key
self.key = attribute_field.key
self.key = self.attribute_field.key
end
def method_missing(*field)

View File

@ -32,8 +32,7 @@ class Site
field :search,:type => Hash
field :site_settings
field :template, type: String
field :site_token
field :store_confirmation, type: Boolean, default: false
field :store_token
field :month_traffic_cache
@ -42,20 +41,6 @@ class Site
mount_uploader :favicon, ImageUploader
mount_uploader :mobile_icon, ImageUploader
def confirm_store(site_token)
if self.site_token.eql?(site_token)
self.store_confirmation = true
self.save
end
end
def generate_site_token
if self.site_token.nil?
self.site_token = SecureRandom.uuid.gsub('-','')
self.save
end
end
def register_site(url,university,department,email,country)
api_key = STORE_CONFIG[:store_settings]["api_key"]
self.generate_site_token

View File

@ -143,7 +143,7 @@
</table>
</div>
<div class="pannel-footer">
<button id="apply_change_btn" onclick="apply_change();" class="btn btn-primary btn-small pull-right">Appy Change</button>
<button id="apply_change_btn" onclick="apply_change();" class="btn btn-primary btn-small pull-right">Apply Change</button>
</div>
</div>
</div>
@ -152,18 +152,7 @@
<div class="panel">
<div class="panel-heading"><i class="icon-shopping-cart"></i><span class="break"></span><%= t(:template_store) %></div>
<div class="pannel-body">
<table id="mt-list" class="table main-list">
<tbody>
<tr id="loading">
<td>
<%= image_tag("preloader.gif", size: "50") %>
<span>Loading template store...</span>
<td>
</tr>
</tbody>
</table>
<%= render :partial => "admin/store/store", :locals => {:section => "templates"} %>
</div>
<div class="pannel-footer">
</div>
@ -176,58 +165,3 @@
<div class="form-actions form-fixed pagination-right">
<%#= link_to content_tag(:i, nil, :class => 'icon-plus icon-white') + t(:upload), upload_package_admin_designs_path, :class => 'btn btn-primary pull-right' %>
</div>
<script type="text/javascript">
// $.ajax({
// url : "<%#= admin_template_store_path %>",
// type : "get",
// datatType : "html"
// }).done(function(data){
// $("#loading").addClass('hide');
// $("#mt-list").html(data);
// bindHandlers();
// }).fail(function(){
// $("#loading").addClass('hide');
// $("#mt-list").html("<tr><td>Error loading template store</td></tr>");
// })
$(document).on('change', '.design_default', function(){
$("#alert_wrap").show();
$(".modal-backdrop").show();
$(this).attr('value');
// console.log($(this).attr('rel') + '/' + $(this).val());
$.getScript($(this).attr('rel'),function(){
$("#alert_wrap").hide();
$(".modal-backdrop").hide();
});
});
var bindHandlers = function(){
// $("a.download-link").on(clickEvent,function(){
// if($(this).attr("disabled") == "disabled")return false;
// var el = $(this);
// el.removeClass("btn-primary").addClass("btn-info").text("Installing").attr('disabled',"disabled");
// $.ajax({
// url : "<%#= admin_template_store_download_theme_path %>",
// data : el.data(),
// dataType : "json",
// type : "post"
// }).done(function(data){
// if(data.success){
// el.removeClass('btn-info').addClass('btn-success').text("Installed");
// $.ajax({
// url: '<%= admin_design_list_path %>',
// type: 'get',
// dataType: 'html'
// })
// .done(function(data) {
// $("#tbody_designs").html(data);
// $(".toggle-check").togglebox();
// });
// }
// }).fail(function(){
// el.removeClass('btn-info').addClass('btn-danger').text("Error, please try again.").removeAttr('disabled');
// })
// })
}
</script>

View File

@ -180,49 +180,10 @@
<div class="panel">
<div class="panel-heading"><i class="icon-shopping-cart"></i><span class="break"></span><%= t(:module_store) %></div>
<div class="pannel-body">
<% if @extensions.empty? %>
<% if @store_confirmation %>
<%#= render :partial => "admin/site_registration/site_registration" %>
<% else %>
<%#= render :partial => "admin/site_registration/not_confirmed_store" %>
<% end %>
<% else %>
<table id="mt-list" class="table main-list">
<thead>
<tr class="sort-header">
<th class="first"><a href="#">Module Title</a></th>
<th data-hide="all" class="active"><a href="#">Description</a></th>
<th class="span2">Active</th>
</tr>
</thead>
<tbody>
<% @extensions.each do |extension|%>
<tr>
<td class="detail-row">
<div class="module_icon pull-left">
<i class='icons-<%= extension["key"] %> icon-3x'></i>
</div>
<h5 class="mt_title"><span><%=link_to extension["title"], admin_module_store_show_path(:id => extension["_slugs"][0])%></span></h5>
<p class="mt_dev muted"><%=extension["author"]%></p>
</td>
<td>
<%= extension["description"].html_safe%> <%=link_to extension["title"], admin_module_store_show_path(:id => extension["_slugs"][0])%>
</td>
<% @module_installed = File.read("downloaded_extensions.rb").include?(extension["key"])%>
<% if @module_installed.eql?(true)%>
<td class="active">Installed</td>
<% else %>
<td class="active"><%= link_to t(:install), admin_module_store_download_path(:id => extension["_slugs"][0]), :class=>"act btn btn-success" %></td>
<% end %>
</tr>
<% end %>
</tbody>
</table>
<% end %>
</div>
<%= render :partial => "admin/store/store", :locals => {:section => "apps"} %>
</div>
<div class="pannel-footer">
</div>
</div>
</div>
</div>
<div class="modal-backdrop"></div>

View File

@ -0,0 +1,36 @@
<%= javascript_include_tag "admin/store_manager" %>
<%= javascript_include_tag "validator" %>
<style type="text/css">
.loading-store{
width: 320px;
margin: 150px auto 0;
text-align: center;
}
.loading-status{
font-weight: bold;
}
.form-area{
width: 500px;
margin: 0 auto;
}
.controls span{
display: inline-block;
padding: 5px 0;
font-size: 14px;
height: 20px;
line-height: 20px;
}
</style>
<div id="store-area">
<div class="loading-store">
<%= image_tag("preloader.gif", size: "50") %>
<p class="loading-status"></p>
<p> Please wait ... </p>
</div>
<div class="form-area">
</div>
</div>
<script type="text/javascript">
new StoreManager("<%= section %>");
</script>

View File

@ -0,0 +1 @@
This is app store.

View File

@ -0,0 +1,28 @@
<h4 class="text-center">Store Registration Form</h4>
<hr />
<form id="store_registration_form" action="/admin/store/register_site" method="post" class="form-horizontal">
<div class="control-group">
<label class="control-label">Site Domain : </label>
<div class="controls">
<span><%= request.host_with_port %></span>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail">Admin Email : </label>
<div class="controls">
<input type="text" id="inputEmail" placeholder="Email" name="admin_email" data-fv-validation="required;email;" data-fv-messages="Cannot be empty.;Not valid email.;">
</div>
</div>
<div class="control-group">
<label class="control-label">Site Token : </label>
<div class="controls">
<span><%= current_site.uid %></span>
</div>
</div>
<hr />
<div class="control-group">
<div class="controls">
<input type="submit" class="btn" value="Register" />
</div>
</div>
</form>

View File

@ -0,0 +1 @@
This is template store.

View File

@ -1,2 +1,2 @@
<p>Thank you for registering your site with Orbit! Please click on the following link and confirm. This is to make sure we could provide you with a spam free experience. Thanks a lot.</p>
<p>Thank you for registering! Please click on the following link and confirm. This is to make sure we could provide you with a spam free experience. Thanks a lot.</p>
<a href="<%= @data['url'] %>" > Please click to confirm </a>

View File

@ -26,6 +26,8 @@ Orbit::Application.routes.draw do
get "/module/:name" => "home#index"
get "/module/:name/show" => "home#show"
post "/store/confirmation" => "store_api#confirmation"
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
@ -216,6 +218,16 @@ Orbit::Application.routes.draw do
get 'module_store/toggle_module' => 'module_store#toggle_module'
get 'module_store/restart_server' => 'module_store#restart_server'
#store routes
get "/store/check_credentials" => "store#check_credentials"
get "/store/register_form" => "store#register_form"
post "/store/register_site" => "store#register_site"
get "/store/check_permissions" => "store#check_permissions"
get "/store/template_store" => "store#template_store"
get "/store/app_store" => "store#app_store"
get "/store/send_email" => "store#send_email"
get "import" => "import#index"
get "import/check_url" => "import#check_url"