make an App::Netdisco dist using Module::Install

This commit is contained in:
Oliver Gorwits
2012-12-17 18:31:16 +00:00
parent 6a0aa7864e
commit 05086e8b78
125 changed files with 428 additions and 127 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,99 @@
/**
* @author Kyle Florence <kyle[dot]florence[at]gmail[dot]com>
* @website https://github.com/kflorence/jquery-deserialize/
* @version 1.1.0
*
* Dual licensed under the MIT and GPLv2 licenses.
*/
(function( jQuery ) {
var push = Array.prototype.push,
rcheck = /^(radio|checkbox)$/i,
rselect = /^(option|select-one|select-multiple)$/i,
rvalue = /^(hidden|text|search|tel|url|email|password|datetime|date|month|week|time|datetime-local|number|range|color|submit|image|reset|button|textarea)$/i;
jQuery.fn.extend({
deserialize: function( data, callback ) {
if ( !this.length || !data ) {
return this;
}
var i, length,
elements = this[ 0 ].elements || this.find( ":input" ).get(),
normalized = [];
if ( !elements ) {
return this;
}
if ( jQuery.isArray( data ) ) {
normalized = data;
} else if ( jQuery.isPlainObject( data ) ) {
var key, value;
for ( key in data ) {
jQuery.isArray( value = data[ key ] ) ?
push.apply( normalized, jQuery.map( value, function( v ) {
return { name: key, value: v };
})) : push.call( normalized, { name: key, value: value } );
}
} else if ( typeof data === "string" ) {
var parts;
data = decodeURIComponent( data ).split( "&" );
for ( i = 0, length = data.length; i < length; i++ ) {
parts = data[ i ].split( "=" );
push.call( normalized, { name: parts[ 0 ], value: parts[ 1 ] } );
}
}
if ( !( length = normalized.length ) ) {
return this;
}
var current, element, item, j, len, property, type;
for ( i = 0; i < length; i++ ) {
current = normalized[ i ];
if ( !( element = elements[ current.name ] ) ) {
continue;
}
type = ( len = element.length ) ? element[ 0 ] : element;
type = type.type || type.nodeName;
property = null;
if ( rvalue.test( type ) ) {
property = "value";
} else if ( rcheck.test( type ) ) {
property = "checked";
} else if ( rselect.test( type ) ) {
property = "selected";
}
// Handle element group
if ( len ) {
for ( j = 0; j < len; j++ ) {
item = element [ j ];
if ( item.value == current.value ) {
item[ property ] = true;
}
}
} else {
element[ property ] = current.value;
}
}
if ( jQuery.isFunction( callback ) ) {
callback.call( this );
}
return this;
}
});
})( jQuery );

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,218 @@
// parameterised for the active tab - submits search form and injects
// HTML response into the tab pane, or an error/empty-results message
function do_search (event, tab) {
var form = '#' + tab + '_form';
var target = '#' + tab + '_pane';
// stop form from submitting normally
event.preventDefault();
// page title
var pgtitle = 'Netdisco';
if ($('#nd_device_name').text().length) {
var pgtitle = $('#nd_device_name').text() +' - '+ $('#'+ tab + '_link').text();
}
// each sidebar search form has a hidden copy of the main navbar search
// query. when the tab query takes place, copy the navbar locally, then
// replicate to all other tabs.
if ($('#nq').val()) {
$(form).find("input[name=q]").val( $('#nq').val() );
}
$('form').find("input[name=q]").each( function() {
$(this).val( $(form).find("input[name=q]").val() );
});
// hide or show sidebars depending on previous state,
// and whether the sidebar contains any content (detected by TT)
if (has_sidebar[tab] == 0) {
$('.sidebar, #sidebar_toggle_img_out').hide();
$('.content').css('margin-right', '10px');
}
else {
if (sidebar_hidden) {
$('#sidebar_toggle_img_out').show();
}
else {
$('.content').css('margin-right', '215px');
$('.sidebar').show();
}
}
// get the form params
var query = $(form).serialize();
// update browser search history with the new query.
// however if it's the same tab, this is a *replace* of the query url.
if (window.History && window.History.enabled) {
is_from_history_plugin = 1;
window.History.replaceState(
{name: tab, fields: $(form).serializeArray()},
pgtitle, uri_base + '/' + path + '?' + query
);
is_from_history_plugin = 0;
}
// in case of slow data load, let the user know
$(target).html(
'<div class="span2 alert">Waiting for results...</div>'
);
// submit the query and put results into the tab pane
$(target).load( uri_base + '/ajax/content/' + path + '/' + tab + '?' + query,
function(response, status, xhr) {
if (status !== "success") {
$(target).html(
'<div class="span5 alert alert-error">' +
'Search failed! Please contact your site administrator.</div>'
);
return;
}
if (response === "") {
$(target).html(
'<div class="span2 alert alert-info">No matching records.</div>'
);
}
// delegate to any [device|search] specific JS code
inner_view_processing(tab);
}
);
}
// keep track of which tabs have a sidebar, for when switching tab
var has_sidebar = {};
var sidebar_hidden = 0;
// the history.js plugin is great, but fires statechange at pushState
// so we have these semaphpores to help avoid messing the History.
// set true when faking a user click on a tab
var is_from_state_event = 0;
// set true when the history plugin does pushState - to prevent loop
var is_from_history_plugin = 0;
// on tab change, hide previous tab's search form and show new tab's
// search form. also trigger to load the content for the newly active tab.
function update_content(from, to) {
$('#' + from + '_search').toggleClass('active');
$('#' + to + '_search').toggleClass('active');
var to_form = '#' + to + '_form';
var from_form = '#' + from + '_form';
// page title
var pgtitle = 'Netdisco';
if ($('#nd_device_name').text().length) {
var pgtitle = $('#nd_device_name').text() +' - '+ $('#'+ to + '_link').text();
}
if (window.History && window.History.enabled && is_from_state_event == 0) {
is_from_history_plugin = 1;
window.History.pushState(
{name: to, fields: $(to_form).serializeArray()},
pgtitle, uri_base + '/' + path + '?' + $(to_form).serialize()
);
is_from_history_plugin = 0;
}
$(to_form).trigger("submit");
}
// handler for ajax navigation
if (window.History && window.History.enabled) {
var History = window.History;
History.Adapter.bind(window, "statechange", function() {
if (is_from_history_plugin == 0) {
is_from_state_event = 1;
var State = History.getState();
// History.log(State.data.name, State.title, State.url);
$('#'+ State.data.name + '_form').deserialize(State.data.fields);
$('#'+ State.data.name + '_link').click();
is_from_state_event = 0;
}
});
}
$(document).ready(function() {
// activate typeahead on the main search box, for device names only
$('#nq').typeahead({
source: function (query, process) {
return $.get('/ajax/data/device/typeahead', { query: query }, function (data) {
return process(data);
});
}
,minLength: 3
});
// activate tooltips
$("[rel=tooltip]").tooltip({live: true});
// bind submission to the navbar go icon
$('#navsearchgo').click(function() {
$('#navsearchgo').parents('form').submit();
});
// fix green background on search checkboxes
// https://github.com/twitter/bootstrap/issues/742
syncCheckBox = function() {
$(this).parents('.add-on').toggleClass('active', $(this).is(':checked'));
};
$('.add-on :checkbox').each(syncCheckBox).click(syncCheckBox);
// sidebar toggle - pinning
$('.sidebar_pin').click(function() {
$('.sidebar').toggleClass('sidebar_pinned');
$('.sidebar_pin').toggleClass('sidebar_pin_clicked');
// update tooltip note for current state
if ($('.sidebar_pin').hasClass('sidebar_pin_clicked')) {
$('.sidebar_pin').first().data('tooltip').options.title = 'Unpin Sidebar';
}
else {
$('.sidebar_pin').first().data('tooltip').options.title = 'Pin Sidebar';
}
});
// sidebar toggle - trigger in/out on image click()
$('#sidebar_toggle_img_in').click(function() {
$('.sidebar').toggle(250);
$('#sidebar_toggle_img_out').toggle();
$('.content').css('margin-right', '10px');
sidebar_hidden = 1;
});
$('#sidebar_toggle_img_out').click(function() {
$('#sidebar_toggle_img_out').toggle();
$('.content').css('margin-right', '215px');
$('.sidebar').toggle(250);
if (! $('.sidebar').hasClass('sidebar_pinned')) {
$(window).scrollTop(0);
}
sidebar_hidden = 0;
});
// could not get twitter bootstrap tabs to behave, so implemented this
// but warning! will probably not work for dropdowns in tabs
$('#search_results li').delegate('a', 'click', function(event) {
event.preventDefault();
var from_li = $('.nav-tabs').find('> .active').first();
var to_li = $(this).parent('li')
from_li.toggleClass('active');
to_li.toggleClass('active');
var from_id = from_li.find('a').attr('href');
var to_id = $(this).attr('href');
if (from_id == to_id) {
return;
}
$(from_id).toggleClass('active');
$(to_id).toggleClass('active');
update_content(
from_id.replace(/^#/,"").replace(/_pane$/,""),
to_id.replace(/^#/,"").replace(/_pane$/,"")
);
});
});

View File

@@ -0,0 +1,72 @@
// user clicked or asked for port changes to be submitted via ajax
function port_control (e) {
var td = $(e).closest('td');
$.ajax({
type: 'POST'
,url: uri_base + '/ajax/portcontrol'
,data: {
device: td.attr('data-for-device')
,port: td.attr('data-for-port')
,field: td.attr('data-field')
,action: td.attr('data-action')
,value: td.text().trim()
}
,success: function() {
toastr.info('Submitted change request');
// update all the screen furniture for port up/down control
if ($.trim(td.attr('data-action')) == 'down') {
td.prev('td').html('<span class="label">S</span>');
$(e).toggleClass('icon-hand-down');
$(e).toggleClass('icon-hand-up');
$(e).data('tooltip').options.title = 'Click to Enable';
td.attr('data-action', 'up');
}
else if ($.trim(td.attr('data-action')) == 'up') {
td.prev('td').html('<span class="label"><i class="icon-refresh"></i></span>');
$(e).toggleClass('icon-hand-up');
$(e).toggleClass('icon-hand-down');
$(e).data('tooltip').options.title = 'Click to Disable';
td.attr('data-action', 'down');
}
else if ($.trim(td.attr('data-action')) == 'false') {
$(e).next('span').text('');
$(e).toggleClass('nd_power_on');
$(e).data('tooltip').options.title = 'Click to Enable';
td.attr('data-action', 'true');
}
else if ($.trim(td.attr('data-action')) == 'true') {
$(e).toggleClass('nd_power_on');
$(e).data('tooltip').options.title = 'Click to Disable';
td.attr('data-action', 'false');
}
}
,error: function() {
toastr.error('Failed to submit change request');
document.execCommand('undo');
$(e).blur();
}
});
}
// for growl-like functionality, check for notifications periodically
(function worker() {
$.ajax({
url: uri_base + '/ajax/userlog'
,success: function(data) {
for (var i = 0; i < data['error'].length; i++) {
toastr.error(data['error'][i], 'Failed Change Request');
}
for (var i = 0; i < data['done'].length; i++) {
toastr.success(data['done'][i], 'Successful Change Request');
}
// Schedule next request when the current one's complete
setTimeout(worker, 5000);
}
,error: function() {
// after one failure, don't try again
toastr.warning('Unable to retrieve change request log')
}
});
})();

View File

@@ -0,0 +1,195 @@
// By: Hans Fjällemark and John Papa
// https://github.com/CodeSeven/toastr
//
// Modified to support css styling instead of inline styling
// Inspired by https://github.com/Srirangan/notifer.js/
; (function (define) {
define(['jquery'], function ($) {
var toastr = (function () {
var
defaults = {
tapToDismiss: true,
toastClass: 'toast',
containerId: 'toast-container',
debug: false,
fadeIn: 300,
fadeOut: 1000,
extendedTimeOut: 1000,
iconClasses: {
error: 'toast-error',
info: 'toast-info',
success: 'toast-success',
warning: 'toast-warning'
},
iconClass: 'toast-info',
positionClass: 'toast-top-right',
timeOut: 5000, // Set timeOut to 0 to make it sticky
titleClass: 'toast-title',
messageClass: 'toast-message'
},
error = function (message, title, optionsOverride) {
return notify({
iconClass: getOptions().iconClasses.error,
message: message,
optionsOverride: optionsOverride,
title: title
});
},
getContainer = function (options) {
var $container = $('#' + options.containerId);
if ($container.length) {
return $container;
}
$container = $('<div/>')
.attr('id', options.containerId)
.addClass(options.positionClass);
$container.appendTo($('body'));
return $container;
},
getOptions = function () {
return $.extend({}, defaults, toastr.options);
},
info = function (message, title, optionsOverride) {
return notify({
iconClass: getOptions().iconClasses.info,
message: message,
optionsOverride: optionsOverride,
title: title
});
},
notify = function (map) {
var
options = getOptions(),
iconClass = map.iconClass || options.iconClass;
if (typeof (map.optionsOverride) !== 'undefined') {
options = $.extend(options, map.optionsOverride);
iconClass = map.optionsOverride.iconClass || iconClass;
}
var
intervalId = null,
$container = getContainer(options),
$toastElement = $('<div/>'),
$titleElement = $('<div/>'),
$messageElement = $('<div/>'),
response = { options: options, map: map };
if (map.iconClass) {
$toastElement.addClass(options.toastClass).addClass(iconClass);
}
if (map.title) {
$titleElement.append(map.title).addClass(options.titleClass);
$toastElement.append($titleElement);
}
if (map.message) {
$messageElement.append(map.message).addClass(options.messageClass);
$toastElement.append($messageElement);
}
var fadeAway = function () {
if ($(':focus', $toastElement).length > 0) {
return;
}
var fade = function (callback) {
return $toastElement.fadeOut(options.fadeOut, callback);
};
var removeToast = function () {
if ($toastElement.is(':visible')) {
return;
}
$toastElement.remove();
if ($container.children().length === 0) {
$container.remove();
}
};
fade(removeToast);
};
var delayedFadeAway = function () {
if (options.timeOut > 0 || options.extendedTimeOut > 0) {
intervalId = setTimeout(fadeAway, options.extendedTimeOut);
}
};
var stickAround = function () {
clearTimeout(intervalId);
$toastElement.stop(true, true).fadeIn(options.fadeIn);
};
$toastElement.hide();
$container.prepend($toastElement);
$toastElement.fadeIn(options.fadeIn);
if (options.timeOut > 0) {
intervalId = setTimeout(fadeAway, options.timeOut);
}
$toastElement.hover(stickAround, delayedFadeAway);
if (!options.onclick && options.tapToDismiss) {
$toastElement.click(fadeAway);
}
if (options.onclick) {
$toastElement.click(function () {
options.onclick() && fadeAway();
});
}
if (options.debug && console) {
console.log(response);
}
return $toastElement;
},
success = function (message, title, optionsOverride) {
return notify({
iconClass: getOptions().iconClasses.success,
message: message,
optionsOverride: optionsOverride,
title: title
});
},
warning = function (message, title, optionsOverride) {
return notify({
iconClass: getOptions().iconClasses.warning,
message: message,
optionsOverride: optionsOverride,
title: title
});
},
clear = function () {
var options = getOptions();
var $container = $('#' + options.containerId);
if ($container.length) {
$container.fadeOut(options.fadeOut, function () {
$container.remove();
});
}
};
return {
clear: clear,
error: error,
info: info,
options: {},
success: success,
version: '1.1.1',
warning: warning
};
})();
return toastr;
});
}(typeof define === 'function' && define.amd ? define : function (deps, factory) {
if (typeof module !== 'undefined' && module.exports) { //Node
module.exports = factory(require(deps[0]));
} else {
window['toastr'] = factory(window['jQuery']);
}
}));