Skip to content

Commit

Permalink
Dealing with tabs [TTPLAT-10]
Browse files Browse the repository at this point in the history
Move scripts from details up to show.
  • Loading branch information
smeeks committed Aug 16, 2018
1 parent 1689d3e commit 70fbcf9
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 55 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ TAGS
shadowed_views.log
*.rb~
*.haml~
*.erb~
55 changes: 0 additions & 55 deletions app/views/assets/_detail_scripts.html.erb
Original file line number Diff line number Diff line change
@@ -1,58 +1,3 @@
<script type="text/javascript">

var user_tab_key = 'assets_tab_key';
var tag_url = '<%= tag_inventory_path(@asset) + ".js" %>';

$(document).ready(function() {

// Make the tabs responsive if the viewport gets smaller than the displayed tabs
$('.responsive-tabs').tabdrop({
text: '<i class="fa fa-align-justify"></i>'
});

// Manage the tabs
$('a[data-toggle="tab"]').on('shown.bs.tab', function(e) {
// save the latest tab
var this_tab = $(this).attr('href');
transam.set_ui_key_value(user_tab_key, this_tab);
});

});

// Register a click-handler for the taggable class
$('.taggable').on('click', function() {
var elem = $(this);
var order = elem.data('id');
// Toggle the class
if (elem.hasClass('fa-star-o')) {
// Tag this
elem.removeClass('fa-star-o');
elem.addClass('fa-star');
} else {
// Untag this
elem.removeClass('fa-star');
elem.addClass('fa-star-o');
}
// Send an ajax request to make the change
$.ajax({
url: tag_url,
type: 'get',
success: function(result) {
},
error: function (xhr, ajaxOptions, thrownError) {
}
});
});

$(function() {
// Find the previously selected tab
var selected_tab = $('a[href="'+transam.get_ui_key_value(user_tab_key)+'"]');
// Default to the first tab if no tab is stored or stored tab isn't available to current user
if (selected_tab.length) {
selected_tab.tab('show');
} else {
$('a[data-toggle="tab"]:first').tab('show');
}
});

</script>
67 changes: 67 additions & 0 deletions app/views/assets/_show_scripts.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<script type="text/javascript">

var user_detail_tab_key = 'assets_detail_tab_key';
var user_profile_tab_key = 'assets_profile_tab_key';
var tag_url = '<%= tag_inventory_path(@asset) + ".js" %>';

$(document).ready(function() {
console.log('core_ready');

// Make the tabs responsive if the viewport gets smaller than the displayed tabs
$('.responsive-tabs').tabdrop({
text: '<i class="fa fa-align-justify"></i>'
});

// Manage the tabs
$('a[data-toggle="tab"]').on('shown.bs.tab', function(e) {
console.log('core_handler');
// save the latest tab
var this_tab = $(this).attr('href');
if ($(this).attr('data-panel') == 'profile') {
transam.set_ui_key_value(user_profile_tab_key, this_tab);
} else {
transam.set_ui_key_value(user_detail_tab_key, this_tab);
}
});

});

// Register a click-handler for the taggable class
$('.taggable').on('click', function() {
var elem = $(this);
var order = elem.data('id');
// Toggle the class
if (elem.hasClass('fa-star-o')) {
// Tag this
elem.removeClass('fa-star-o');
elem.addClass('fa-star');
} else {
// Untag this
elem.removeClass('fa-star');
elem.addClass('fa-star-o');
}
// Send an ajax request to make the change
$.ajax({
url: tag_url,
type: 'get',
success: function(result) {
},
error: function (xhr, ajaxOptions, thrownError) {
}
});
});

$(function() {
// Find the previously selected tabs
[user_detail_tab_key, user_profile_tab_key].forEach(function(key) {
var selected_tab = $('a[href="'+transam.get_ui_key_value(key)+'"]');
// Default to first tab if no tab is stored or stored tab isn't available to current user
if (selected_tab.length) {
selected_tab.tab('show');
} else {
$('a[data-toggle="tab"]:first').tab('show');
}
});
});

</script>
2 changes: 2 additions & 0 deletions app/views/assets/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@
Profile
.panel-body
= render 'profile'

=render 'show_scripts'

0 comments on commit 70fbcf9

Please sign in to comment.