From 05852ed09fa89108459b56822d871ab12ec3bda1 Mon Sep 17 00:00:00 2001
From: Harry Bomrah <harry@rulingcom.com>
Date: Tue, 9 Dec 2014 22:00:40 +0800
Subject: [PATCH] category enhancements

---
 app/controllers/pages_controller.rb           | 20 +++++++++++++------
 app/helpers/application_helper.rb             |  4 ++--
 app/helpers/pages_helper.rb                   |  2 +-
 .../admin/categories/_select_form.html.erb    |  1 +
 app/views/admin/categories/index.html.erb     |  1 +
 5 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb
index 2b5bba7..b70eafb 100644
--- a/app/controllers/pages_controller.rb
+++ b/app/controllers/pages_controller.rb
@@ -74,10 +74,11 @@ class PagesController < ApplicationController
              params[:layout_type] = params[:method] || page.layout || "index"
           end
           params[:url] = page.url
-
-          categories = page.categories.collect do |c|
-            if !c.disable
-              return c
+          categories = []
+          page.categories.each do |c|
+            category = Category.find(c) rescue nil
+            if !category.nil? && !category.disable
+              categories << c
             end
           end
           categories = ["all"] if categories.blank?
@@ -289,13 +290,20 @@ class PagesController < ApplicationController
         partials = []
         subparts.each do |subpart|
           if subpart.kind == "module_widget"
+            subpart_categories = []
+            subpart.categories.each do |c|
+              category = Category.find(c) rescue nil
+              if !category.nil? && !category.disable
+                subpart_categories << c
+              end
+            end
+            subpart_categories = ["all"] if subpart_categories.blank?
             OrbitHelper.set_current_widget subpart
             OrbitHelper.set_widget_data_count subpart.data_count
-            OrbitHelper.set_widget_categories subpart.categories
             OrbitHelper.set_widget_module_app subpart.module
             OrbitHelper.set_widget_item_url subpart
             OrbitHelper.set_widget_title subpart.title
-            OrbitHelper.set_widget_categories subpart.categories || []
+            OrbitHelper.set_widget_categories subpart_categories || ["all"]
             OrbitHelper.set_widget_tags subpart.tags || []
             custom_value = subpart.custom_string_field || subpart.custom_array_field rescue nil
             if !custom_value.nil?
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 0d37af4..624d2f5 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -246,7 +246,7 @@ module ApplicationHelper
 				end
 				html.html_safe
 			else
-				return "<div class='well'>It seems we have a problem with the module at this point of time, we will try to fix it as soon as possible. Sorry for the inconvenience!! :( </div>".html_safe
+				return "<div class='well'>No content to show.</div>".html_safe
 			end
 		else
 			f = File.join(Rails.root, 'app', 'templates', "#{@key}", 'modules', params[:target_controller].singularize, "#{params[:target_action]}.html.erb")
@@ -257,7 +257,7 @@ module ApplicationHelper
 				controller = "#{params[:target_controller].capitalize}_controller".classify.constantize.new
 				data = controller.send("#{params[:target_action]}") rescue nil
 				if data.nil?
-					return "<div class='well'>It seems we have a problem with the module at this point of time, we will try to fix it as soon as possible. Sorry for the inconvenience!! :( </div>".html_safe
+					return "<div class='well'> No content to show. </div>".html_safe
 				end
 
 				if data.blank? || data.empty?
diff --git a/app/helpers/pages_helper.rb b/app/helpers/pages_helper.rb
index 54dd677..4d451ae 100644
--- a/app/helpers/pages_helper.rb
+++ b/app/helpers/pages_helper.rb
@@ -87,7 +87,7 @@ module PagesHelper
       end
       html.html_safe
     else
-      return "<div class='well'>It seems we have a problem with the module at this point of time, we will try to fix it as soon as possible. Sorry for the inconvenience!! :( </div>".html_safe
+      return "<div class='well'>No content to show.</div>".html_safe
     end
   end
 
diff --git a/app/views/admin/categories/_select_form.html.erb b/app/views/admin/categories/_select_form.html.erb
index af6914a..b3573d3 100644
--- a/app/views/admin/categories/_select_form.html.erb
+++ b/app/views/admin/categories/_select_form.html.erb
@@ -24,6 +24,7 @@
             </div>
           </div>
         <% end %>
+        <div class="text-error text-center">Category once created, cannot be deleted.</div>
       </div>
       <div class="modal-footer">
         <button type="button" class="btn btn-default pull-left" data-dismiss="modal"><%= t(:close) %></button>
diff --git a/app/views/admin/categories/index.html.erb b/app/views/admin/categories/index.html.erb
index e47f01e..b397fbc 100644
--- a/app/views/admin/categories/index.html.erb
+++ b/app/views/admin/categories/index.html.erb
@@ -25,6 +25,7 @@
                 </div>
               <% end %>
             <% end %>
+            <div class="text-error text-center">Category once created, cannot be deleted.</div>
             <%= label_tag "disable" do %>
               <%= f.check_box :disable %>
               <%= t(:disable) %>