updates for universal table. Added filtering, reordering, sorting and categorizable

This commit is contained in:
harrybomrah committed 2015-11-18 23:51:49 +08:00
1 parent 52c12560ef
commit 316d211b99
15 files changed
+269 -47

No files matched your search

@@ -0,0 +1,7 @@
/*! jQuery UI - v1.11.4 - 2015-11-18
* http://jqueryui.com
* Includes: core.js, widget.js, mouse.js, sortable.js
* Copyright jQuery Foundation and other contributors; Licensed MIT */
(function(e){"function"==typeof define&&define.amd?define(["jquery"],e):e(jQuery)})(function(e){function t(t,s){var n,a,o,r=t.nodeName.toLowerCase();return"area"===r?(n=t.parentNode,a=n.name,t.href&&a&&"map"===n.nodeName.toLowerCase()?(o=e("img[usemap='#"+a+"']")[0],!!o&&i(o)):!1):(/^(input|select|textarea|button|object)$/.test(r)?!t.disabled:"a"===r?t.href||s:s)&&i(t)}function i(t){return e.expr.filters.visible(t)&&!e(t).parents().addBack().filter(function(){return"hidden"===e.css(this,"visibility")}).length}e.ui=e.ui||{},e.extend(e.ui,{version:"1.11.4",keyCode:{BACKSPACE:8,COMMA:188,DELETE:46,DOWN:40,END:35,ENTER:13,ESCAPE:27,HOME:36,LEFT:37,PAGE_DOWN:34,PAGE_UP:33,PERIOD:190,RIGHT:39,SPACE:32,TAB:9,UP:38}}),e.fn.extend({scrollParent:function(t){var i=this.css("position"),s="absolute"===i,n=t?/(auto|scroll|hidden)/:/(auto|scroll)/,a=this.parents().filter(function(){var t=e(this);return s&&"static"===t.css("position")?!1:n.test(t.css("overflow")+t.css("overflow-y")+t.css("overflow-x"))}).eq(0);return"fixed"!==i&&a.length?a:e(this[0].ownerDocument||document)},uniqueId:function(){var e=0;return function(){return this.each(function(){this.id||(this.id="ui-id-"+ ++e)})}}(),removeUniqueId:function(){return this.each(function(){/^ui-id-\d+$/.test(this.id)&&e(this).removeAttr("id")})}}),e.extend(e.expr[":"],{data:e.expr.createPseudo?e.expr.createPseudo(function(t){return function(i){return!!e.data(i,t)}}):function(t,i,s){return!!e.data(t,s[3])},focusable:function(i){return t(i,!isNaN(e.attr(i,"tabindex")))},tabbable:function(i){var s=e.attr(i,"tabindex"),n=isNaN(s);return(n||s>=0)&&t(i,!n)}}),e("<a>").outerWidth(1).jquery||e.each(["Width","Height"],function(t,i){function s(t,i,s,a){return e.each(n,function(){i-=parseFloat(e.css(t,"padding"+this))||0,s&&(i-=parseFloat(e.css(t,"border"+this+"Width"))||0),a&&(i-=parseFloat(e.css(t,"margin"+this))||0)}),i}var n="Width"===i?["Left","Right"]:["Top","Bottom"],a=i.toLowerCase(),o={innerWidth:e.fn.innerWidth,innerHeight:e.fn.innerHeight,outerWidth:e.fn.outerWidth,outerHeight:e.fn.outerHeight};e.fn["inner"+i]=function(t){return void 0===t?o["inner"+i].call(this):this.each(function(){e(this).css(a,s(this,t)+"px")})},e.fn["outer"+i]=function(t,n){return"number"!=typeof t?o["outer"+i].call(this,t):this.each(function(){e(this).css(a,s(this,t,!0,n)+"px")})}}),e.fn.addBack||(e.fn.addBack=function(e){return this.add(null==e?this.prevObject:this.prevObject.filter(e))}),e("<a>").data("a-b","a").removeData("a-b").data("a-b")&&(e.fn.removeData=function(t){return function(i){return arguments.length?t.call(this,e.camelCase(i)):t.call(this)}}(e.fn.removeData)),e.ui.ie=!!/msie [\w.]+/.exec(navigator.userAgent.toLowerCase()),e.fn.extend({focus:function(t){return function(i,s){return"number"==typeof i?this.each(function(){var t=this;setTimeout(function(){e(t).focus(),s&&s.call(t)},i)}):t.apply(this,arguments)}}(e.fn.focus),disableSelection:function(){var e="onselectstart"in document.createElement("div")?"selectstart":"mousedown";return function(){return this.bind(e+".ui-disableSelection",function(e){e.preventDefault()})}}(),enableSelection:function(){return this.unbind(".ui-disableSelection")},zIndex:function(t){if(void 0!==t)return this.css("zIndex",t);if(this.length)for(var i,s,n=e(this[0]);n.length&&n[0]!==document;){if(i=n.css("position"),("absolute"===i||"relative"===i||"fixed"===i)&&(s=parseInt(n.css("zIndex"),10),!isNaN(s)&&0!==s))return s;n=n.parent()}return 0}}),e.ui.plugin={add:function(t,i,s){var n,a=e.ui[t].prototype;for(n in s)a.plugins[n]=a.plugins[n]||[],a.plugins[n].push([i,s[n]])},call:function(e,t,i,s){var n,a=e.plugins[t];if(a&&(s||e.element[0].parentNode&&11!==e.element[0].parentNode.nodeType))for(n=0;a.length>n;n++)e.options[a[n][0]]&&a[n][1].apply(e.element,i)}};var s=0,n=Array.prototype.slice;e.cleanData=function(t){return function(i){var s,n,a;for(a=0;null!=(n=i[a]);a++)try{s=e._data(n,"events"),s&&s.remove&&e(n).triggerHandler("remove")}catch(o){}t(i)}}(e.cleanData),e.widget=function(t,i,s){var n,a,o,r,h={},l=t.split(".")[0];return t=t.split(".")[1],n=l+"-"+t,s||(s=i,i=e.Widget),e.expr[":"][n.toLowerCase()]=function(t){return!!e.data(t,n)},e[l]=e[l]||{},a=e[l][t],o=e[l][t]=function(e,t){return this._createWidget?(arguments.length&&this._createWidget(e,t),void 0):new o(e,t)},e.extend(o,a,{version:s.version,_proto:e.extend({},s),_childConstructors:[]}),r=new i,r.options=e.widget.extend({},r.options),e.each(s,function(t,s){return e.isFunction(s)?(h[t]=function(){var e=function(){return i.prototype[t].apply(this,arguments)},n=function(e){return i.prototype[t].apply(this,e)};return function(){var t,i=this._super,a=this._superApply;return this._super=e,this._superApply=n,t=s.apply(this,arguments),this._super=i,this._superApply=a,t}}(),void 0):(h[t]=s,void 0)}),o.prototype=e.widget.extend(r,{widgetEventPrefix:a?r.widgetEventPrefix||t:t},h,{constructor:o,namespace:l,widgetName:t,widgetFullName:n}),a?(e.each(a._childConstructors,function(t,i){var s=i.prototype;e.widget(s.nLine truncated
},_convertPositionTo:function(t,i){i||(i=this.position);var s="absolute"===t?1:-1,n="absolute"!==this.cssPosition||this.scrollParent[0]!==this.document[0]&&e.contains(this.scrollParent[0],this.offsetParent[0])?this.scrollParent:this.offsetParent,a=/(html|body)/i.test(n[0].tagName);return{top:i.top+this.offset.relative.top*s+this.offset.parent.top*s-("fixed"===this.cssPosition?-this.scrollParent.scrollTop():a?0:n.scrollTop())*s,left:i.left+this.offset.relative.left*s+this.offset.parent.left*s-("fixed"===this.cssPosition?-this.scrollParent.scrollLeft():a?0:n.scrollLeft())*s}},_generatePosition:function(t){var i,s,n=this.options,a=t.pageX,o=t.pageY,r="absolute"!==this.cssPosition||this.scrollParent[0]!==this.document[0]&&e.contains(this.scrollParent[0],this.offsetParent[0])?this.scrollParent:this.offsetParent,h=/(html|body)/i.test(r[0].tagName);return"relative"!==this.cssPosition||this.scrollParent[0]!==this.document[0]&&this.scrollParent[0]!==this.offsetParent[0]||(this.offset.relative=this._getRelativeOffset()),this.originalPosition&&(this.containment&&(t.pageX-this.offset.click.left<this.containment[0]&&(a=this.containment[0]+this.offset.click.left),t.pageY-this.offset.click.top<this.containment[1]&&(o=this.containment[1]+this.offset.click.top),t.pageX-this.offset.click.left>this.containment[2]&&(a=this.containment[2]+this.offset.click.left),t.pageY-this.offset.click.top>this.containment[3]&&(o=this.containment[3]+this.offset.click.top)),n.grid&&(i=this.originalPageY+Math.round((o-this.originalPageY)/n.grid[1])*n.grid[1],o=this.containment?i-this.offset.click.top>=this.containment[1]&&i-this.offset.click.top<=this.containment[3]?i:i-this.offset.click.top>=this.containment[1]?i-n.grid[1]:i+n.grid[1]:i,s=this.originalPageX+Math.round((a-this.originalPageX)/n.grid[0])*n.grid[0],a=this.containment?s-this.offset.click.left>=this.containment[0]&&s-this.offset.click.left<=this.containment[2]?s:s-this.offset.click.left>=this.containment[0]?s-n.grid[0]:s+n.grid[0]:s)),{top:o-this.offset.click.top-this.offset.relative.top-this.offset.parent.top+("fixed"===this.cssPosition?-this.scrollParent.scrollTop():h?0:r.scrollTop()),left:a-this.offset.click.left-this.offset.relative.left-this.offset.parent.left+("fixed"===this.cssPosition?-this.scrollParent.scrollLeft():h?0:r.scrollLeft())}},_rearrange:function(e,t,i,s){i?i[0].appendChild(this.placeholder[0]):t.item[0].parentNode.insertBefore(this.placeholder[0],"down"===this.direction?t.item[0]:t.item[0].nextSibling),this.counter=this.counter?++this.counter:1;var n=this.counter;this._delay(function(){n===this.counter&&this.refreshPositions(!s)})},_clear:function(e,t){function i(e,t,i){return function(s){i._trigger(e,s,t._uiHash(t))}}this.reverting=!1;var s,n=[];if(!this._noFinalSort&&this.currentItem.parent().length&&this.placeholder.before(this.currentItem),this._noFinalSort=null,this.helper[0]===this.currentItem[0]){for(s in this._storedCSS)("auto"===this._storedCSS[s]||"static"===this._storedCSS[s])&&(this._storedCSS[s]="");this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper")}else this.currentItem.show();for(this.fromOutside&&!t&&n.push(function(e){this._trigger("receive",e,this._uiHash(this.fromOutside))}),!this.fromOutside&&this.domPosition.prev===this.currentItem.prev().not(".ui-sortable-helper")[0]&&this.domPosition.parent===this.currentItem.parent()[0]||t||n.push(function(e){this._trigger("update",e,this._uiHash())}),this!==this.currentContainer&&(t||(n.push(function(e){this._trigger("remove",e,this._uiHash())}),n.push(function(e){return function(t){e._trigger("receive",t,this._uiHash(this))}}.call(this,this.currentContainer)),n.push(function(e){return function(t){e._trigger("update",t,this._uiHash(this))}}.call(this,this.currentContainer)))),s=this.containers.length-1;s>=0;s--)t||n.push(i("deactivate",this,this.containers[s])),this.containers[s].containerCache.over&&(n.push(i("out",this,this.containers[s])),this.containers[s].containerCache.over=0);if(this.storedCursor&&(this.document.find("body").css("cursor",this.storedCursor),this.storedStylesheet.remove()),this._storedOpacity&&this.helper.css("opacity",this._storedOpacity),this._storedZIndex&&this.helper.css("zIndex","auto"===this._storedZIndex?"":this._storedZIndex),this.dragging=!1,t||this._trigger("beforeStop",e,this._uiHash()),this.placeholder[0].parentNode.removeChild(this.placeholder[0]),this.cancelHelperRemoval||(this.helper[0]!==this.currentItem[0]&&this.helper.remove(),this.helper=null),!t){for(s=0;n.length>s;s++)n[s].call(this,e);this._trigger("stop",e,this._uiHash())}return this.fromOutside=!1,!this.cancelHelperRemoval},_trigger:function(){e.Widget.prototype._trigger.apply(this,arguments)===!1&&this.cancel()},_uiHash:function(t){var i=t||this;return{helper:i.helper,placeholder:i.placeholder||e([]),position:i.position,originalPosition:i.originalPosition,offset:i.positionAbs,item:i.currentItem,sender:t?t.element:null}}})});
@@ -29,6 +29,16 @@
&:nth-child(even) {
background-color: #e8e8e8;
}
&:nth-child(odd) {
background-color: #fff;
}
.draggable {
cursor: move;
}
.draggable i{
cursor: move;
vertical-align: middle;
}
}
}
.attributes-checkbox {
@@ -49,6 +59,13 @@
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
.select-holder{
margin-left: 20px;
display: inline-block;
span {
margin: 0 5px;
}
}
}
.main-forms fieldset .input-area:after {
@@ -6,7 +6,6 @@ class Admin::UniversalTablesController < OrbitAdminController
.order_by(sort)
.with_categories(filters("category"))
@tables = search_data(@tables,[:title])
end
def show
@@ -15,7 +14,11 @@ class Admin::UniversalTablesController < OrbitAdminController
if !@table.nil?
@columns = @table.table_columns.asc(:order)
@table_fields = @columns.collect{|tc| tc.title}
@entries = @table.table_entries.desc(:created_at).page(params[:page_id]).per(10)
if params[:q].present?
@entries = Kaminari.paginate_array(search_data(@table)).page(params[:page]).per(10)
else
@entries = @table.table_entries.desc(:created_at).page(params[:page]).per(10)
end
end
end
@@ -103,6 +106,24 @@ class Admin::UniversalTablesController < OrbitAdminController
private
def search_data(table)
keywords = params["q"]
keywords = keywords.strip.nil? ? keywords : keywords.strip
regexes = keywords.split(/\s+(?=(?:[^"]*"[^"]*")*[^"]*$)/)
regex = Regexp.union(regexes.map{|word| Regexp.new(".*"+word+".*", "i")})
column = table.table_columns.where(:type.in => ["text","editor"])
columns = []
column.each do |c|
columns = (columns | c.column_entries.any_of(:"text.en" => regex).or(:"text.zh_tw" => regex).or(:"content.en" => regex).or(:"content.zh_tw" => regex))
end
entries = []
columns.each do |column|
entries << column.table_entry
end
entries = entries.sort{|k,v| v["created_at"] <=> k["created_at"]}
end
def table_params
params.require(:u_table).permit!
end
@@ -110,4 +131,10 @@ class Admin::UniversalTablesController < OrbitAdminController
def table_entry_params
params.require(:table_entry).permit!
end
end
end
+99 -17
View File
@@ -1,19 +1,50 @@
class UniversalTablesController < ApplicationController
include Admin::UniversalTablesHelper
def index
params = OrbitHelper.params
table = UTable.where(:category_id => OrbitHelper.page_categories.first).first rescue nil
page = Page.where(:page_id => params[:page_id]).first
if !table.nil?
reset = "hide"
table_heads = table.table_columns.where(:display_in_index => true).asc(:order).collect do |tc|
search = ""
sort = "hide"
sort_class = "sort"
sort = ""
form_field = "<input type='search' class='form-control' name='q' placeholder='Search keyword'>"
query_string = ""
query_string = "&column=#{params["column"]}&q=#{params["q"]}" if params["column"].present?
query_string = query_string + "&page_no=#{params["page_no"]}" if params["page_no"].present?
sort_url = "/#{I18n.locale.to_s}#{page.url}?sortcolumn=#{tc.key}&sort=asc#{query_string}"
title_class = ""
case tc.type
when "date","period","image"
when "date"
search = "hide"
when "period","image"
sort_class = "sort hide"
search = "hide"
sort_url = "#"
sort = "hide"
when "editor"
sort_url = "#"
sort = "hide"
sort_class = "sort hide"
when "text"
if tc.make_categorizable
select_values = tc.column_entries.distinct(:text).uniq
form_field = "<select class='form-control' name='q'>"
select_values.each do |sv|
form_field = form_field + "<option value='#{sv[I18n.locale.to_s]}'>#{sv[I18n.locale.to_s]}</option>"
end
form_field = form_field + "</select>"
end
end
title_class = title_class + "no-sort" if sort == "hide"
if params["sortcolumn"] == tc.key
sort_class = params["sort"] == "asc" ? "sort-desc" : "sort-asc"
sort_url = "/#{I18n.locale.to_s}#{page.url}?sortcolumn=#{tc.key}&sort=#{params["sort"] == "asc" ? "desc" : "asc"}#{query_string}"
end
title_class = title_class + "no-sort" if sort == "sort"
title_class = title_class + " no-search" if search == "hide"
{
@@ -21,31 +52,79 @@ class UniversalTablesController < ApplicationController
"type" => tc.type,
"key" => tc.key,
"search" => search,
"form-field" => form_field,
"sort" => sort,
"sort-class" => sort_class,
"sort-url" => sort_url,
"title-class" => title_class
}
end
tablecolumns = table.table_columns.where(:display_in_index => true).asc(:order)
rows = []
if params["column"].present?
reset = ""
keywords = params["q"]
keywords = keywords.strip.nil? ? keywords : keywords.strip
regexes = keywords.split(/\s+(?=(?:[^"]*"[^"]*")*[^"]*$)/)
regex = Regexp.union(regexes.map{|word| Regexp.new(".*"+word+".*", "i")})
column = table.table_columns.where(:key => params["column"]).first
columns = column.column_entries.any_of(:"text.en" => regex).or(:"text.zh_tw" => regex).or(:"content.en" => regex).or(:"content.zh_tw" => regex)
if params["sort"].present?
column_to_sort = table.table_columns.where(:key => params["sortcolumn"]).first
case column_to_sort.type
when "text"
field_name = :text
when "editor"
field_name = :content
when "date"
field_name = :date
end
if params["column"] == params["sortcolumn"]
columns = column.column_entries.any_of(:"text.en" => regex).or(:"text.zh_tw" => regex).or(:"content.en" => regex).or(:"content.zh_tw" => regex).order_by(field_name => params["sort"])
else
temp = column.column_entries.any_of(:"text.en" => regex).or(:"text.zh_tw" => regex).or(:"content.en" => regex).or(:"content.zh_tw" => regex)
columns = []
temp.each do |c|
columns << c.table_entry.column_entries.where(:table_column_id => column_to_sort.id).first
end
sorted_columns = column_to_sort.column_entries.order_by(field_name => params["sort"]).to_a
columns = sorted_columns & columns
end
else
columns = column.column_entries.any_of(:"text.en" => regex).or(:"text.zh_tw" => regex).or(:"content.en" => regex).or(:"content.zh_tw" => regex)
end
entries = []
columns.each do |column|
entries << column.table_entry
end
entries = entries.sort{|k,v| v["created_at"] <=> k["created_at"]}
entries = entries.sort{|k,v| v["created_at"] <=> k["created_at"]} if !params["sort"].present?
entries = Kaminari.paginate_array(entries).page(params["page_no"]).per(OrbitHelper.page_data_count)
else
entries = table.table_entries.desc(:created_at).page(params["page_no"]).per(OrbitHelper.page_data_count)
if params["sort"].present?
reset = ""
column_to_sort = table.table_columns.where(:key => params["sortcolumn"]).first
case column_to_sort.type
when "text"
field_name = :text
when "editor"
field_name = :content
when "date"
field_name = :date
end
columns = column_to_sort.column_entries.order_by(field_name => params["sort"])
entries = []
columns.each do |column|
entries << column.table_entry
end
entries = Kaminari.paginate_array(entries).page(params["page_no"]).per(OrbitHelper.page_data_count)
else
entries = table.table_entries.desc(:created_at).page(params["page_no"]).per(OrbitHelper.page_data_count)
end
end
total_pages = entries.total_pages
entries.each do |te|
cols = []
sort_value = ""
tablecolumns.each do |column|
ce = te.column_entries.where(:table_column_id => column.id).first rescue nil
if !ce.nil?
@@ -56,19 +135,20 @@ class UniversalTablesController < ApplicationController
when "editor"
text = ce.content
when "date"
text = ce.date.strftime("%Y-%m-%d %H:%M")
text = format_date(ce.date, column.date_format)
when "period"
text = (ce.period_from.strftime("%Y-%m-%d") rescue "") + " ~ " + (ce.period_to.strftime("%Y-%m-%d") rescue "")
text = "" if text.starts_with?("~")
text = format_date(ce.period_from, column.date_format) + " ~ " + format_date(ce.period_to, column.date_format)
text = "" if text.starts_with?(" ~")
when "image"
text = "<img src='#{ce.image.thumb.url}' class='image-preview' />"
end
if column.is_link_to_show
text = "<a href='#{OrbitHelper.url_to_show("-" + te.uid)}'>#{text}</a>"
end
cols << {
"text" => text
}
cols << {"text" => text}
else
cols << {"text" => ""}
end
end
rows << {
@@ -79,9 +159,10 @@ class UniversalTablesController < ApplicationController
{
"head-columns" => table_heads,
"rows" => rows,
"total_pages" => entries.total_pages,
"total_pages" => total_pages,
"extras" => {
"table-name" => table.title,
"reset" => reset,
"url" => "/#{I18n.locale.to_s}#{page.url}"
}
}
@@ -101,18 +182,19 @@ class UniversalTablesController < ApplicationController
when "editor"
text = ce.content
when "date"
text = ce.date.strftime("%Y-%m-%d %H:%M")
text = format_date(ce.date, ce.table_column.date_format)
when "period"
text = (ce.period_from.strftime("%Y-%m-%d") rescue "") + " ~ " + (ce.period_to.strftime("%Y-%m-%d") rescue "")
text = "" if text.starts_with?("~")
text = format_date(ce.period_from, ce.table_column.date_format) + " ~ " + format_date(ce.period_from, ce.table_column.date_format)
text = "" if text.starts_with?(" ~")
when "image"
text = "<img src='#{ce.image.thumb.url}' class='image-preview' />"
end
rows << {
"title" => ct.title,
"text" => text,
"order" => ct.order
}
} if text != ""
end
sorted = rows.sort{ |k,v| k["order"] <=> v["order"] }
{
@@ -0,0 +1,31 @@
module Admin::UniversalTablesHelper
def format_date(date, format, for_editing=false)
case format
when "yyyy/MM/dd hh:mm"
f = "%Y/%m/%d %H:%M"
when "yyyy/MM/dd"
f = "%Y/%m/%d"
when "yyyy/MM"
f = "%Y/%m"
when "yyyy"
f = "%Y"
f = "%Y/%m" if for_editing
end
d = date.strftime(f) rescue ""
return d
end
def render_unique_texts(f,column,i)
select_values = column.column_entries.distinct(:text).uniq
select = "<select id='#{column.key}_#{i}'>"
s = {"en" => "", "zh_tw" => ""}
select = select + "<option class='muted' value='#{s.to_json.html_safe}'>---------------Select---------------</option>"
select_values.each do |sv|
select = select + "<option value='#{sv.to_json.html_safe}'>#{sv[I18n.locale]}</option>"
end
select = select + "</select>"
"<div class='select-holder'> <span>Or</span> " + select + "</div>"
end
end
@@ -1,4 +0,0 @@
module UniversalTable
module ApplicationHelper
end
end
+2
View File
@@ -6,8 +6,10 @@ class TableColumn
field :title, localize: true
field :display_in_index, type: Boolean, default: true
field :type
field :date_format, default: "YYYY/MM//DD"
field :is_link_to_show, type: Boolean, default: false
field :order, type: Integer
field :make_categorizable, type: Boolean, default: false
belongs_to :u_table
+1
View File
@@ -12,4 +12,5 @@ class UTable
accepts_nested_attributes_for :table_columns, :allow_destroy => true
FIELD_TYPES = ["text", "editor", "image", "date", "period"]
DATE_FORMATS = ["yyyy/MM/dd hh:mm", "yyyy/MM/dd","yyyy/MM", "yyyy"]
end
@@ -2,12 +2,12 @@
<div class="attributes">
<% end %>
<div class="attributes-header clearfix">
<a class="btn btn-mini pull-right btn-danger delete" href="#"><i class="icon-trash"></i> Delete</a>
<a class="btn btn-mini pull-right btn-danger delete" href="#"><i class="icon-trash"></i> Delete</a>
<% if defined?(i) %>
<%= f.hidden_field :_destroy, :value => "false", :class => "attribute_field_to_delete" %>
<h4><%= column.title %></h4>
<h4 class="draggable"><i class="icons-list-2"></i> <%= column.title %></h4>
<% else %>
<h4>ColumnXX</h4>
<h4 class="draggable"><i class="icons-list-2"></i> ColumnXX</h4>
<% end %>
</div>
<div class="attributes-body">
@@ -59,21 +59,30 @@
<div class="controls">
<% select_values = UTable::FIELD_TYPES.collect{|ft| [ft.capitalize,ft]} %>
<%= f.select :type, select_values, {}, {class: "type-selector"} %>
<label class="checkbox inline attributes-checkbox <%= !defined?(i) || column.type == "text" ? "" : "hide" %>">
<%= f.check_box :is_link_to_show %> Link to show
<span class="link_to_show <%= !defined?(i) || column.type == "text" ? "" : "hide" %>">
<label class="checkbox inline attributes-checkbox ">
<%= f.check_box :is_link_to_show %> Link to show
</label>
<label class="checkbox inline attributes-checkbox">
<%= f.check_box :make_categorizable %> Categorizable
</label>
</span>
<% select_values = UTable::DATE_FORMATS.collect{|ft| [ft.upcase,ft]} %>
<label class="checkbox date_format inline attributes-checkbox <%= column.type == "date" || column.type == "period" ? "" : "hide" %>">
Date Format <%= f.select :date_format, select_values%>
</label>
</div>
</div>
<% if defined?(i) %>
<% if column.order.nil? %>
<%= f.hidden_field :order, :value => i %>
<%= f.hidden_field :order, :value => i, :class => "order-hidden-field" %>
<% else %>
<%= f.hidden_field :order %>
<%= f.hidden_field :order, :class => "order-hidden-field" %>
<% end %>
<% else %>
<%= f.hidden_field :order, :value=> "XXX" %>
<%= f.hidden_field :order, :value=> "XXX", :class => "order-hidden-field" %>
<% end %>
</div>
<% if !defined?(i) %>
<div class="attributes">
</div>
<% end %>
@@ -3,7 +3,8 @@
<div class="controls">
<div>
<div class="default_picker input-append" style="">
<%= f.text_field :date, :value => (date_field.date.strftime("%Y/%m/%d %H:%M") rescue ""), :placeholder => "YYYY/MM/DD HH:MM", :data => {:format => "yyyy/MM/dd hh:mm"} %>
<% v = !date_field.new_record? ? format_date(date_field.date, column.date_format, true) : "" %>
<%= f.text_field :date, :value => v, :placeholder => column.date_format.upcase, :data => {:format => (column.date_format == "yyyy" ? "yyyy/MM" : column.date_format)} %>
<span class="add-on clearDate"><i class="icons-cross-3"></i></span>
<span class="add-on iconbtn"><i data-date-icon="icons-calendar" data-time-icon="icons-clock" class="icons-calendar"></i></span>
</div>
@@ -4,7 +4,8 @@
<div class="controls">
<div>
<div class="default_picker input-append" style="">
<%= f.text_field :period_from, :value => (period_field.period_from.strftime("%Y/%m/%d") rescue ""), :placeholder => "YYYY/MM/DD", :data => {:format => "yyyy/MM/dd"}, :class => "input-small" %>
<% v = !period_field.new_record? ? format_date(period_field.period_from, column.date_format, true) : "" %>
<%= f.text_field :period_from, :value => v, :placeholder => column.date_format.upcase, :data => {:format => (column.date_format == "yyyy" ? "yyyy/MM" : column.date_format)}, :class => "input-small" %>
<span class="add-on clearDate"><i class="icons-cross-3"></i></span>
<span class="add-on iconbtn"><i data-date-icon="icons-calendar" data-time-icon="icons-clock" class="icons-calendar"></i></span>
</div>
@@ -16,7 +17,8 @@
<div class="controls">
<div>
<div class="default_picker input-append" style="">
<%= f.text_field :period_to,:value => (period_field.period_to.strftime("%Y/%m/%d") rescue ""), :placeholder => "YYYY/MM/DD", :data => {:format => "yyyy/MM/dd"}, :class => "input-small" %>
<% v = !period_field.new_record? ? format_date(period_field.period_to, column.date_format, true) : "" %>
<%= f.text_field :period_to,:value => v, :placeholder => column.date_format.upcase, :data => {:format => (column.date_format == "yyyy" ? "yyyy/MM" : column.date_format)}, :class => "input-small" %>
<span class="add-on clearDate"><i class="icons-cross-3"></i></span>
<span class="add-on iconbtn"><i data-date-icon="icons-calendar" data-time-icon="icons-clock" class="icons-calendar"></i></span>
</div>
@@ -1,6 +1,9 @@
<% content_for :page_specific_css do %>
<%= stylesheet_link_tag "universal_table/universal-table" %>
<% end %>
<% content_for :page_specific_javascript do %>
<%= javascript_include_tag "universal_table/jquery-ui.min" %>
<% end %>
<fieldset class="utable-heading-wrap">
<div class="utable-heading-header">
@@ -68,10 +71,13 @@
if($(this).parent().find(".attribute_field_to_delete").length == 0){
$(this).parent().parent().slideUp(function(){
$(this).remove();
updateOrder();
});
}else{
if(confirm("Are you sure?")){
$(this).parent().parent().slideUp();
$(this).parent().parent().slideUp(function(){
updateOrder();
});
$(this).parent().find(".attribute_field_to_delete").val("true");
}
}
@@ -80,15 +86,35 @@
$(document.body).on("change","select.type-selector",function(){
var el = $(this),
label = el.parent().find("label");
label = el.parent().find("span.link_to_show");
if(el.val() == "text"){
label.removeClass("hide");
}else{
label.addClass("hide");
label.find("input[type=checkbox]").prop("checked",false);
}
label = el.parent().find("label.date_format");
if(el.val() == "date" || el.val() == "period"){
label.removeClass("hide");
}else{
label.addClass("hide");
}
})
$("#attributes-area").sortable({
update: function( event, ui ) {
updateOrder();
}
});
var updateOrder = function(){
var attributes = $("#attributes-area").find(".attributes:visible");
attributes.each(function(i){
$(this).find("input.order-hidden-field").val(i);
})
}
</script>
@@ -8,7 +8,7 @@
<% id = "table_entry_column_entries_#{i}_text_translations_#{locale.to_s}" %>
<div class="tab-pane fade in <%= active %>" id="<%= id %>">
<%= f.fields_for :text_translations do |f| %>
<%= f.text_field locale, :value => text_field.text_translations[locale.to_s] %>
<%= f.text_field locale, :value => text_field.text_translations[locale.to_s], :for => locale.to_s %>
<% end %>
</div>
<% end %>
@@ -21,6 +21,22 @@
<% end %>
</div>
</div>
<% if column.make_categorizable %>
<%= render_unique_texts(f,column,i).html_safe %>
<script type="text/javascript">
$("select#<%= column.key + "_" + i.to_s %>").on("change",function(){
var el = $(this),
locales = <%= @site_in_use_locales.to_json.html_safe %>,
values = JSON.parse(el.val()),
inputs = el.parent().parent().find("input[type=text]");
$.each(locales,function(i,locale){
var input = inputs.filter("input[for=" + locale + "]");
input.val(values[locale]);
})
})
</script>
<% end %>
</div>
<% if !text_field.new_record? %>
<%= f.hidden_field :id %>
+12 -7
View File
@@ -1,11 +1,14 @@
<% content_for :page_specific_css do %>
<%= stylesheet_link_tag "universal_table/universal-table" %>
<% end %>
<form class="form-search">
<input type="text" class="input-large search-query" placeholder="Search keyword">
<form class="form-search" action="<%= admin_universal_table_path(@table) %>" method="get">
<input type="text" name="q" class="input-large search-query" placeholder="Search from text or editor columns">
<button type="submit" class="btn btn-primary">Search</button>
<% if params[:q].present? %>
<a href="<%= admin_universal_table_path(@table) %>" class="btn btn-info">Reset</a>
<% end %>
</form>
<div id="data-table" class="ut-table">
<table class="table main-list">
<thead>
@@ -34,10 +37,10 @@
<% end %>
</div>
<% when "date" %>
<%= ce.date.strftime("%Y-%m-%d %H:%M") rescue "" %>
<%= format_date(ce.date, column.date_format) %>
<% when "period" %>
<% if !ce.period_from.nil? %>
<%= ce.period_from.strftime("%Y-%m-%d") rescue "" %> ~ <%= ce.period_to.strftime("%Y-%m-%d") rescue "" %>
<%= format_date(ce.period_from, column.date_format) %> ~ <%= format_date(ce.period_to, column.date_format) %>
<% end %>
<% end %>
<% if index == 0 %>
@@ -49,6 +52,10 @@
</div>
<% end %>
</td>
<% else %>
<td>
&nbsp;
</td>
<% end %>
<% end %>
</tr>
@@ -65,8 +72,6 @@
</div>
</div>
</script>
+1 -1
View File
@@ -1,6 +1,6 @@
zh_tw:
universal_table:
universal_table: Universal Table
universal_table: 萬用表格
all_tables: All Tables
new_table: Create New Table
table_name: Table Name