location category

This commit is contained in:
Harry Bomrah 2013-06-21 18:24:46 +08:00 committed by chris
parent 8ad015af7f
commit c4e8ed96a9
14 changed files with 135 additions and 5 deletions

View File

@ -0,0 +1,36 @@
class Panel::Location::BackEnd::LocationCategoriesController < OrbitBackendController
def index
@categorylist = LocationCategory.all
@new_category = LocationCategory.new
end
def create
@category = LocationCategory.new(params[:location_category])
@category.save!
respond_to do |h|
h.js
end
end
def edit
@category = LocationCategory.find(params[:id])
render :layout => false
end
def update
@category = LocationCategory.find(params[:id])
@category.update_attributes(params[:location_category])
respond_to do |h|
h.js
end
end
def destroy
@category = LocationCategory.find(params['id'])
@category.delete
render :json=>{"success"=>"true"}.to_json
end
end

View File

@ -14,7 +14,6 @@ class Panel::Location::BackEnd::LocationsController < OrbitBackendController
def new
@location_info = LocationInfo.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @location }

View File

@ -8,4 +8,6 @@ class Location
field :description
field :longitude, type: Float
field :latitude, type: Float
belongs_to :location_category
end

View File

@ -0,0 +1,14 @@
class LocationCategory
include Mongoid::Document
include Mongoid::Timestamps
# include OrbitCoreLib::ObjectAuthable
# ObjectAuthTitlesOptions = %W{new_album}
# APP_NAME = "album"
field :name, localize: true
has_many :location_infos, :autosave => true, :dependent => :destroy
end

View File

@ -9,6 +9,8 @@ class LocationInfo
field :longitude, type: Float
field :latitude, type: Float
belongs_to :location_category
validates :file, presence: true
validates :longitude,
numericality: { less_than_or_equal_to: 180.0, greater_than_or_equal_to: -180.0 },

View File

@ -0,0 +1,13 @@
<div class="tag clear">
<div class="tagitem">
<i class="icon-folder-close"></i>
<% @site_valid_locales.each do |locale| %>
<span class="value" for="<%= locale %>"><%= category.name_translations[locale] rescue nil %> </span>
<% end %>
</div>
<div class="action">
<%= link_to(t(:delete_), panel_location_back_end_location_category_path(category), :method => :delete, :confirm => t("sure?"), :remote => true, :class => "delete") %>
<%= link_to(t(:edit), edit_panel_location_back_end_location_category_path(category), :remote => true, :class => "edit") %>
<%#= show_gallery_category_permission_link(category) %>
</div>
</div>

View File

@ -0,0 +1,2 @@
var dom = $("<%= j render :partial => 'category', :object => @category %>");
$("div#tags").append(dom);

View File

@ -0,0 +1,10 @@
<%= form_for @category, :url => panel_location_back_end_location_category_path(@category), :remote => true do |f| %>
<%= f.fields_for :name_translations do |name| %>
<% @site_valid_locales.each do |locale| %>
<%= label_tag(locale,t("location.new_category")+"["+I18nVariable.from_locale(locale)+"]") %>
<%= name.text_field locale, :value =>(@category.name_translations[locale]) %>
<% end %>
<% end %>
<%= f.submit "Save", :class=> "btn btn-primary temp_save_btn" %>
<a href="#" class="btn btn-primary" id="temp_cancel_btn" onclick="return false;"><%= I18n.t(:cancel) %></a>
<% end %>

View File

@ -0,0 +1,41 @@
<div id="tags" class="clear">
<%= render :partial => 'category', :collection => @categorylist %>
</div>
<div class="form-actions form-fixed form-inline pagination-right">
<%= form_for @new_category, :url => {:action => "create"}, :remote => true do |f| %>
<%= f.fields_for :name_translations do |name| %>
<% @site_valid_locales.each do |locale| %>
<%= label_tag(locale,t("location.new_category")+"["+I18nVariable.from_locale(locale)+"]") %>
<%= name.text_field locale %>
<% end %>
<% end %>
<%= f.submit "Save", :class=> "btn btn-primary" %>
<% end %>
</div>
<script type="text/javascript">
var deleteCategory = function(a){
var parent = a.parent().parent();
parent.hide("slide",function(){parent.remove();})
}
var parent;
var editCategory = function(a,data){
parent = a.parent().parent();
var parenthtml = parent.html();
var tempdom = $("<div class='tagitem'></div>");
tempdom.append(data);
parent.html(tempdom);
tempdom.find("a#temp_cancel_btn").click(function(){
parent.html(parenthtml);
})
}
$(document).ready(function(){
$("#tags div.action a.delete").live('ajax:success', function(){
deleteCategory($(this));
})
$("#tags div.action a.edit").live('ajax:success',function(evt, data, status, xhr){
editCategory($(this),data);
})
})
</script>

View File

@ -0,0 +1,2 @@
var dom = $("<%= j render :partial => 'category', :object => @category %>");
parent.html(dom.html());

View File

@ -9,6 +9,12 @@
<% end %>
</div>
</div>
<div class="control-group">
<label class="control-label" for=""><%= t "category" %></label>
<div class="controls">
<%= f.select(:location_category_id, LocationCategory.all.collect {|p| [ p.name, p.id ] },{:prompt => t("location.select_category")},:class => "validate input-xlarge") %>
</div>
</div>
<div class="control-group">
<label class="control-label" for=""><%= t 'picture' %></label>
<div class="controls">
@ -20,7 +26,7 @@
<label class="control-label" for=""><%= t 'coordinates' %></label>
<div class="controls">
<%= f.text_field :longitude, :class=>"span2", :placeholder => "Longitude" %>
<%= f.text_field :latitude, :class=>"span2", :placeholder => "Langitude" %>
<%= f.text_field :latitude, :class=>"span2", :placeholder => "Lantitude" %>
</div>
</div>
<div class="control-group">

View File

@ -1,3 +1,3 @@
<%= form_for @location_info, :url=> panel_location_back_end_locations_path, :html => { :class=>"form-horizontal"} do |f| %>
<%= form_for @location_info, :url=> panel_location_back_end_locations_path, :html => { :class=>"form-horizontal",:multipart => true} do |f| %>
<%= render :partial => 'form', :locals => {:f => f} %>
<% end %>

View File

@ -1,3 +1,5 @@
en:
location:
location: Location
location: Location
new_category: "New Category"
save: Save
select_category: "Select Category"

View File

@ -6,6 +6,7 @@ Rails.application.routes.draw do
match "locations/get_locations" => "locations#get_locations"
resources :locations
resources :location_categories
end
end
end