/*
* This file is part of Cockpit.
*
* Copyright (C) 2016 Red Hat, Inc.
*
* Cockpit is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Cockpit is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Cockpit; If not, see .
*/
(function() {
"use strict";
var React = require("react");
var cockpitListing = require("cockpit-components-listing.jsx");
/* Sample tab renderer for listing pattern
* Shows a caption and the time it was instantiated
*/
var DemoListingTab = React.createClass({
propTypes: {
description: React.PropTypes.string.isRequired,
},
getInitialState: function() {
return {
initTime: new Date().toLocaleString(),
};
},
render: function() {
return (
This is a listing tab {this.props.description} Initialized at: {this.state.initTime}
);
},
});
var showListingDemo = function(rootElement, rootElementSelectable, rootElementEmptyList) {
var navigateToItem = function(msg) {
window.alert("navigated to item: " + msg);
};
var handleAddClick = function(event) {
if (event.button !== 0)
return;
window.alert('This link could open a dialog to create a new entry');
};
var handlePlayClick = function(event) {
if (event.button !== 0)
return;
window.alert('This is a row-specific action');
event.stopPropagation();
};
var tabRenderers = [
{
name: 'onlyActive',
renderer: DemoListingTab,
data: { description: "Tab should only stay loaded when active" },
presence: 'onlyActive',
},
{
name: 'default',
renderer: DemoListingTab,
data: { description: "standard behavior tab" },
},
{
name: 'always',
renderer: DemoListingTab,
data: { description: "Tab should always stay loaded while row is expanded" },
presence: 'always',
},
{
name: 'loadOnDemand',
renderer: DemoListingTab,
data: { description: "Tab is loaded on demand, then stays active until row is collapsed" },
presence: 'loadOnDemand',
},
];
var addLink = Add Row;
var rowAction = {
element: ,
tight: true
};
// create the listings
var listing = (
);
React.render(listing, rootElement);
listing = (
);
React.render(listing, rootElementSelectable);
var emptyListing = ;
React.render(emptyListing, rootElementEmptyList);
};
module.exports = {
demo: showListingDemo,
};
}());