// ******** START DEFAULT INTERNATIONALISATION ********************
// * default values for translation keys in case they are not loaded
// * also acts as a spec for the translation keys that this file requires
if ( typeof tc_translate == "undefined" ) {
tc_translate = { keys:{} };
}
$.each({
// add the default values here
"process.button.log-ascent": "Log ascent(s)",
"process.button.log-ascent.one": "Log ascent",
"process.button.log-ascent.many": "Log {count} ascents",
"process.button.edit-item": "Edit item(s)",
"process.button.edit-item.one": "Edit item",
"process.button.edit-item.many": "Edit {count} items",
"process.button.add-area-above": "Add area above",
"process.button.add-area-below": "Add area below",
"process.button.add-route-above": "Add route above",
"process.button.add-route-below": "Add route below",
"process.button.add-annotation-above": "Add annotation above",
"process.button.add-annotation-below": "Add annotation below",
"process.button.archive-item": "Archive item",
"process.button.unarchive-item": "Unarchive item",
"process.button.move-item": "Move item(s)",
"process.button.move-item.one": "Move item",
"process.button.move-item.many": "Move {count} items",
"process.button.merge-items": "Merge items",
"process.button.your-ascent-history": "Your ascent history",
"process.button.all-ascent-history": "All ascent history",
"process.button.link-to-this-route": "Link to this route",
"x":""}, function(key, val){
if ( typeof tc_translate.keys[key] == "undefined" ) {
tc_translate.keys[key] = val
}
});
// ******** END DEFAULT INTERNATIONALISATION ********************
function addDynamicListViewMenu(event,element) {
if ( element.find('.actionarea').length>0 ) { // bail if already added
return false;
}
var $tr = element;
var anid = $('body').data('nid');
var refParentID = anid;
var cctname = $('body').data('cctname');
var uid = $('body').data('uid');
var canEdit = $('body').data('can-edit');
var canReparent = $('body').data('can-reparent');
var canMerge = $('body').data('can-merge');
var canArchive = $('body').data('can-archive');
var isGym = $('body').data('is-gym');
var ntype = '';
var ret = 'R='+location.pathname;
var archived = $tr.hasClass('archived');
var collapsed = $tr.data('collapsed');
var archivable = $tr.data('archivable');
var lastUnarchived = $tr.data('last-unarchived');
var useParent = $tr.data('use-parent');
if ( useParent ) {
refParentID = useParent;
}
if ($tr.data('nid')){
if ($tr.hasClass('route')) {
ntype = 'route';
} else if ($tr.hasClass('annotation')) {
ntype = 'annotation';
} else {
ntype = 'area';
}
id = $tr.data('nid');
}
var cctid = $tr.data('cctid');
var $selected = $tr.siblings('[data-nid].selected').add( $tr );
selectIDs = $selected.map( function(){ return $(this).data('nid'); }).get();
selectRouteIDs = [];
selectAnnotationIDs = [];
selectAreaIDs = [];
var node_type_present = {};
var parents_selected = {};
$selected.each(function(){
var s_nid = $(this).data('nid');
var s_p = $(this).data('use-parent');
if ( !s_p ) {
s_p = anid;
}
parents_selected[s_p] = 1;
if ( $(this).hasClass('route') ) {
selectRouteIDs.push(s_nid);
node_type_present['route'] = 1;
} else if ( $(this).hasClass('area') ) {
selectAreaIDs.push(s_nid);
node_type_present['area'] = 1;
} else if ( $(this).hasClass('annotation') ) {
selectAnnotationIDs.push(s_nid);
node_type_present['annotation'] = 1;
}
})
var numberParents = Object.keys(parents_selected).length;
var log_ascent_txt = tc_translate.getText('process.button.log-ascent',{count:selectRouteIDs.length},{count:selectRouteIDs.length});
var $refInp = $('input[name="D:NetworkNodeID"]');
var log_ascent_link = '';
if ( $refInp.length ) {
var refNodeID = $refInp.val();
log_ascent_link = '/processmap/logascent_multi/' + selectRouteIDs.join('+') + '?parent='+refNodeID+'&'+ret;
}
var use_node_text = false;
if ( Object.keys(node_type_present).length > 1 ) {
use_node_text = true;
}
var edit_route_txt = tc_translate.getText('process.button.edit-item',{count:selectRouteIDs.length},{count:selectRouteIDs.length});
var edit_area_txt = tc_translate.getText('process.button.edit-item',{count:selectAreaIDs.length},{count:selectAreaIDs.length});
var edit_annotation_txt = tc_translate.getText('process.button.edit-item',{count:selectAnnotationIDs.length},{count:selectAnnotationIDs.length});
var edit_node_txt = tc_translate.getText('process.button.edit-item',{count:selectIDs.length},{count:selectIDs.length});
var edit_txt = edit_node_txt;
if ( !use_node_text ) {
if ( ntype == 'route' ) {
edit_txt = edit_route_txt;
} else if ( ntype == 'annotation' ) {
edit_txt = edit_annotation_txt;
}
}
var edit_link = '/processmap/bulkedit/' + selectIDs.join('+') + '?select=0&'+ret;
var cta_icon = 'pencil';
var cta_txt = edit_txt;
var cta_link = edit_link;
if ( ntype == 'route' ) {
cta_icon = 'ok';
cta_txt = log_ascent_txt;
cta_link = log_ascent_link;
}
// make a drop down menu
var $m = $('
');
var $menu = $m.find('.dropdown-menu');
if ( canEdit ){
$menu.append('' + edit_txt + '');
} else {
$menu.append(''+edit_txt+'');
}
if ( ntype == 'area' ) {
var add_area_above = tc_translate.getText('process.button.add-area-above')
if ( $selected.length==1 && canEdit ) {
$menu.append(''+add_area_above+'');
} else {
$menu.append(''+add_area_above+'');
}
} else {
var add_annotation_above = tc_translate.getText('process.button.add-annotation-above')
var add_route_above = tc_translate.getText('process.button.add-route-above')
if ( $selected.length==1 && canEdit ) {
$menu.append(''+add_route_above+'');
$menu.append(''+add_annotation_above+'');
} else {
$menu.append(''+add_route_above+'');
$menu.append(''+add_annotation_above+'');
}
}
// if it is the last row
if (!$tr.next().length || lastUnarchived){
if ( ntype == 'area' ) {
var add_area_below = tc_translate.getText('process.button.add-area-below')
if ( $selected.length==1 && canEdit ) {
$menu.append(''+add_area_below+'');
} else {
$menu.append(''+add_area_below+'');
}
} else {
var add_annotation_below = tc_translate.getText('process.button.add-annotation-below')
var add_route_below = tc_translate.getText('process.button.add-route-below')
$menu.append('');
if ( $selected.length==1 && canEdit ) {
$menu.append(''+add_route_below+'');
$menu.append(''+add_annotation_below+'');
} else {
$menu.append(''+add_route_below+'');
$menu.append(''+add_annotation_below+'');
}
}
}
if ( isGym ){
if (ntype == 'route'){
$menu.append('');
var archive_route_txt = tc_translate.getText('process.button.archive-item')
var unarchive_route_txt = tc_translate.getText('process.button.unarchive-item')
if ( archived ) {
if (selectRouteIDs.length==1 && canArchive){
$menu.append(''+unarchive_route_txt+'');
} else {
$menu.append(''+unarchive_route_txt+'');
}
} else {
if (selectRouteIDs.length==1 && canArchive){
$menu.append(''+archive_route_txt+'');
} else {
$menu.append(''+archive_route_txt+'');
}
}
}
if (ntype == 'area'){
$menu.append('');
var archive_area_txt = tc_translate.getText('process.button.archive-item')
var unarchive_area_txt = tc_translate.getText('process.button.unarchive-item')
if ( archived ) {
if (selectAreaIDs.length==1 && canArchive){
$menu.append(''+unarchive_area_txt+'');
} else {
$menu.append(''+unarchive_area_txt+'');
}
} else {
if (selectAreaIDs.length==1 && canArchive && archivable ){
$menu.append(''+archive_area_txt+'');
} else {
$menu.append(''+archive_area_txt+'');
}
}
}
}
if (ntype == 'route'){
$menu.append('');
var move_route_txt = tc_translate.getText('process.button.move-item',{count:selectIDs.length},{count:selectIDs.length});
var move_route_link = '';
if (canReparent && selectIDs.length>0 && numberParents<=1){
if ( selectIDs.length==1 ){
var n1 = selectIDs[0];
move_route_link = '/processmap/reparentnode/' + n1;
} else {
move_route_link = '/processmap/reparentnode/'+anid+'?CHECKBOX:AllChildren=1&D:ID='
+ selectIDs.join('&D:ID=')
+ '&D:NetworkNodeID='+anid
+ '&C:HideNavigation=1&State:7126=Next'
+ '&C:ReturnURL='+location.pathname;
}
}
if (move_route_link.length>0){
$menu.append(''+move_route_txt+'');
} else {
$menu.append(''+move_route_txt+'');
}
var merge_routes_txt = tc_translate.getText('process.button.merge-items')
if (selectRouteIDs.length==2 && selectIDs.length==2 && canMerge && numberParents<=1){
var n1 = selectRouteIDs[0];
var n2 = selectRouteIDs[1];
var merge_routes_link = '/processmap/mergenode/' + n1 + '?D:NetworkNodeID:' + n1 + 'P=' + anid + '&D:ChildNode=' + n2 + '&D:Action=ClimbMerge';
$menu.append(''+merge_routes_txt+'');
} else {
$menu.append(''+merge_routes_txt+'');
}
$menu.append('');
if ( log_ascent_link.length > 0 ) {
$menu.append(''+log_ascent_txt+'');
} else {
$menu.append(''+log_ascent_txt+'');
}
var your_history_txt = tc_translate.getText('process.button.your-ascent-history')
var history = $selected.has('.tick > a > span:not(.tick_unticked)').map( function(){ return $(this).data('nid'); }).get();
if (history.length > 0){
var your_history_link = '/ascents/at/'+ history.join('+') +'/by/' + uid;
$menu.append(''+your_history_txt+'');
} else {
$menu.append(''+your_history_txt+'');
}
var all_history_txt = tc_translate.getText('process.button.all-ascent-history')
if (selectRouteIDs.length > 0){
var all_history_link = '/ascents/at/'+ selectRouteIDs.join('+');
$menu.append(''+all_history_txt+'');
} else {
$menu.append(''+all_history_txt+'');
}
$menu.append('');
var link_to_route_txt = tc_translate.getText('process.button.link-to-this-route')
$menu.append(''+link_to_route_txt+'');
}
// not translated until we rework circuits
if ($selected.length==1 && cctid && cctname){
$menu.append('');
$menu.append('Add route to active circuit').find(".cctlink").unbind('click').bind('click',function(){
$tr.data('cctid',0);
$tr.removeAttr("data-cctid");
addRouteToCircuit(uid,cctid,id,function(){});
});
}
$m.prependTo( $tr );
$menu.find(".fn-archive-route").unbind('click').bind('click',function(event){
return archiveRoute(event,$(this));
});
$menu.find(".fn-unarchive-route").unbind('click').bind('click',function(event){
return unarchiveRoute(event,$(this));
});
$menu.find(".fn-archive-area").unbind('click').bind('click',function(event){
return archiveArea(event,$(this));
});
$menu.find(".fn-unarchive-area").unbind('click').bind('click',function(event){
return unarchiveArea(event,$(this));
});
}
function removeDynamicListViewMenu(event,element) {
if ( element.find('.actionarea').length<1 ) { // bail if not there
return false;
}
element.find('.actionarea').remove();
element.removeClass('hover');
}
function updateDynamicListViewMenu(event,element) {
element.siblings('[data-nid].selected').each(function(){
removeDynamicListViewMenu(event,$(this));
// addDynamicListViewMenu(event,$(this));
});
if ( element.hasClass('selected') ) {
addDynamicListViewMenu(event,element);
} else {
removeDynamicListViewMenu(event,element);
}
}
function updateDynamicListViewMenuForTouchscreen(event,element) {
if(('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch) {
updateDynamicListViewMenu(event,element);
}
}
(function(){
// if not logged in then bail
if ( !$('body').data('uid') ){
return;
}
// see https://github.com/Modernizr/Modernizr/blob/master/feature-detects/touchevents.js
if(('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch) {
} else {
// NON touch events
// cycle through all route and annotation rows in the route table
$('.routetable, .node-listview').on({
'mouseenter': function(event){
addDynamicListViewMenu(event,$(this));
},
'mouseleave': function(event){
removeDynamicListViewMenu(event,$(this));
}
}, '.area[data-nid], .route[data-nid], .annotation[data-nid]');
}
$(".node-listview").on("click", ".fn-toggle-grade-convert", function(e){
e.preventDefault();
var link = $(this).closest('.fn-toggle-grade-convert');
var state = link.data('grade-state');
var container = $(this).closest('.node-listview');
if ( state === 'converted' ) {
container.find('.grade-convert-sys').addClass('hide');
container.find('.grade-base-sys').removeClass('hide');
state = link.data('grade-state','unconverted');
} else {
container.find('.grade-convert-sys').removeClass('hide');
container.find('.grade-base-sys').addClass('hide');
state = link.data('grade-state','converted');
}
return false;
});
})();