From d465febca7abaad3b4a4fdffb92c0b454240f323 Mon Sep 17 00:00:00 2001 From: chris2tof Date: Thu, 22 Dec 2011 15:43:38 +0800 Subject: [PATCH] merge with november_presentation --- app/assets/stylesheets/feile.css.erb | 0 app/controllers/admin/app_auths_controller.rb | 2 +- app/models/design/design.rb | 34 +++++++- app/views/admin/designs/_design_file.html.erb | 2 +- app/views/admin/designs/edit.html.erb | 2 +- app/views/admin/designs/new.html.erb | 2 +- config/initializers/fix_using_obj_id.rb | 5 ++ lib/tasks/app_auth.rake | 11 +++ spec/spec_helper.rb | 3 +- .../app/views/panel/blog/posts/index.html.erb | 25 ++++++ vendor/plugins/NewBlog/NewBlog.json | 9 ++ .../panel/blog/back_end/posts_controller.rb | 84 +++++++++++++++++++ .../panel/blog/back_end/posts/_form.html.erb | 13 +++ .../panel/blog/back_end/posts/index.html.erb | 32 +++++++ .../blog/back_end/posts/latest_post.html.erb | 5 ++ .../panel/blog/back_end/posts/new.html.erb | 13 +++ .../panel/blog/front_end/posts/show.html.erb | 34 ++++++++ .../app/views/panel/blog/posts/index.html.erb | 32 +++++++ .../panel/blog/posts/latest_post.html.erb | 5 ++ .../app/views/panel/blog/posts/new.html.erb | 13 +++ .../app/views/panel/blog/posts/show.html.erb | 38 +++++++++ .../panel/blog/posts/widget_index.html.erb | 16 ++++ .../blog/posts/widget_latest_post.html.erb | 7 ++ .../panel/blog/widget/posts/index.html.erb | 16 ++++ .../blog/widget/posts/latest_post.html.erb | 7 ++ .../plugins/NewBlog/config/locales/zh_tw.yml | 20 +++++ vendor/plugins/NewBlog/config/routes.rb | 13 +++ 27 files changed, 437 insertions(+), 6 deletions(-) create mode 100644 app/assets/stylesheets/feile.css.erb create mode 100644 config/initializers/fix_using_obj_id.rb create mode 100644 lib/tasks/app_auth.rake create mode 100644 vendor/built_in_modules/blog/app/views/panel/blog/posts/index.html.erb create mode 100755 vendor/plugins/NewBlog/NewBlog.json create mode 100644 vendor/plugins/NewBlog/app/controllers/panel/blog/back_end/posts_controller.rb create mode 100644 vendor/plugins/NewBlog/app/views/panel/blog/back_end/posts/_form.html.erb create mode 100644 vendor/plugins/NewBlog/app/views/panel/blog/back_end/posts/index.html.erb create mode 100644 vendor/plugins/NewBlog/app/views/panel/blog/back_end/posts/latest_post.html.erb create mode 100644 vendor/plugins/NewBlog/app/views/panel/blog/back_end/posts/new.html.erb create mode 100644 vendor/plugins/NewBlog/app/views/panel/blog/front_end/posts/show.html.erb create mode 100644 vendor/plugins/NewBlog/app/views/panel/blog/posts/index.html.erb create mode 100644 vendor/plugins/NewBlog/app/views/panel/blog/posts/latest_post.html.erb create mode 100644 vendor/plugins/NewBlog/app/views/panel/blog/posts/new.html.erb create mode 100644 vendor/plugins/NewBlog/app/views/panel/blog/posts/show.html.erb create mode 100644 vendor/plugins/NewBlog/app/views/panel/blog/posts/widget_index.html.erb create mode 100644 vendor/plugins/NewBlog/app/views/panel/blog/posts/widget_latest_post.html.erb create mode 100644 vendor/plugins/NewBlog/app/views/panel/blog/widget/posts/index.html.erb create mode 100644 vendor/plugins/NewBlog/app/views/panel/blog/widget/posts/latest_post.html.erb create mode 100644 vendor/plugins/NewBlog/config/locales/zh_tw.yml create mode 100644 vendor/plugins/NewBlog/config/routes.rb diff --git a/app/assets/stylesheets/feile.css.erb b/app/assets/stylesheets/feile.css.erb new file mode 100644 index 00000000..e69de29b diff --git a/app/controllers/admin/app_auths_controller.rb b/app/controllers/admin/app_auths_controller.rb index f2c01451..6f3f1c3d 100644 --- a/app/controllers/admin/app_auths_controller.rb +++ b/app/controllers/admin/app_auths_controller.rb @@ -4,7 +4,7 @@ class Admin::AppAuthsController < ApplicationController before_filter :is_admin? def index - @roles = Role.all.entries + @user_roles = UserRole.all.entries apps = Purchase.where(:type =>"App") @app_auth_data = apps.entries.map do |app| app_c = eval(app.app_controller) diff --git a/app/models/design/design.rb b/app/models/design/design.rb index f39a4816..e77f7f0f 100644 --- a/app/models/design/design.rb +++ b/app/models/design/design.rb @@ -24,6 +24,35 @@ class Design after_save :procs_embedded_objects # after_destroy :del_embedded_objects + # validate do + # errors.add('atttribute1', 'error for 1') if files_with_duplicate? + # errors.add('atttribute2', 'error for 1') if files_with_noname? + # end + + def files_with_duplicate? + [self.javascripts, self.images,self.themes].each do |objects_hash| + ary = objects_hash.collect{ |k| k.file_filename} + ary.compact! + # debugger + return true if(ary.count!=ary.uniq.count) + end + false + end + + def files_with_noname? + [self.javascripts, self.images,self.themes].each do |objects_hash| + objects_hash.each{ |k| + return true if(k.file_filename.nil? && !k.to_save?) + } + end + false + end + def new_files=(*attrs) + attrs[0].map do |key,items_ary| #Loop by JSs,Themes,Imgs + self.files=([items_ary, key]) + end + end + def javascripts=(*attrs) self.files = (attrs << 'javascripts') end @@ -45,6 +74,7 @@ class Design files = eval(attrs.last) end attrs[0].each do |a| + if a[:id].blank? && !a[:file].blank? files.build(:file => a[:file], :to_save => true) else @@ -86,12 +116,14 @@ class Design end end end + self.valid? end def process_object(object) if object.to_save if object.file_filename.nil? - new_object = self.send(object._type.downcase.pluralize).build(object) + new_object = self.send(object._type.downcase.pluralize).build(object.attributes) + new_object.file = object.file object.destroy new_object.to_save = false new_object.save diff --git a/app/views/admin/designs/_design_file.html.erb b/app/views/admin/designs/_design_file.html.erb index 205b5350..c2945069 100644 --- a/app/views/admin/designs/_design_file.html.erb +++ b/app/views/admin/designs/_design_file.html.erb @@ -18,7 +18,7 @@ <% end %>

-<%= fields_for "design[" + field_name + "][]", object.send(field_name).build, :index => nil do |f| %> +<%= fields_for "design[new_files][" + field_name + "][]", object.send(field_name).build, :index => nil do |f| %> <%= f.file_field :file, :class => "multi_files" %>

<% end %> \ No newline at end of file diff --git a/app/views/admin/designs/edit.html.erb b/app/views/admin/designs/edit.html.erb index 5e7e705a..16ec7d4c 100644 --- a/app/views/admin/designs/edit.html.erb +++ b/app/views/admin/designs/edit.html.erb @@ -1,6 +1,6 @@

<%= t('admin.editing_design') %>

-<%= form_for @design, :url => admin_design_path(@design) do |f| %> +<%= form_for @design, :url => admin_design_path(@design),:html => {:multipart => true} do |f| %> <%= f.error_messages %> <%= render :partial => "form", :locals => { :f => f } %>

diff --git a/app/views/admin/designs/new.html.erb b/app/views/admin/designs/new.html.erb index ded2237a..10316f40 100644 --- a/app/views/admin/designs/new.html.erb +++ b/app/views/admin/designs/new.html.erb @@ -1,6 +1,6 @@

<%= t('admin.new_design') %>

-<%= form_for :design, :url => admin_designs_path do |f| %> +<%= form_for :design, :url => admin_designs_path,:html => {:multipart => true} do |f| %> <%= f.error_messages %> <%= render :partial => "form", :locals => { :f => f } %> diff --git a/config/initializers/fix_using_obj_id.rb b/config/initializers/fix_using_obj_id.rb new file mode 100644 index 00000000..a215cb86 --- /dev/null +++ b/config/initializers/fix_using_obj_id.rb @@ -0,0 +1,5 @@ +Module.instance_eval do + def using_object_ids? + false + end +end \ No newline at end of file diff --git a/lib/tasks/app_auth.rake b/lib/tasks/app_auth.rake new file mode 100644 index 00000000..2cf5066e --- /dev/null +++ b/lib/tasks/app_auth.rake @@ -0,0 +1,11 @@ +# encoding: utf-8 + +namespace :app_auth do + + task :build => :environment do + + + + end + +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 77a57396..2529da0f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -5,6 +5,7 @@ Spork.prefork do # Loading more in this block will cause your tests to run faster. However, # if you change any configuration or code from libraries loaded here, you'll # need to restart spork for it take effect. + # This file is copied to spec/ when you run 'rails generate rspec:install' ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) @@ -54,4 +55,4 @@ end # - Any code that is left outside of the blocks will be ran during preforking # and during each_run! # - These instructions should self-destruct in 10 seconds. If they don't, -# feel free to delete them. +# feel free to delete them. \ No newline at end of file diff --git a/vendor/built_in_modules/blog/app/views/panel/blog/posts/index.html.erb b/vendor/built_in_modules/blog/app/views/panel/blog/posts/index.html.erb new file mode 100644 index 00000000..2bb91518 --- /dev/null +++ b/vendor/built_in_modules/blog/app/views/panel/blog/posts/index.html.erb @@ -0,0 +1,25 @@ +

<%= t('blog.list_post') %>

+ + + + + + + + + + +<% @posts.each do |post| %> + + + + + + + +<% end %> +
<%= t('blog.title') %><%= t('blog.body') %>
<%= post.title %><%= post.body %><%= link_to t('blog.show'), panel_blog_post_path(post) %><%= link_to t('blog.edit'), edit_panel_blog_post_path(post) %><%= link_to t('blog.delete'), panel_blog_post_path(post), :confirm => t('blog.sure?'), :method => :delete %>
+ +
+ +<%= link_to t('blog.new_post'), new_panel_blog_back_end_post_path %> \ No newline at end of file diff --git a/vendor/plugins/NewBlog/NewBlog.json b/vendor/plugins/NewBlog/NewBlog.json new file mode 100755 index 00000000..1c0faa55 --- /dev/null +++ b/vendor/plugins/NewBlog/NewBlog.json @@ -0,0 +1,9 @@ +{ + "title": "NewBlog", + "version": "0.1", + "organization": "Rulingcom", + "author": "RD dep", + "intro": "A simple blog……", + "update_info": "Some info", + "create_date": "11-11-2011" +} \ No newline at end of file diff --git a/vendor/plugins/NewBlog/app/controllers/panel/blog/back_end/posts_controller.rb b/vendor/plugins/NewBlog/app/controllers/panel/blog/back_end/posts_controller.rb new file mode 100644 index 00000000..f853d54c --- /dev/null +++ b/vendor/plugins/NewBlog/app/controllers/panel/blog/back_end/posts_controller.rb @@ -0,0 +1,84 @@ +class Panel::Blog::BackEnd::PostsController < ApplicationController + + layout 'admin' + + def index + @posts = Post.all + + respond_to do |format| + format.html # index.html.erb + format.xml { render :xml => @posts } + end + end + + # GET /posts/1 + # GET /posts/1.xml + def show + @post = Post.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.xml { render :xml => @post } + end + end + + # GET /posts/new + # GET /posts/new.xml + def new + @post = Post.new + + respond_to do |format| + format.html # new.html.erb + format.xml { render :xml => @post } + end + end + + # GET /posts/1/edit + def edit + @post = Post.find(params[:id]) + end + + # POST /posts + # POST /posts.xml + def create + @post = Post.new(params[:post]) + + respond_to do |format| + if @post.save + format.html { redirect_to(panel_blog_post_url(@post), :notice => t('blog.create_post_success')) } + format.xml { render :xml => @post, :status => :created, :location => @post } + else + format.html { render :action => "new" } + format.xml { render :xml => @post.errors, :status => :unprocessable_entity } + end + end + end + + # PUT /posts/1 + # PUT /posts/1.xml + def update + @post = Post.find(params[:id]) + + respond_to do |format| + if @post.update_attributes(params[:post]) + format.html { redirect_to(panel_blog_post_url(@post), :notice => t('blog.update_post_success')) } + format.xml { head :ok } + else + format.html { render :action => "edit" } + format.xml { render :xml => @post.errors, :status => :unprocessable_entity } + end + end + end + + # DELETE /posts/1 + # DELETE /posts/1.xml + def destroy + @post = Post.find(params[:id]) + @post.destroy + + respond_to do |format| + format.html { redirect_to(panel_blog_posts_url) } + format.xml { head :ok } + end + end +end diff --git a/vendor/plugins/NewBlog/app/views/panel/blog/back_end/posts/_form.html.erb b/vendor/plugins/NewBlog/app/views/panel/blog/back_end/posts/_form.html.erb new file mode 100644 index 00000000..2ce8dfe8 --- /dev/null +++ b/vendor/plugins/NewBlog/app/views/panel/blog/back_end/posts/_form.html.erb @@ -0,0 +1,13 @@ +<%= f.error_messages %> + +
+ <%= f.label :title %>
+ <%= f.text_field :title %> +
+
+ <%= f.label :body %>
+ <%= f.text_area :body %> +
+
+ <%= f.submit %> +
diff --git a/vendor/plugins/NewBlog/app/views/panel/blog/back_end/posts/index.html.erb b/vendor/plugins/NewBlog/app/views/panel/blog/back_end/posts/index.html.erb new file mode 100644 index 00000000..25eca5f7 --- /dev/null +++ b/vendor/plugins/NewBlog/app/views/panel/blog/back_end/posts/index.html.erb @@ -0,0 +1,32 @@ +<% content_for :secondary do %> + +<% end -%> + +<%= flash_messages %> + +

<%= t('blog.list_post') %>

+ + + + + + + + + + +<% @posts.each do |post| %> + + + + + + + +<% end %> +
<%= t('blog.title') %><%= t('blog.body') %>
<%= post.title %><%= truncate(post.body,:length=>15) %><%= link_to t('blog.show'), panel_blog_back_end_post_path(post) %><%= link_to t('blog.edit'), edit_panel_blog_back_end_post_path(post) %><%= link_to t('blog.delete'), panel_blog_back_end_post_path(post), :confirm => t('blog.sure?'), :method => :delete %>
+ +
+ diff --git a/vendor/plugins/NewBlog/app/views/panel/blog/back_end/posts/latest_post.html.erb b/vendor/plugins/NewBlog/app/views/panel/blog/back_end/posts/latest_post.html.erb new file mode 100644 index 00000000..9eb6ebbb --- /dev/null +++ b/vendor/plugins/NewBlog/app/views/panel/blog/back_end/posts/latest_post.html.erb @@ -0,0 +1,5 @@ +<%=stylesheet_link_tag "NewBlog/application"%> +

<%=@post.title%>

+

+ <%= @post.body%> +

diff --git a/vendor/plugins/NewBlog/app/views/panel/blog/back_end/posts/new.html.erb b/vendor/plugins/NewBlog/app/views/panel/blog/back_end/posts/new.html.erb new file mode 100644 index 00000000..03508f90 --- /dev/null +++ b/vendor/plugins/NewBlog/app/views/panel/blog/back_end/posts/new.html.erb @@ -0,0 +1,13 @@ +<% content_for :secondary do %> + +<% end -%> + +<%= flash_messages %> +

<%= t('blog.new_post') %>

+<%= form_for @post, :url => panel_blog_back_end_posts_path do |f| %> + <%= render :partial => 'form', :locals => {:f => f} %> +<% end %> + +<%= link_back %> diff --git a/vendor/plugins/NewBlog/app/views/panel/blog/front_end/posts/show.html.erb b/vendor/plugins/NewBlog/app/views/panel/blog/front_end/posts/show.html.erb new file mode 100644 index 00000000..46842f96 --- /dev/null +++ b/vendor/plugins/NewBlog/app/views/panel/blog/front_end/posts/show.html.erb @@ -0,0 +1,34 @@ +

<%= flash_messages %>

+ +

+ <%= t('blog.body') %> + <%=h @post.body %> +

+ +

<%= t('blog.comments') %>

+ +<% @post.comments.each do |c| %> +

+ <%=h c.name %> said:
+ <%= time_ago_in_words(c.created_at) %> ago +

+ +

+ <%=h c.body %> +

+<% end %> + +<%= form_for Comment.new, :url => panel_blog_front_end_comments_path do |f| %> +

+ + <%= f.label :name, "Author" %>
+ <%= f.text_field :name %>
+ <%= f.label :body, "Comment Description" %>
+ <%= f.text_area :body %> + <%= hidden_field_tag :post_id, @post.id %> +

+ +

+ <%= f.submit "Add Comment" %> +

+<% end %> diff --git a/vendor/plugins/NewBlog/app/views/panel/blog/posts/index.html.erb b/vendor/plugins/NewBlog/app/views/panel/blog/posts/index.html.erb new file mode 100644 index 00000000..477429cd --- /dev/null +++ b/vendor/plugins/NewBlog/app/views/panel/blog/posts/index.html.erb @@ -0,0 +1,32 @@ +<% content_for :secondary do %> + +<% end -%> + +<%= flash_messages %> + +

<%= t('blog.list_post') %>

+ + + + + + + + + + +<% @posts.each do |post| %> + + + + + + + +<% end %> +
<%= t('blog.title') %><%= t('blog.body') %>
<%= post.title %><%= truncate(post.body,:length=>15) %><%= link_to t('blog.show'), panel_blog_post_path(post) %><%= link_to t('blog.edit'), edit_panel_blog_post_path(post) %><%= link_to t('blog.delete'), panel_blog_post_path(post), :confirm => t('blog.sure?'), :method => :delete %>
+ +
+ diff --git a/vendor/plugins/NewBlog/app/views/panel/blog/posts/latest_post.html.erb b/vendor/plugins/NewBlog/app/views/panel/blog/posts/latest_post.html.erb new file mode 100644 index 00000000..9eb6ebbb --- /dev/null +++ b/vendor/plugins/NewBlog/app/views/panel/blog/posts/latest_post.html.erb @@ -0,0 +1,5 @@ +<%=stylesheet_link_tag "NewBlog/application"%> +

<%=@post.title%>

+

+ <%= @post.body%> +

diff --git a/vendor/plugins/NewBlog/app/views/panel/blog/posts/new.html.erb b/vendor/plugins/NewBlog/app/views/panel/blog/posts/new.html.erb new file mode 100644 index 00000000..fc4e591d --- /dev/null +++ b/vendor/plugins/NewBlog/app/views/panel/blog/posts/new.html.erb @@ -0,0 +1,13 @@ +<% content_for :secondary do %> + +<% end -%> + +<%= flash_messages %> +

<%= t('blog.new_post') %>

+<%= form_for @post, :url => panel_blog_posts_path do |f| %> + <%= render :partial => 'form', :locals => {:f => f} %> +<% end %> + +<%= link_back %> diff --git a/vendor/plugins/NewBlog/app/views/panel/blog/posts/show.html.erb b/vendor/plugins/NewBlog/app/views/panel/blog/posts/show.html.erb new file mode 100644 index 00000000..7fce5fd1 --- /dev/null +++ b/vendor/plugins/NewBlog/app/views/panel/blog/posts/show.html.erb @@ -0,0 +1,38 @@ +

<%= flash_messages %>

+ +

+ <%= t('blog.body') %> + <%=h @post.body %> +

+ +

<%= t('blog.comments') %>

+ +<% @post.comments.each do |c| %> +

+ <%=h c.name %> said:
+ <%= time_ago_in_words(c.created_at) %> ago +

+ +

+ <%=h c.body %> +

+<% end %> + +<%= form_for Comment.new, :url => panel_blog_comments_path do |f| %> +

+ + <%= f.label :name, "Author" %>
+ <%= f.text_field :name %>
+ <%= f.label :body, "Comment Description" %>
+ <%= f.text_area :body %> + <%= hidden_field_tag :post_id, @post.id %> +

+ +

+ <%= f.submit "Add Comment" %> +

+<% end %> + + +<%= link_to t('blog.edit'), edit_panel_blog_post_path(@post) %> | +<%= link_back %> \ No newline at end of file diff --git a/vendor/plugins/NewBlog/app/views/panel/blog/posts/widget_index.html.erb b/vendor/plugins/NewBlog/app/views/panel/blog/posts/widget_index.html.erb new file mode 100644 index 00000000..cd16cfc7 --- /dev/null +++ b/vendor/plugins/NewBlog/app/views/panel/blog/posts/widget_index.html.erb @@ -0,0 +1,16 @@ +<%=stylesheet_link_tag "NewBlog/application"%> +
+ + + + + + + <% @posts.each do |post| %> + + + + + <% end %> +
<%= t('blog.title') %><%= t('blog.body') %>
<%= link_to post.title,panel_blog_post_path(post) %><%= post.body.truncate(14) %>
+
\ No newline at end of file diff --git a/vendor/plugins/NewBlog/app/views/panel/blog/posts/widget_latest_post.html.erb b/vendor/plugins/NewBlog/app/views/panel/blog/posts/widget_latest_post.html.erb new file mode 100644 index 00000000..2312fc74 --- /dev/null +++ b/vendor/plugins/NewBlog/app/views/panel/blog/posts/widget_latest_post.html.erb @@ -0,0 +1,7 @@ +<%=stylesheet_link_tag "NewBlog/application"%> +
+

<%= @post.title %>

+

+ <%= @post.body %> +

+
\ No newline at end of file diff --git a/vendor/plugins/NewBlog/app/views/panel/blog/widget/posts/index.html.erb b/vendor/plugins/NewBlog/app/views/panel/blog/widget/posts/index.html.erb new file mode 100644 index 00000000..0ea7639f --- /dev/null +++ b/vendor/plugins/NewBlog/app/views/panel/blog/widget/posts/index.html.erb @@ -0,0 +1,16 @@ +<%=stylesheet_link_tag "NewBlog/application"%> +
+ + + + + + + <% @posts.each do |post| %> + + + + + <% end %> +
<%= t('blog.title') %><%= t('blog.body') %>
<%= link_to post.title,panel_blog_front_end_post_path(post) %><%= post.body.truncate(14) %>
+
\ No newline at end of file diff --git a/vendor/plugins/NewBlog/app/views/panel/blog/widget/posts/latest_post.html.erb b/vendor/plugins/NewBlog/app/views/panel/blog/widget/posts/latest_post.html.erb new file mode 100644 index 00000000..2312fc74 --- /dev/null +++ b/vendor/plugins/NewBlog/app/views/panel/blog/widget/posts/latest_post.html.erb @@ -0,0 +1,7 @@ +<%=stylesheet_link_tag "NewBlog/application"%> +
+

<%= @post.title %>

+

+ <%= @post.body %> +

+
\ No newline at end of file diff --git a/vendor/plugins/NewBlog/config/locales/zh_tw.yml b/vendor/plugins/NewBlog/config/locales/zh_tw.yml new file mode 100644 index 00000000..d34b583d --- /dev/null +++ b/vendor/plugins/NewBlog/config/locales/zh_tw.yml @@ -0,0 +1,20 @@ +zh_tw: + + _locale: 中文 + + add: 新增 + back: 回去 + create: 創造 + delete: 刪除 + disable: 禁用 + edit: 編輯 + enable: 啟用 + hide: 隱藏 + homepage: 首頁 + no_: "No" + nothing: 無 + show: 顯示 + sure?: 您肯定嗎? + update: 更新 + yes_: "Yes" + diff --git a/vendor/plugins/NewBlog/config/routes.rb b/vendor/plugins/NewBlog/config/routes.rb new file mode 100644 index 00000000..b619df18 --- /dev/null +++ b/vendor/plugins/NewBlog/config/routes.rb @@ -0,0 +1,13 @@ +Rails.application.routes.draw do + + namespace :panel do + namespace :blog do + root :to => "posts#index" + resources :posts + resources :comments + match "widget_latest_post" => "posts#widget_latest_post" + match "widget_index" => "posts#widget_index" + end + end + +end