Parent: [ba32ac] (diff)

Child: [454b32] (diff)

Download this file

project_tools.js    139 lines (134 with data), 5.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
(function() {
// Provide CSRF protection
var cval = $.cookie('_session_id');
var csrf_input = $('<input name="_session_id" type="hidden" value="'+cval+'">');
// Install popup
var install_popup = $('#lightbox_install_modal');
var install_form = $('#install_form');
var new_ep_name = install_form.find('input.new_ep_name');
var new_mount_point = install_form.find('input.new_mount_point');
var new_mount_label = install_form.find('input.new_mount_label');
var install_tool_label = $('#install_tool_label');
var mount_point_rule_names = $('#install_form .mount-point-rule-names');
install_popup.append(install_form.show());
$('a.install_trig').click(function () {
var datatool = $(this).data('tool');
var relaxed_mount_points = $(this).data('relaxed-mount-points');
install_form.find('.mount-point-name-rules').hide();
if (datatool) {
var tool = defaults[datatool];
install_tool_label.html(tool.default_label);
new_ep_name.val(datatool);
new_mount_point.val(tool.default_mount);
new_mount_label.val(tool.default_label);
if (relaxed_mount_points) {
install_form.find('.mount-point-name-rules.tool-relaxed').show();
}
else {
install_form.find('.mount-point-name-rules.tool').show();
}
} else {
install_tool_label.html("Subproject");
new_ep_name.val('');
new_mount_point.val('');
new_mount_label.val('');
install_form.find('.mount-point-name-rules.subproject').show();
}
});
// Edit popup
var $popup_title = $('#popup_title');
var $popup_contents = $('#popup_contents');
$('a.admin_modal').click(function () {
var link = this;
$popup_title.html('');
$popup_contents.html('Loading...');
$.get(link.href, function (data) {
$popup_title.html($(link).html());
$popup_contents.html(data);
$popup_contents.find('form').append(csrf_input);
});
});
// delete popup
var form_to_delete = null;
var mount_delete_popup = $('#lightbox_mount_delete');
var mount_delete_form = $('#mount_delete_form');
mount_delete_popup.append(mount_delete_form.show());
mount_delete_form.find('.continue_delete').click(function () {
form_to_delete.submit();
form_to_delete = null;
});
mount_delete_form.find('.cancel_delete').click(function () {
form_to_delete = null;
});
$('a.mount_delete').click(function () {
var tool_label = 'this';
var mount_point = $(this).data('mount-point');
if (mount_point) {
tool_label = 'the "' + mount_point + '"';
}
$('div.warning_msg').text('Warning: This will destroy all data in ' + tool_label + ' tool and is irreversable!');
form_to_delete = this.parentNode;
return false;
});
// sorting
$('#sortable').sortable({items: ".fleft:not(.isnt_sorted)"}).bind( "sortupdate", function (e) {
var sortables = $('#sortable .fleft');
var tools = 0;
var subs = 0;
var params = {'_session_id':$.cookie('_session_id')};
for (var i = 0, len = sortables.length; i < len; i++) {
var item = $(sortables[i]);
var mount_point = item.find('input.mount_point');
var shortname = item.find('input.shortname');
if (mount_point.length) {
params['tools-' + tools + '.mount_point'] = mount_point.val();
params['tools-' + tools + '.ordinal'] = i;
tools++;
}
if (shortname.length) {
params['subs-' + subs + '.shortname'] = shortname.val();
params['subs-' + subs + '.ordinal'] = i;
subs++;
}
}
$.ajax({
type: 'POST',
url: 'update_mount_order',
data: params,
success: function(xhr, textStatus, errorThrown) {
$('#messages').notify('Tool order updated, refresh this page to see the updated project navigation.',
{status: 'confirm'});
},
error: function(xhr, textStatus, errorThrown) {
$('#messages').notify('Error saving tool order.',
{status: 'error'});
}
});
});
// fix firefox scroll offset bug
var userAgent = navigator.userAgent.toLowerCase();
if(userAgent.match(/firefox/)) {
$('#sortable').bind( "sortstart", function (event, ui) {
ui.helper.css('margin-top', $(window).scrollTop() );
});
$('#sortable').bind( "sortbeforestop", function (event, ui) {
ui.helper.css('margin-top', 0 );
});
}
})();