knitkit 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. data/GPL-3-LICENSE +674 -0
  2. data/README.md +6 -0
  3. data/Rakefile +30 -0
  4. data/app/assets/javascripts/knitkit/application.js +9 -0
  5. data/app/assets/stylesheets/knitkit/application.css +7 -0
  6. data/app/controllers/knitkit/articles_controller.rb +7 -0
  7. data/app/controllers/knitkit/base_controller.rb +45 -0
  8. data/app/controllers/knitkit/blogs_controller.rb +27 -0
  9. data/app/controllers/knitkit/comments_controller.rb +18 -0
  10. data/app/controllers/knitkit/erp_app/desktop/app_controller.rb +135 -0
  11. data/app/controllers/knitkit/erp_app/desktop/articles_controller.rb +144 -0
  12. data/app/controllers/knitkit/erp_app/desktop/comments_controller.rb +43 -0
  13. data/app/controllers/knitkit/erp_app/desktop/content_controller.rb +27 -0
  14. data/app/controllers/knitkit/erp_app/desktop/file_assets_controller.rb +145 -0
  15. data/app/controllers/knitkit/erp_app/desktop/image_assets_controller.rb +28 -0
  16. data/app/controllers/knitkit/erp_app/desktop/inquiries_controller.rb +68 -0
  17. data/app/controllers/knitkit/erp_app/desktop/position_controller.rb +20 -0
  18. data/app/controllers/knitkit/erp_app/desktop/theme_controller.rb +272 -0
  19. data/app/controllers/knitkit/erp_app/desktop/versions_controller.rb +135 -0
  20. data/app/controllers/knitkit/erp_app/desktop/website_controller.rb +177 -0
  21. data/app/controllers/knitkit/erp_app/desktop/website_nav_controller.rb +143 -0
  22. data/app/controllers/knitkit/erp_app/desktop/website_section_controller.rb +116 -0
  23. data/app/controllers/knitkit/unauthorized_controller.rb +8 -0
  24. data/app/controllers/knitkit/website_sections_controller.rb +17 -0
  25. data/app/helpers/application_helper.rb +132 -0
  26. data/app/models/article.rb +14 -0
  27. data/app/models/blog.rb +21 -0
  28. data/app/models/comment.rb +24 -0
  29. data/app/models/content.rb +158 -0
  30. data/app/models/extensions/user.rb +5 -0
  31. data/app/models/published_element.rb +9 -0
  32. data/app/models/published_website.rb +118 -0
  33. data/app/models/theme.rb +239 -0
  34. data/app/models/website.rb +457 -0
  35. data/app/models/website_host.rb +3 -0
  36. data/app/models/website_inquiry.rb +11 -0
  37. data/app/models/website_inquiry_mailer.rb +12 -0
  38. data/app/models/website_nav.rb +17 -0
  39. data/app/models/website_nav_item.rb +21 -0
  40. data/app/models/website_section.rb +152 -0
  41. data/app/models/website_section_content.rb +4 -0
  42. data/app/views/knitkit/articles/index.html.erb +3 -0
  43. data/app/views/knitkit/articles/show.html.erb +4 -0
  44. data/app/views/knitkit/blogs/_add_comment.html.erb +28 -0
  45. data/app/views/knitkit/blogs/_comment.html.erb +8 -0
  46. data/app/views/knitkit/blogs/index.html.erb +51 -0
  47. data/app/views/knitkit/blogs/index.rss.builder +23 -0
  48. data/app/views/knitkit/blogs/show.html.erb +22 -0
  49. data/app/views/knitkit/unauthorized/index.html.erb +4 -0
  50. data/app/views/knitkit/website_sections/index.html.erb +6 -0
  51. data/app/views/layouts/knitkit/base.html.erb +59 -0
  52. data/app/views/menus/knitkit/_default_menu.html.erb +23 -0
  53. data/app/views/menus/knitkit/_default_section_menu.html.erb +27 -0
  54. data/app/views/menus/knitkit/_default_sub_menu.html.erb +45 -0
  55. data/app/views/menus/knitkit/_default_sub_section_menu.html.erb +49 -0
  56. data/app/views/shared/knitkit/_bread_crumb.html.erb +7 -0
  57. data/app/views/shared/knitkit/_footer.html.erb +3 -0
  58. data/app/views/website_inquiry_mailer/inquiry.erb +3 -0
  59. data/app/widgets/contact_us/base.rb +86 -0
  60. data/app/widgets/contact_us/javascript/contact_us.js +13 -0
  61. data/app/widgets/contact_us/views/_contact_form.html.erb +36 -0
  62. data/app/widgets/contact_us/views/error.html.erb +10 -0
  63. data/app/widgets/contact_us/views/index.html.erb +1 -0
  64. data/app/widgets/contact_us/views/layouts/base.html.erb +7 -0
  65. data/app/widgets/contact_us/views/success.html.erb +4 -0
  66. data/app/widgets/google_map/base.rb +48 -0
  67. data/app/widgets/google_map/javascript/google_map.js +174 -0
  68. data/app/widgets/google_map/views/index.html.erb +41 -0
  69. data/app/widgets/login/base.rb +61 -0
  70. data/app/widgets/login/javascript/login.js +162 -0
  71. data/app/widgets/login/views/index.html.erb +37 -0
  72. data/app/widgets/login/views/layouts/base.html.erb +14 -0
  73. data/app/widgets/login/views/login_header.html.erb +9 -0
  74. data/app/widgets/login/views/reset_password.html.erb +26 -0
  75. data/app/widgets/manage_profile/base.rb +327 -0
  76. data/app/widgets/manage_profile/javascript/manage_profile.js +11 -0
  77. data/app/widgets/manage_profile/views/_contact_information_form.html.erb +180 -0
  78. data/app/widgets/manage_profile/views/_password_form.html.erb +20 -0
  79. data/app/widgets/manage_profile/views/_user_information_form.html.erb +30 -0
  80. data/app/widgets/manage_profile/views/contact_type_in_use.html.erb +4 -0
  81. data/app/widgets/manage_profile/views/default_type_error.html.erb +5 -0
  82. data/app/widgets/manage_profile/views/error.html.erb +3 -0
  83. data/app/widgets/manage_profile/views/index.html.erb +46 -0
  84. data/app/widgets/manage_profile/views/layouts/base.html.erb +1 -0
  85. data/app/widgets/manage_profile/views/password_blank.html.erb +4 -0
  86. data/app/widgets/manage_profile/views/password_invalid.html.erb +4 -0
  87. data/app/widgets/manage_profile/views/password_success.html.erb +3 -0
  88. data/app/widgets/manage_profile/views/success.html.erb +3 -0
  89. data/app/widgets/reset_password/base.rb +42 -0
  90. data/app/widgets/reset_password/javascript/reset_password.js +13 -0
  91. data/app/widgets/reset_password/views/index.html.erb +31 -0
  92. data/app/widgets/reset_password/views/layouts/base.html.erb +1 -0
  93. data/app/widgets/search/base.rb +80 -0
  94. data/app/widgets/search/javascript/search.js +31 -0
  95. data/app/widgets/search/views/_search.html.erb +39 -0
  96. data/app/widgets/search/views/index.html.erb +3 -0
  97. data/app/widgets/search/views/layouts/base.html.erb +24 -0
  98. data/app/widgets/search/views/show.html.erb +48 -0
  99. data/app/widgets/signup/base.rb +72 -0
  100. data/app/widgets/signup/javascript/signup.js +13 -0
  101. data/app/widgets/signup/views/_signup_form.html.erb +36 -0
  102. data/app/widgets/signup/views/error.html.erb +11 -0
  103. data/app/widgets/signup/views/index.html.erb +1 -0
  104. data/app/widgets/signup/views/layouts/base.html.erb +7 -0
  105. data/app/widgets/signup/views/success.html.erb +4 -0
  106. data/config/environment.rb +0 -0
  107. data/config/routes.rb +41 -0
  108. data/db/data_migrations/20110509223702_add_publisher_role.rb +11 -0
  109. data/db/data_migrations/20110816153456_add_knitkit_application.rb +31 -0
  110. data/db/data_migrations/upgrade/20111011203718_create_paths_for_sections.rb +13 -0
  111. data/db/data_migrations/upgrade/20111216192114_add_secured_models_to_menu_items.rb +18 -0
  112. data/db/data_migrations/upgrade/20111216202819_set_contents_iid_to_permalink_where_null.rb +12 -0
  113. data/db/migrate/20110211002317_setup_knitkit.rb +259 -0
  114. data/db/migrate/upgrade/20111014190442_update_contents.rb +25 -0
  115. data/db/migrate/upgrade/20111014201502_add_published_by_to_published_elements.rb +22 -0
  116. data/db/migrate/upgrade/20111017133851_add_iid_to_section.rb +21 -0
  117. data/db/migrate/upgrade/20111027145006_add_in_menu_to_section.rb +19 -0
  118. data/lib/knitkit.rb +12 -0
  119. data/lib/knitkit/engine.rb +26 -0
  120. data/lib/knitkit/extensions.rb +18 -0
  121. data/lib/knitkit/extensions/action_controller/theme_support/acts_as_themed_controller.rb +88 -0
  122. data/lib/knitkit/extensions/active_record/acts_as_commentable.rb +28 -0
  123. data/lib/knitkit/extensions/active_record/acts_as_publishable.rb +38 -0
  124. data/lib/knitkit/extensions/active_record/theme_support/has_many_themes.rb +34 -0
  125. data/lib/knitkit/extensions/compass/widgets/base.rb +53 -0
  126. data/lib/knitkit/extensions/core/array.rb +5 -0
  127. data/lib/knitkit/extensions/railties/action_view.rb +187 -0
  128. data/lib/knitkit/extensions/railties/theme_support/asset_tag_helper.rb +198 -0
  129. data/lib/knitkit/extensions/railties/theme_support/theme_file_resolver.rb +44 -0
  130. data/lib/knitkit/routing_filter/section_router.rb +55 -0
  131. data/lib/knitkit/syntax_validator.rb +32 -0
  132. data/lib/knitkit/version.rb +3 -0
  133. data/lib/tasks/knitkit_tasks.rake +4 -0
  134. data/public/images/knitkit/bullet.png +0 -0
  135. data/public/images/knitkit/content.png +0 -0
  136. data/public/images/knitkit/footer.png +0 -0
  137. data/public/images/knitkit/graphic.png +0 -0
  138. data/public/images/knitkit/greyFadeDown.png +0 -0
  139. data/public/images/knitkit/link.png +0 -0
  140. data/public/images/knitkit/logo.png +0 -0
  141. data/public/images/knitkit/menu.png +0 -0
  142. data/public/images/knitkit/menu_select.png +0 -0
  143. data/public/images/knitkit/search.png +0 -0
  144. data/public/javascripts/datepicker.js +440 -0
  145. data/public/javascripts/erp_app/desktop/applications/knitkit/articles_grid_panel.js +473 -0
  146. data/public/javascripts/erp_app/desktop/applications/knitkit/center_region.js +576 -0
  147. data/public/javascripts/erp_app/desktop/applications/knitkit/comments_grid_panel.js +217 -0
  148. data/public/javascripts/erp_app/desktop/applications/knitkit/east_region.js +26 -0
  149. data/public/javascripts/erp_app/desktop/applications/knitkit/file_assets_panel.js +109 -0
  150. data/public/javascripts/erp_app/desktop/applications/knitkit/image_assets_data_view.js +30 -0
  151. data/public/javascripts/erp_app/desktop/applications/knitkit/image_assets_panel.js +160 -0
  152. data/public/javascripts/erp_app/desktop/applications/knitkit/inquiries_grid_panel.js +46 -0
  153. data/public/javascripts/erp_app/desktop/applications/knitkit/module.js +46 -0
  154. data/public/javascripts/erp_app/desktop/applications/knitkit/publish_window.js +92 -0
  155. data/public/javascripts/erp_app/desktop/applications/knitkit/published_grid_panel.js +220 -0
  156. data/public/javascripts/erp_app/desktop/applications/knitkit/section_articles_grid_panel.js +613 -0
  157. data/public/javascripts/erp_app/desktop/applications/knitkit/themes_tree_panel.js +573 -0
  158. data/public/javascripts/erp_app/desktop/applications/knitkit/versions_grid_panel.js +664 -0
  159. data/public/javascripts/erp_app/desktop/applications/knitkit/west_region.js +2161 -0
  160. data/public/javascripts/erp_app/desktop/applications/knitkit/widgets_panel.js +52 -0
  161. data/public/stylesheets/datepicker.css +121 -0
  162. data/public/stylesheets/erp_app/desktop/applications/knitkit/knitkit.css +114 -0
  163. data/public/stylesheets/extjs/resources/css/knitkit_extjs_4.css +219 -0
  164. data/public/stylesheets/knitkit/style.css +394 -0
  165. metadata +289 -0
@@ -0,0 +1,23 @@
1
+ <div id="menubar">
2
+ <ul id="menu">
3
+ <%
4
+ selected_menu_item = nil
5
+ menu_items.each do |menu_item|
6
+ %>
7
+ <%if menu_item.has_access?(current_user)%>
8
+ <% if menu_item_selected(menu_item)
9
+ selected_menu_item = menu_item
10
+ %>
11
+ <li class="selected">
12
+ <% else %>
13
+ <li>
14
+ <% end %>
15
+ <a href="<%= menu_item.path %>"><span><%= menu_item.title %></span></a>
16
+ </li>
17
+ <% end %>
18
+ <% end %>
19
+ </ul>
20
+ </div>
21
+
22
+
23
+
@@ -0,0 +1,27 @@
1
+ <div id="menubar">
2
+ <%
3
+ selected_section_parent = @website_section.nil? ? nil : @website_section.parent
4
+ %>
5
+ <% unless @website_sections.nil? %>
6
+ <ul id="menu">
7
+ <% @website_sections.each do |section| %>
8
+ <%if section.in_menu %>
9
+ <%if section.has_access?(current_user)%>
10
+ <% if (!@website_section.nil? && section.id == @website_section.id) or (!selected_section_parent.nil? and selected_section_parent.id == section.id) %>
11
+ <li class="selected">
12
+ <%
13
+ selected_section_parent = section
14
+ else
15
+ %>
16
+ <li>
17
+ <%end%>
18
+ <a href="<%= section.path %>"><span><%= section.title %></span></a>
19
+ </li>
20
+ <%end%>
21
+ <% end %>
22
+ <% end %>
23
+ </ul>
24
+ </div>
25
+ <br/>
26
+ <% end %>
27
+
@@ -0,0 +1,45 @@
1
+ <%if !menu_items.nil? && menu_items.count > 0%>
2
+ <div id="side_menu_container">
3
+ <ul id="side_menu">
4
+ <%
5
+ menu_items.each do |menu_item| %>
6
+ <%if menu_item.has_access?(current_user)%>
7
+ <% if menu_item_selected(menu_item) %>
8
+ <li class="selected">
9
+ <%
10
+ selected_menu_item = menu_item
11
+ else
12
+ %>
13
+ <li>
14
+ <% end %>
15
+ <a href="<%= menu_item.path %>"><span><%= menu_item.title %></span></a>
16
+ </li>
17
+
18
+ <% unless selected_menu_item.nil? %>
19
+ <% unless selected_menu_item.positioned_children.nil? %>
20
+ <ul class="side_menu_children">
21
+ <% selected_menu_item.positioned_children.each do |child_menu_item| %>
22
+ <% if child_menu_item.has_access?(current_user)%>
23
+ <% if menu_item_selected(child_menu_item) %>
24
+ <li class="selected">
25
+ <% else %>
26
+ <li>
27
+ <% end %>
28
+ <a href="<%= child_menu_item.path %>"><span><%= child_menu_item.title %></span></a>
29
+ </li>
30
+ <% end %>
31
+ <% end %>
32
+ </ul>
33
+ <%
34
+ end
35
+ selected_menu_item = nil
36
+ end
37
+ %>
38
+ <% end %>
39
+ <% end %>
40
+
41
+ </ul>
42
+ </div>
43
+ <%end%>
44
+
45
+
@@ -0,0 +1,49 @@
1
+
2
+ <% selected_section_parent = @website_section.nil? ? nil : @website_section.parent %>
3
+ <% unless section.nil? %>
4
+ <% section = section.root? ? section : section.root %>
5
+ <% unless section.positioned_children.empty? %>
6
+ <div id="side_menu_container">
7
+ <ul id="side_menu">
8
+ <% section.positioned_children.each do |child_section| %>
9
+ <%if child_section.in_menu %>
10
+ <%if child_section.has_access?(current_user)%>
11
+ <% if (!@website_section.nil? && child_section.id == @website_section.id) or (!selected_section_parent.nil? and selected_section_parent.id == child_section.id) %>
12
+ <li class="selected">
13
+ <%
14
+ selected_section = child_section
15
+ else
16
+ %>
17
+ <li>
18
+ <% end %>
19
+ <a href="<%= child_section.path %>"><span><%= child_section.title %></span></a>
20
+ </li>
21
+ <% end %>
22
+ <% end %>
23
+
24
+ <% if !selected_section.nil? and !selected_section.children.empty? %>
25
+ <ul class="side_menu_children">
26
+ <%
27
+ selected_section.positioned_children.each do |child_section|
28
+ %>
29
+ <% if !@website_section.nil? && child_section.id == @website_section.id %>
30
+ <li class="selected">
31
+ <% else %>
32
+ <li>
33
+ <% end %>
34
+ <a href="<%= child_section.path %>"><span><%= child_section.title %></span></a>
35
+ </li>
36
+ <% end %>
37
+ </ul>
38
+
39
+ <%
40
+ selected_section = nil
41
+ end
42
+ %>
43
+ <% end %>
44
+ </ul>
45
+ </div>
46
+ <% end %>
47
+ <% end %>
48
+
49
+
@@ -0,0 +1,7 @@
1
+ <% links.each do |link| %>
2
+ <% unless link[:title] == links.first[:title]%>
3
+ >
4
+ <%end %>
5
+ <a href="<%= link[:url] %>"><%=link[:title]%></a>
6
+ <% end %>
7
+ <br/>
@@ -0,0 +1,3 @@
1
+ <div id="footer">
2
+ Powered By Compass
3
+ </div>
@@ -0,0 +1,3 @@
1
+ <% @website_inquiry.data.dynamic_attributes_without_prefix.each do |k,v| -%>
2
+ <%=k %>: <%=v %>
3
+ <% end %>
@@ -0,0 +1,86 @@
1
+ module Widgets
2
+ module ContactUs
3
+ class Base < ErpApp::Widgets::Base
4
+ def index
5
+ @use_dynamic_form = params[:use_dynamic_form]
6
+
7
+ render
8
+ end
9
+
10
+ def new
11
+ @is_html_form = params[:is_html_form]
12
+ @validation = {}
13
+ @validation[:first_name] = "First Name Cannot be Blank" if params[:first_name].blank?
14
+ @validation[:last_name] = "Last Name Cannot be Blank" if params[:last_name].blank?
15
+ @validation[:message] = "Message Cannot be Blank" if params[:message].blank?
16
+ @validation[:email] = "Please Enter a Valid Email Address" unless /^.+@.+\..+$/.match(params[:email])
17
+
18
+ if @is_html_form and !@validation.empty?
19
+ return render :view => :error
20
+ end
21
+
22
+ @website = Website.find_by_host(request.host_with_port)
23
+ @website_inquiry = WebsiteInquiry.new
24
+
25
+ params[:created_by] = current_user unless current_user.nil?
26
+ params[:created_with_form_id] = params[:dynamic_form_id] if params[:dynamic_form_id] and params[:is_html_form].blank?
27
+ params[:website_id] = @website.id
28
+ @website_inquiry = DynamicFormModel.save_all_attributes(@website_inquiry, params, ErpApp::Widgets::Base::IGNORED_PARAMS)
29
+
30
+ if @website_inquiry
31
+ if @website.email_inquiries?
32
+ @website_inquiry.send_email
33
+ end
34
+
35
+ if @is_html_form
36
+ render :update => {:id => "#{@uuid}_result", :view => :success}
37
+ else
38
+ render :json => {
39
+ :success => true,
40
+ :response => render_to_string(:template => "success", :layout => false)
41
+ }
42
+ end
43
+ else
44
+ if @is_html_form
45
+ render :update => {:id => "#{@uuid}_result", :view => :error}
46
+ else
47
+ render :json => {
48
+ :success => false,
49
+ :response => render_to_string(:template => "error", :layout => false)
50
+ }
51
+ end
52
+ end
53
+ end
54
+
55
+ #should not be modified
56
+ #modify at your own risk
57
+ def locate
58
+ File.dirname(__FILE__)
59
+ end
60
+
61
+ class << self
62
+ def title
63
+ "Contact Us"
64
+ end
65
+
66
+ def views_location
67
+ File.join(File.dirname(__FILE__),"/views")
68
+ end
69
+
70
+ def widget_name
71
+ File.basename(File.dirname(__FILE__))
72
+ end
73
+
74
+ def base_layout
75
+ begin
76
+ file = File.join(File.dirname(__FILE__),"/views/layouts/base.html.erb")
77
+ IO.read(file)
78
+ rescue
79
+ return nil
80
+ end
81
+ end
82
+ end
83
+
84
+ end#Base
85
+ end#ContactUs
86
+ end#Widgets
@@ -0,0 +1,13 @@
1
+ Compass.ErpApp.Widgets.ContactUs = {
2
+ addContactUs:function(){
3
+ Ext.getCmp('knitkitCenterRegion').addContentToActiveCodeMirror('<%= render_widget :contact_us, :params => {:use_dynamic_form => false} %>');
4
+ }
5
+ }
6
+
7
+ Compass.ErpApp.Widgets.AvailableWidgets.push({
8
+ name:'Contact Us',
9
+ iconUrl:'/images/icons/message/message_48x48.png',
10
+ onClick:Compass.ErpApp.Widgets.ContactUs.addContactUs
11
+ });
12
+
13
+
@@ -0,0 +1,36 @@
1
+ <%if @use_dynamic_form%>
2
+ <div id="<%=widget_result_id %>"></div>
3
+
4
+ <%=raw render_dynamic_form('WebsiteInquiry', :width => 410) %>
5
+
6
+ <div id="dynamic_form_target"></div>
7
+ <%else%>
8
+ <div id="<%=widget_result_id %>"></div>
9
+ <div>
10
+ <%= form_remote_tag build_widget_url(:new) do %>
11
+ <div class="form_settings">
12
+ <p>
13
+ <span>First Name</span>
14
+ <%= text_field_tag :first_name %>
15
+ </p>
16
+ <p>
17
+ <span>Last Name</span>
18
+ <%= text_field_tag :last_name %>
19
+ </p>
20
+ <p>
21
+ <span>Email</span>
22
+ <%= text_field_tag :email %>
23
+ </p>
24
+ <p>
25
+ <span>Message</span>
26
+ <%= text_area_tag :message, nil, :class => 'contact textarea', :rows => 8, :cols => 50 %>
27
+ </p>
28
+ <p style="padding-top: 15px">
29
+ <span>&nbsp;</span>
30
+ <%= submit_tag "Submit", :disable_with => "Please wait...", :class => "submit", :style => 'margin: 0 0 0 0px;' %>
31
+ </p>
32
+ <input type="hidden" name="is_html_form" value="<%=!@use_dynamic_form%>"/>
33
+ </div>
34
+ <% end %>
35
+ </div>
36
+ <%end%>
@@ -0,0 +1,10 @@
1
+ <div class="sexyerror">
2
+ <h1>An Error Occurred</h1>
3
+ <% if @is_html_form %>
4
+ <ul>
5
+ <% @validation.each do |k, v| %>
6
+ <li><%= v %></li>
7
+ <% end %>
8
+ </ul>
9
+ <% end %>
10
+ </div>
@@ -0,0 +1 @@
1
+ <%= render :partial => '/contact_form' %>
@@ -0,0 +1,7 @@
1
+ <h2><%=h @website_section.title %></h2>
2
+
3
+ <% @contents.each do |content| %>
4
+ <%=raw content.body_html %>
5
+ <% end %>
6
+
7
+ <%= render_widget :contact_us %>
@@ -0,0 +1,4 @@
1
+ <div class="sexynotice">
2
+ <h1>Thank you.</h1>
3
+ <p>We've received your inquiry and will get back to you with a response shortly.</p>
4
+ </div>
@@ -0,0 +1,48 @@
1
+
2
+ module Widgets
3
+ module GoogleMap
4
+ class Base < ErpApp::Widgets::Base
5
+ def index
6
+ @uuid = Digest::SHA1.hexdigest(Time.now.to_s + rand(100).to_s)
7
+ @drop_pins = params[:drop_pins]
8
+ @map_width = params[:map_width] || 500
9
+ @map_height = params[:map_height] || 500
10
+ @zoom = params[:zoom] || 18
11
+ @map_type = params[:map_type] || 'SATELLITE'
12
+
13
+ render
14
+ end
15
+
16
+ #should not be modified
17
+ #modify at your own risk
18
+ def locate
19
+ File.dirname(__FILE__)
20
+ end
21
+
22
+ class << self
23
+ def title
24
+ "Google Map"
25
+ end
26
+
27
+ def widget_name
28
+ File.basename(File.dirname(__FILE__))
29
+ end
30
+
31
+ def views_location
32
+ File.join(File.dirname(__FILE__),"/views")
33
+ end
34
+
35
+ def base_layout
36
+ begin
37
+ file = File.join(File.dirname(__FILE__),"/views/layouts/base.html.erb")
38
+ IO.read(file)
39
+ rescue
40
+ return nil
41
+ end
42
+ end
43
+ end
44
+
45
+ end
46
+ end
47
+ end
48
+
@@ -0,0 +1,174 @@
1
+ Compass.ErpApp.Widgets.GoogleMap = {
2
+ addGoogleMap:function(){
3
+
4
+ // Define our data model
5
+ var GoogleMapAddressModel = Ext.define('GoogleMapAddress', {
6
+ extend: 'Ext.data.Model',
7
+ fields: ['title','address']
8
+ });
9
+
10
+ // create the Data Store
11
+ var store = Ext.create('Ext.data.Store', {
12
+ // destroy the store if the grid is destroyed
13
+ autoDestroy: true,
14
+ model: 'GoogleMapAddress',
15
+ proxy: {
16
+ type: 'memory'
17
+ },
18
+ data:[{
19
+ title:'Google Inc.',
20
+ address:'1600 Amphitheatre Parkway Mountain View, CA 94043'
21
+ }]
22
+ });
23
+
24
+
25
+ var rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
26
+ clicksToMoveEditor: 1,
27
+ autoCancel: false,
28
+ listeners:{
29
+ 'edit':function(editor, e){
30
+ editor.record.commit();
31
+ }
32
+ }
33
+ });
34
+
35
+
36
+ var grid = Ext.create('Ext.grid.Panel', {
37
+ autoDestroy:true,
38
+ autoScroll:true,
39
+ region:'center',
40
+ store: store,
41
+ columns: [{
42
+ header: 'Title',
43
+ dataIndex: 'title',
44
+ width:160,
45
+ editor: {
46
+ allowBlank: false
47
+ }
48
+ }, {
49
+ header: 'Address',
50
+ dataIndex: 'address',
51
+ flex: 1,
52
+ editor: {
53
+ allowBlank: false
54
+ }
55
+ }],
56
+ frame:false,
57
+ tbar: [{
58
+ text: 'Add Location',
59
+ iconCls: 'icon-add',
60
+ handler : function() {
61
+ rowEditing.cancelEdit();
62
+ store.insert(0, new GoogleMapAddressModel());
63
+ rowEditing.startEdit(0, 0);
64
+ }
65
+ }, {
66
+ itemId: 'removelocation',
67
+ text: 'Remove Location',
68
+ iconCls: 'icon-delete',
69
+ handler: function() {
70
+ var sm = grid.getSelectionModel();
71
+ rowEditing.cancelEdit();
72
+ store.remove(sm.getSelection());
73
+ if (store.getCount() > 0) {
74
+ sm.select(0);
75
+ }
76
+ },
77
+ disabled: true
78
+ }],
79
+ plugins: [rowEditing],
80
+ listeners: {
81
+ 'selectionchange':function(view, records) {
82
+ grid.down('#removelocation').setDisabled(!records.length);
83
+ }
84
+ }
85
+ });
86
+
87
+ var formPanel = Ext.create("Ext.form.Panel",{
88
+ region:'north',
89
+ frame:false,
90
+ bodyStyle:'padding:5px 5px 0',
91
+ items: [
92
+ {
93
+ xtype: 'combo',
94
+ forceSelection:true,
95
+ store: [
96
+ ['HYBRID','HYBRID'],
97
+ ['ROADMAP','ROADMAP'],
98
+ ['SATELLITE','SATELLITE'],
99
+ ['TERRAIN','TERRAIN'],
100
+ ],
101
+ fieldLabel:'Map Type',
102
+ value:'SATELLITE',
103
+ name: 'mapType',
104
+ allowBlank: false,
105
+ triggerAction: 'all'
106
+ },
107
+ {
108
+ xtype:'numberfield',
109
+ fieldLabel:'Zoom',
110
+ allowBlank:false,
111
+ value:18,
112
+ id:'zoom'
113
+ }
114
+ ]
115
+ });
116
+
117
+
118
+ var addGoogleMapWidgetWindow = Ext.create("Ext.window.Window",{
119
+ layout:'border',
120
+ width:500,
121
+ title:'Add Map Widget',
122
+ height:350,
123
+ plain: true,
124
+ buttonAlign:'center',
125
+ items:[formPanel,grid],
126
+ buttons: [{
127
+ text:'Submit',
128
+ listeners:{
129
+ 'click':function(button){
130
+ var window = button.findParentByType('window');
131
+ var formPanel = window.query('form')[0];
132
+ var basicForm = formPanel.getForm();
133
+ var mapType = basicForm.findField('mapType').getValue();
134
+ var zoom = basicForm.findField('zoom').getValue();
135
+
136
+ var data = {mapType:mapType,zoom:zoom,dropPins:[]};
137
+ grid.store.each(function(record){
138
+ data.dropPins.push({
139
+ title:record.data.title,
140
+ address:record.data.address
141
+ })
142
+ });
143
+
144
+ var tpl = new Ext.XTemplate("<%= render_widget :google_map,\n",
145
+ ':params => {\n',
146
+ ' :zoom => {zoom},',
147
+ " :map_type => '{mapType}',",
148
+ ' :drop_pins => [\n',
149
+ '<tpl for="dropPins">',
150
+ " {:title => '{title}', :address => '{address}'},\n",
151
+ '</tpl>',
152
+ "]}%>");
153
+ var content = tpl.apply(data);
154
+ content = content.replace(",\n]}%>","\n]}%>")
155
+ Ext.getCmp('knitkitCenterRegion').addContentToActiveCodeMirror(content);
156
+ addGoogleMapWidgetWindow.close();
157
+ }
158
+ }
159
+ },{
160
+ text: 'Close',
161
+ handler: function(){
162
+ addGoogleMapWidgetWindow.close();
163
+ }
164
+ }]
165
+ });
166
+ addGoogleMapWidgetWindow.show();
167
+ }
168
+ }
169
+
170
+ Compass.ErpApp.Widgets.AvailableWidgets.push({
171
+ name:'Google Map',
172
+ iconUrl:'/images/icons/map/map_48x48.png',
173
+ onClick:Compass.ErpApp.Widgets.GoogleMap.addGoogleMap
174
+ });