Skip to content

Commit 591bfb8

Browse files
committed
Add page/section/link within a given section.
"New" button will correctly add pages/sections/links to the proper parent section based on what item in the sitemap the user has selected. * Remove old style add page/link/section from nav button * Remove 'New' links from 'Sitemap' menu item. * Selecting an item in the site map updates the 'New' links in the global menu.
1 parent 2ceaa5e commit 591bfb8

File tree

5 files changed

+50
-14
lines changed

5 files changed

+50
-14
lines changed

app/assets/javascripts/cms/new-sitemap.js

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,36 @@
44

55
// Code for working with the new sitemap structure.
66

7+
var GlobalMenu = function() {
8+
9+
};
10+
11+
// Setting the 'New Page' path should update the global menu
12+
GlobalMenu.prototype.addPagePath = function(path){
13+
$('#new-content-button').attr('href', path);
14+
$('.add-page-button').attr('href', path);
15+
};
16+
17+
GlobalMenu.prototype.addSectionPath = function(path){
18+
$('.add-link-button').attr('href', path);
19+
};
20+
21+
GlobalMenu.prototype.addLinkPath = function(path){
22+
$('.add-section-button').attr('href', path);
23+
};
24+
25+
var globalMenu = new GlobalMenu();
26+
727
var Sitemap = function() {
828
};
929

30+
// @return [Selector] The currently selected section in the sitemap. If a page or other child is selected, this will be
31+
// that element's parent.
32+
Sitemap.prototype.currentSection = function(){
33+
console.log(this.selectedSection);
34+
return $(this.selectedSection);
35+
};
36+
1037
Sitemap.prototype.selectSection = function(section) {
1138
this.selectedSection = section;
1239
};
@@ -33,7 +60,15 @@ Sitemap.prototype.selectRow = function(row) {
3360

3461
// Highlight the row as selected.
3562
this.selectedRow.parents('li:first').addClass('active');
36-
this.enableButtons();
63+
this.enableMenuButtons();
64+
this.configureNewButton();
65+
};
66+
67+
// Configure the 'New' button for content that is added directly to sections.
68+
Sitemap.prototype.configureNewButton = function(){
69+
globalMenu.addPagePath(this.currentSection().data('add-page-path'));
70+
globalMenu.addLinkPath(this.currentSection().data('add-link-path'));
71+
globalMenu.addSectionPath(this.currentSection().data('add-section-path'));
3772
};
3873

3974
// @return [Selector]
@@ -78,14 +113,15 @@ Sitemap.prototype.enable = function(button_name, path_name) {
78113
}
79114
};
80115

81-
Sitemap.prototype.enableButtons = function() {
116+
Sitemap.prototype.enableMenuButtons = function() {
82117
this.enable('#edit-button', 'edit-path');
83118
this.enable('#properties-button', 'configure-path');
84119
if (this.enable('#delete_button', 'delete-path')) {
85120
$('#delete_button')
86121
.unbind('click')
87122
.click(this._deleteContent);
88123
}
124+
89125
};
90126
var sitemap = new Sitemap();
91127

app/views/cms/section_nodes/_nav_bar.html.erb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
<%= link_to "Edit Page", '#', :id => 'edit-button', :class => "btn btn-primary disabled" %>
66
<%= link_to "Edit Properties", '#', :id => 'properties-button', :class => "btn btn-primary disabled" %>
77
</div>
8-
<div class="btn-group pull-left">
9-
<%= link_to "Add Page", '#', :id => 'add-page-button', :class => "btn btn-primary disabled" %>
10-
<%= link_to "Add Section", '#', :id => 'add-section-button', :class => "btn btn-primary disabled" %>
11-
<%= link_to "Add Link", '#', :id => 'add-link-button', :class => "btn btn-primary disabled" %>
8+
<div class="btn-group">
9+
<%= delete_menu_button %>
1210
</div>
13-
<%= delete_menu_button(nil, class: ['pull-left']) %>
1411
<% end %>

app/views/cms/section_nodes/_section.html.erb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
data = {
55
target: "#section#{section.id}",
66
type: 'section',
7-
:configure_path => edit_section_path(section),
8-
:delete_path => section_path(section)
7+
configure_path: edit_section_path(section),
8+
delete_path: section_path(section),
9+
add_page_path: new_section_page_path(section),
10+
add_link_path: new_section_link_path(section),
11+
add_section_path: new_section_path(section_id: section)
12+
913
}
1014
unless section.root?
1115
data[:toggle] = 'collapse'

app/views/cms/toolbar/_new_pages_menu.html.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
prefix = ""
55
end
66
%>
7-
<%= nav_link_to "#{prefix}Page", cms.new_section_page_path(target_section) %>
8-
<%= nav_link_to "#{prefix}Link", cms.new_section_link_path(target_section) %>
9-
<%= nav_link_to "#{prefix}Section", cms.new_section_path(:section_id => target_section.id) %>
7+
<%= nav_link_to "#{prefix}Page", cms.new_section_page_path(target_section), class: 'add-page-button' %>
8+
<%= nav_link_to "#{prefix}Link", cms.new_section_link_path(target_section), class: 'add-section-button' %>
9+
<%= nav_link_to "#{prefix}Section", cms.new_section_path(:section_id => target_section.id), class: 'add-link-button' %>
1010
<%= divider_tag %>

app/views/layouts/cms/_thin_toolbar.html.erb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
<%= nav_link_to "View Sitemap", cms.sitemap_path %>
2222
<%= nav_link_to "Dashboard", cms.dashboard_path %>
2323
<%= divider_tag %>
24-
<%= render :partial=> 'cms/toolbar/new_pages_menu', :locals => {:prefix => "New "}%>
2524
<%= nav_link_to "Redirects", cms.redirects_path %>
2625
</ul>
2726
</li>
@@ -84,7 +83,7 @@
8483
</ul>
8584
</li>
8685
<li class="btn-group pull-right">
87-
<%= menu_button "New", new_button_path %>
86+
<%= menu_button "New", new_button_path, id: 'new-content-button' %>
8887
<a href="#" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
8988
<b class="caret"></b>
9089
</a>

0 commit comments

Comments
 (0)