You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by vi...@apache.org on 2012/07/02 18:46:24 UTC
svn commit: r1356336 [13/34] - in /incubator/ambari/trunk: ./
mon_dashboard/src/addOns/nagios/plugins/ mon_dashboard/src/ui/libs/
mon_dashboard/src/ui/libs/html5shiv/ mon_dashboard/src/ui/libs/jqgrid/css/
mon_dashboard/src/ui/libs/jqgrid/js/ mon_dashbo...
Modified: incubator/ambari/trunk/mon_dashboard/src/ui/libs/jqgrid/plugins/jquery.tablednd.js
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/mon_dashboard/src/ui/libs/jqgrid/plugins/jquery.tablednd.js?rev=1356336&r1=1356335&r2=1356336&view=diff
==============================================================================
--- incubator/ambari/trunk/mon_dashboard/src/ui/libs/jqgrid/plugins/jquery.tablednd.js (original)
+++ incubator/ambari/trunk/mon_dashboard/src/ui/libs/jqgrid/plugins/jquery.tablednd.js Mon Jul 2 16:45:55 2012
@@ -1,383 +1,404 @@
-/**
- * TableDnD plug-in for JQuery, allows you to drag and drop table rows
- * You can set up various options to control how the system will work
- * Copyright (c) Denis Howlett <de...@isocra.com>
- * Licensed like jQuery, see http://docs.jquery.com/License.
- *
- * Configuration options:
- *
- * onDragStyle
- * This is the style that is assigned to the row during drag. There are limitations to the styles that can be
- * associated with a row (such as you can't assign a border--well you can, but it won't be
- * displayed). (So instead consider using onDragClass.) The CSS style to apply is specified as
- * a map (as used in the jQuery css(...) function).
- * onDropStyle
- * This is the style that is assigned to the row when it is dropped. As for onDragStyle, there are limitations
- * to what you can do. Also this replaces the original style, so again consider using onDragClass which
- * is simply added and then removed on drop.
- * onDragClass
- * This class is added for the duration of the drag and then removed when the row is dropped. It is more
- * flexible than using onDragStyle since it can be inherited by the row cells and other content. The default
- * is class is tDnD_whileDrag. So to use the default, simply customise this CSS class in your
- * stylesheet.
- * onDrop
- * Pass a function that will be called when the row is dropped. The function takes 2 parameters: the table
- * and the row that was dropped. You can work out the new order of the rows by using
- * table.rows.
- * onDragStart
- * Pass a function that will be called when the user starts dragging. The function takes 2 parameters: the
- * table and the row which the user has started to drag.
- * onAllowDrop
- * Pass a function that will be called as a row is over another row. If the function returns true, allow
- * dropping on that row, otherwise not. The function takes 2 parameters: the dragged row and the row under
- * the cursor. It returns a boolean: true allows the drop, false doesn't allow it.
- * scrollAmount
- * This is the number of pixels to scroll if the user moves the mouse cursor to the top or bottom of the
- * window. The page should automatically scroll up or down as appropriate (tested in IE6, IE7, Safari, FF2,
- * FF3 beta
- * dragHandle
- * This is the name of a class that you assign to one or more cells in each row that is draggable. If you
- * specify this class, then you are responsible for setting cursor: move in the CSS and only these cells
- * will have the drag behaviour. If you do not specify a dragHandle, then you get the old behaviour where
- * the whole row is draggable.
- *
- * Other ways to control behaviour:
- *
- * Add class="nodrop" to any rows for which you don't want to allow dropping, and class="nodrag" to any rows
- * that you don't want to be draggable.
- *
- * Inside the onDrop method you can also call $.tableDnD.serialize() this returns a string of the form
- * <tableID>[]=<rowID1>&<tableID>[]=<rowID2> so that you can send this back to the server. The table must have
- * an ID as must all the rows.
- *
- * Other methods:
- *
- * $("...").tableDnDUpdate()
- * Will update all the matching tables, that is it will reapply the mousedown method to the rows (or handle cells).
- * This is useful if you have updated the table rows using Ajax and you want to make the table draggable again.
- * The table maintains the original configuration (so you don't have to specify it again).
- *
- * $("...").tableDnDSerialize()
- * Will serialize and return the serialized string as above, but for each of the matching tables--so it can be
- * called from anywhere and isn't dependent on the currentTable being set up correctly before calling
- *
- * Known problems:
- * - Auto-scoll has some problems with IE7 (it scrolls even when it shouldn't), work-around: set scrollAmount to 0
- *
- * Version 0.2: 2008-02-20 First public version
- * Version 0.3: 2008-02-07 Added onDragStart option
- * Made the scroll amount configurable (default is 5 as before)
- * Version 0.4: 2008-03-15 Changed the noDrag/noDrop attributes to nodrag/nodrop classes
- * Added onAllowDrop to control dropping
- * Fixed a bug which meant that you couldn't set the scroll amount in both directions
- * Added serialize method
- * Version 0.5: 2008-05-16 Changed so that if you specify a dragHandle class it doesn't make the whole row
- * draggable
- * Improved the serialize method to use a default (and settable) regular expression.
- * Added tableDnDupate() and tableDnDSerialize() to be called when you are outside the table
- */
-jQuery.tableDnD = {
- /** Keep hold of the current table being dragged */
- currentTable : null,
- /** Keep hold of the current drag object if any */
- dragObject: null,
- /** The current mouse offset */
- mouseOffset: null,
- /** Remember the old value of Y so that we don't do too much processing */
- oldY: 0,
-
- /** Actually build the structure */
- build: function(options) {
- // Set up the defaults if any
-
- this.each(function() {
- // This is bound to each matching table, set up the defaults and override with user options
- this.tableDnDConfig = jQuery.extend({
- onDragStyle: null,
- onDropStyle: null,
- // Add in the default class for whileDragging
- onDragClass: "tDnD_whileDrag",
- onDrop: null,
- onDragStart: null,
- scrollAmount: 5,
- serializeRegexp: /[^\-]*$/, // The regular expression to use to trim row IDs
- serializeParamName: null, // If you want to specify another parameter name instead of the table ID
- dragHandle: null // If you give the name of a class here, then only Cells with this class will be draggable
- }, options || {});
- // Now make the rows draggable
- jQuery.tableDnD.makeDraggable(this);
- });
-
- // Now we need to capture the mouse up and mouse move event
- // We can use bind so that we don't interfere with other event handlers
- jQuery(document)
- .bind('mousemove', jQuery.tableDnD.mousemove)
- .bind('mouseup', jQuery.tableDnD.mouseup);
-
- // Don't break the chain
- return this;
- },
-
- /** This function makes all the rows on the table draggable apart from those marked as "NoDrag" */
- makeDraggable: function(table) {
- var config = table.tableDnDConfig;
- if (table.tableDnDConfig.dragHandle) {
- // We only need to add the event to the specified cells
- var cells = jQuery("td."+table.tableDnDConfig.dragHandle, table);
- cells.each(function() {
- // The cell is bound to "this"
- jQuery(this).mousedown(function(ev) {
- jQuery.tableDnD.dragObject = this.parentNode;
- jQuery.tableDnD.currentTable = table;
- jQuery.tableDnD.mouseOffset = jQuery.tableDnD.getMouseOffset(this, ev);
- if (config.onDragStart) {
- // Call the onDrop method if there is one
- config.onDragStart(table, this);
- }
- return false;
- });
- })
- } else {
- // For backwards compatibility, we add the event to the whole row
- var rows = jQuery("tr", table); // get all the rows as a wrapped set
- rows.each(function() {
- // Iterate through each row, the row is bound to "this"
- var row = jQuery(this);
- if (! row.hasClass("nodrag")) {
- row.mousedown(function(ev) {
- if (ev.target.tagName == "TD") {
- jQuery.tableDnD.dragObject = this;
- jQuery.tableDnD.currentTable = table;
- jQuery.tableDnD.mouseOffset = jQuery.tableDnD.getMouseOffset(this, ev);
- if (config.onDragStart) {
- // Call the onDrop method if there is one
- config.onDragStart(table, this);
- }
- return false;
- }
- }).css("cursor", "move"); // Store the tableDnD object
- }
- });
- }
- },
-
- updateTables: function() {
- this.each(function() {
- // this is now bound to each matching table
- if (this.tableDnDConfig) {
- jQuery.tableDnD.makeDraggable(this);
- }
- })
- },
-
- /** Get the mouse coordinates from the event (allowing for browser differences) */
- mouseCoords: function(ev){
- if(ev.pageX || ev.pageY){
- return {x:ev.pageX, y:ev.pageY};
- }
- return {
- x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
- y:ev.clientY + document.body.scrollTop - document.body.clientTop
- };
- },
-
- /** Given a target element and a mouse event, get the mouse offset from that element.
- To do this we need the element's position and the mouse position */
- getMouseOffset: function(target, ev) {
- ev = ev || window.event;
-
- var docPos = this.getPosition(target);
- var mousePos = this.mouseCoords(ev);
- return {x:mousePos.x - docPos.x, y:mousePos.y - docPos.y};
- },
-
- /** Get the position of an element by going up the DOM tree and adding up all the offsets */
- getPosition: function(e){
- var left = 0;
- var top = 0;
- /** Safari fix -- thanks to Luis Chato for this! */
- if (e.offsetHeight == 0) {
- /** Safari 2 doesn't correctly grab the offsetTop of a table row
- this is detailed here:
- http://jacob.peargrove.com/blog/2006/technical/table-row-offsettop-bug-in-safari/
- the solution is likewise noted there, grab the offset of a table cell in the row - the firstChild.
- note that firefox will return a text node as a first child, so designing a more thorough
- solution may need to take that into account, for now this seems to work in firefox, safari, ie */
- e = e.firstChild; // a table cell
- }
- if (e && e.offsetParent) {
- while (e.offsetParent){
- left += e.offsetLeft;
- top += e.offsetTop;
- e = e.offsetParent;
- }
-
- left += e.offsetLeft;
- top += e.offsetTop;
- }
-
- return {x:left, y:top};
- },
-
- mousemove: function(ev) {
- if (jQuery.tableDnD.dragObject == null) {
- return;
- }
-
- var dragObj = jQuery(jQuery.tableDnD.dragObject);
- var config = jQuery.tableDnD.currentTable.tableDnDConfig;
- var mousePos = jQuery.tableDnD.mouseCoords(ev);
- var y = mousePos.y - jQuery.tableDnD.mouseOffset.y;
- //auto scroll the window
- var yOffset = window.pageYOffset;
- if (document.all) {
- // Windows version
- //yOffset=document.body.scrollTop;
- if (typeof document.compatMode != 'undefined' &&
- document.compatMode != 'BackCompat') {
- yOffset = document.documentElement.scrollTop;
- }
- else if (typeof document.body != 'undefined') {
- yOffset=document.body.scrollTop;
- }
-
- }
-
- if (mousePos.y-yOffset < config.scrollAmount) {
- window.scrollBy(0, -config.scrollAmount);
- } else {
- var windowHeight = window.innerHeight ? window.innerHeight
- : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
- if (windowHeight-(mousePos.y-yOffset) < config.scrollAmount) {
- window.scrollBy(0, config.scrollAmount);
- }
- }
-
-
- if (y != jQuery.tableDnD.oldY) {
- // work out if we're going up or down...
- var movingDown = y > jQuery.tableDnD.oldY;
- // update the old value
- jQuery.tableDnD.oldY = y;
- // update the style to show we're dragging
- if (config.onDragClass) {
- dragObj.addClass(config.onDragClass);
- } else {
- dragObj.css(config.onDragStyle);
- }
- // If we're over a row then move the dragged row to there so that the user sees the
- // effect dynamically
- var currentRow = jQuery.tableDnD.findDropTargetRow(dragObj, y);
- if (currentRow) {
- // TODO worry about what happens when there are multiple TBODIES
- if (movingDown && jQuery.tableDnD.dragObject != currentRow) {
- jQuery.tableDnD.dragObject.parentNode.insertBefore(jQuery.tableDnD.dragObject, currentRow.nextSibling);
- } else if (! movingDown && jQuery.tableDnD.dragObject != currentRow) {
- jQuery.tableDnD.dragObject.parentNode.insertBefore(jQuery.tableDnD.dragObject, currentRow);
- }
- }
- }
-
- return false;
- },
-
- /** We're only worried about the y position really, because we can only move rows up and down */
- findDropTargetRow: function(draggedRow, y) {
- var rows = jQuery.tableDnD.currentTable.rows;
- for (var i=0; i<rows.length; i++) {
- var row = rows[i];
- var rowY = this.getPosition(row).y;
- var rowHeight = parseInt(row.offsetHeight)/2;
- if (row.offsetHeight == 0) {
- rowY = this.getPosition(row.firstChild).y;
- rowHeight = parseInt(row.firstChild.offsetHeight)/2;
- }
- // Because we always have to insert before, we need to offset the height a bit
- if ((y > rowY - rowHeight) && (y < (rowY + rowHeight))) {
- // that's the row we're over
- // If it's the same as the current row, ignore it
- if (row == draggedRow) {return null;}
- var config = jQuery.tableDnD.currentTable.tableDnDConfig;
- if (config.onAllowDrop) {
- if (config.onAllowDrop(draggedRow, row)) {
- return row;
- } else {
- return null;
- }
- } else {
- // If a row has nodrop class, then don't allow dropping (inspired by John Tarr and Famic)
- var nodrop = jQuery(row).hasClass("nodrop");
- if (! nodrop) {
- return row;
- } else {
- return null;
- }
- }
- return row;
- }
- }
- return null;
- },
-
- mouseup: function(e) {
- if (jQuery.tableDnD.currentTable && jQuery.tableDnD.dragObject) {
- var droppedRow = jQuery.tableDnD.dragObject;
- var config = jQuery.tableDnD.currentTable.tableDnDConfig;
- // If we have a dragObject, then we need to release it,
- // The row will already have been moved to the right place so we just reset stuff
- if (config.onDragClass) {
- jQuery(droppedRow).removeClass(config.onDragClass);
- } else {
- jQuery(droppedRow).css(config.onDropStyle);
- }
- jQuery.tableDnD.dragObject = null;
- if (config.onDrop) {
- // Call the onDrop method if there is one
- config.onDrop(jQuery.tableDnD.currentTable, droppedRow);
- }
- jQuery.tableDnD.currentTable = null; // let go of the table too
- }
- },
-
- serialize: function() {
- if (jQuery.tableDnD.currentTable) {
- return jQuery.tableDnD.serializeTable(jQuery.tableDnD.currentTable);
- } else {
- return "Error: No Table id set, you need to set an id on your table and every row";
- }
- },
-
- serializeTable: function(table) {
- var result = "";
- var tableId = table.id;
- var rows = table.rows;
- for (var i=0; i<rows.length; i++) {
- if (result.length > 0) result += "&";
- var rowId = rows[i].id;
- if (rowId && rowId && table.tableDnDConfig && table.tableDnDConfig.serializeRegexp) {
- rowId = rowId.match(table.tableDnDConfig.serializeRegexp)[0];
- }
-
- result += tableId + '[]=' + rowId;
- }
- return result;
- },
-
- serializeTables: function() {
- var result = "";
- this.each(function() {
- // this is now bound to each matching table
- result += jQuery.tableDnD.serializeTable(this);
- });
- return result;
- }
-
-}
-
-jQuery.fn.extend(
- {
- tableDnD : jQuery.tableDnD.build,
- tableDnDUpdate : jQuery.tableDnD.updateTables,
- tableDnDSerialize: jQuery.tableDnD.serializeTables
- }
-);
\ No newline at end of file
+/*
+ *
+ * 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.
+ *
+*/
+
+/**
+ * TableDnD plug-in for JQuery, allows you to drag and drop table rows
+ * You can set up various options to control how the system will work
+ * Copyright (c) Denis Howlett <de...@isocra.com>
+ * Licensed like jQuery, see http://docs.jquery.com/License.
+ *
+ * Configuration options:
+ *
+ * onDragStyle
+ * This is the style that is assigned to the row during drag. There are limitations to the styles that can be
+ * associated with a row (such as you can't assign a border--well you can, but it won't be
+ * displayed). (So instead consider using onDragClass.) The CSS style to apply is specified as
+ * a map (as used in the jQuery css(...) function).
+ * onDropStyle
+ * This is the style that is assigned to the row when it is dropped. As for onDragStyle, there are limitations
+ * to what you can do. Also this replaces the original style, so again consider using onDragClass which
+ * is simply added and then removed on drop.
+ * onDragClass
+ * This class is added for the duration of the drag and then removed when the row is dropped. It is more
+ * flexible than using onDragStyle since it can be inherited by the row cells and other content. The default
+ * is class is tDnD_whileDrag. So to use the default, simply customise this CSS class in your
+ * stylesheet.
+ * onDrop
+ * Pass a function that will be called when the row is dropped. The function takes 2 parameters: the table
+ * and the row that was dropped. You can work out the new order of the rows by using
+ * table.rows.
+ * onDragStart
+ * Pass a function that will be called when the user starts dragging. The function takes 2 parameters: the
+ * table and the row which the user has started to drag.
+ * onAllowDrop
+ * Pass a function that will be called as a row is over another row. If the function returns true, allow
+ * dropping on that row, otherwise not. The function takes 2 parameters: the dragged row and the row under
+ * the cursor. It returns a boolean: true allows the drop, false doesn't allow it.
+ * scrollAmount
+ * This is the number of pixels to scroll if the user moves the mouse cursor to the top or bottom of the
+ * window. The page should automatically scroll up or down as appropriate (tested in IE6, IE7, Safari, FF2,
+ * FF3 beta
+ * dragHandle
+ * This is the name of a class that you assign to one or more cells in each row that is draggable. If you
+ * specify this class, then you are responsible for setting cursor: move in the CSS and only these cells
+ * will have the drag behaviour. If you do not specify a dragHandle, then you get the old behaviour where
+ * the whole row is draggable.
+ *
+ * Other ways to control behaviour:
+ *
+ * Add class="nodrop" to any rows for which you don't want to allow dropping, and class="nodrag" to any rows
+ * that you don't want to be draggable.
+ *
+ * Inside the onDrop method you can also call $.tableDnD.serialize() this returns a string of the form
+ * <tableID>[]=<rowID1>&<tableID>[]=<rowID2> so that you can send this back to the server. The table must have
+ * an ID as must all the rows.
+ *
+ * Other methods:
+ *
+ * $("...").tableDnDUpdate()
+ * Will update all the matching tables, that is it will reapply the mousedown method to the rows (or handle cells).
+ * This is useful if you have updated the table rows using Ajax and you want to make the table draggable again.
+ * The table maintains the original configuration (so you don't have to specify it again).
+ *
+ * $("...").tableDnDSerialize()
+ * Will serialize and return the serialized string as above, but for each of the matching tables--so it can be
+ * called from anywhere and isn't dependent on the currentTable being set up correctly before calling
+ *
+ * Known problems:
+ * - Auto-scoll has some problems with IE7 (it scrolls even when it shouldn't), work-around: set scrollAmount to 0
+ *
+ * Version 0.2: 2008-02-20 First public version
+ * Version 0.3: 2008-02-07 Added onDragStart option
+ * Made the scroll amount configurable (default is 5 as before)
+ * Version 0.4: 2008-03-15 Changed the noDrag/noDrop attributes to nodrag/nodrop classes
+ * Added onAllowDrop to control dropping
+ * Fixed a bug which meant that you couldn't set the scroll amount in both directions
+ * Added serialize method
+ * Version 0.5: 2008-05-16 Changed so that if you specify a dragHandle class it doesn't make the whole row
+ * draggable
+ * Improved the serialize method to use a default (and settable) regular expression.
+ * Added tableDnDupate() and tableDnDSerialize() to be called when you are outside the table
+ */
+jQuery.tableDnD = {
+ /** Keep hold of the current table being dragged */
+ currentTable : null,
+ /** Keep hold of the current drag object if any */
+ dragObject: null,
+ /** The current mouse offset */
+ mouseOffset: null,
+ /** Remember the old value of Y so that we don't do too much processing */
+ oldY: 0,
+
+ /** Actually build the structure */
+ build: function(options) {
+ // Set up the defaults if any
+
+ this.each(function() {
+ // This is bound to each matching table, set up the defaults and override with user options
+ this.tableDnDConfig = jQuery.extend({
+ onDragStyle: null,
+ onDropStyle: null,
+ // Add in the default class for whileDragging
+ onDragClass: "tDnD_whileDrag",
+ onDrop: null,
+ onDragStart: null,
+ scrollAmount: 5,
+ serializeRegexp: /[^\-]*$/, // The regular expression to use to trim row IDs
+ serializeParamName: null, // If you want to specify another parameter name instead of the table ID
+ dragHandle: null // If you give the name of a class here, then only Cells with this class will be draggable
+ }, options || {});
+ // Now make the rows draggable
+ jQuery.tableDnD.makeDraggable(this);
+ });
+
+ // Now we need to capture the mouse up and mouse move event
+ // We can use bind so that we don't interfere with other event handlers
+ jQuery(document)
+ .bind('mousemove', jQuery.tableDnD.mousemove)
+ .bind('mouseup', jQuery.tableDnD.mouseup);
+
+ // Don't break the chain
+ return this;
+ },
+
+ /** This function makes all the rows on the table draggable apart from those marked as "NoDrag" */
+ makeDraggable: function(table) {
+ var config = table.tableDnDConfig;
+ if (table.tableDnDConfig.dragHandle) {
+ // We only need to add the event to the specified cells
+ var cells = jQuery("td."+table.tableDnDConfig.dragHandle, table);
+ cells.each(function() {
+ // The cell is bound to "this"
+ jQuery(this).mousedown(function(ev) {
+ jQuery.tableDnD.dragObject = this.parentNode;
+ jQuery.tableDnD.currentTable = table;
+ jQuery.tableDnD.mouseOffset = jQuery.tableDnD.getMouseOffset(this, ev);
+ if (config.onDragStart) {
+ // Call the onDrop method if there is one
+ config.onDragStart(table, this);
+ }
+ return false;
+ });
+ })
+ } else {
+ // For backwards compatibility, we add the event to the whole row
+ var rows = jQuery("tr", table); // get all the rows as a wrapped set
+ rows.each(function() {
+ // Iterate through each row, the row is bound to "this"
+ var row = jQuery(this);
+ if (! row.hasClass("nodrag")) {
+ row.mousedown(function(ev) {
+ if (ev.target.tagName == "TD") {
+ jQuery.tableDnD.dragObject = this;
+ jQuery.tableDnD.currentTable = table;
+ jQuery.tableDnD.mouseOffset = jQuery.tableDnD.getMouseOffset(this, ev);
+ if (config.onDragStart) {
+ // Call the onDrop method if there is one
+ config.onDragStart(table, this);
+ }
+ return false;
+ }
+ }).css("cursor", "move"); // Store the tableDnD object
+ }
+ });
+ }
+ },
+
+ updateTables: function() {
+ this.each(function() {
+ // this is now bound to each matching table
+ if (this.tableDnDConfig) {
+ jQuery.tableDnD.makeDraggable(this);
+ }
+ })
+ },
+
+ /** Get the mouse coordinates from the event (allowing for browser differences) */
+ mouseCoords: function(ev){
+ if(ev.pageX || ev.pageY){
+ return {x:ev.pageX, y:ev.pageY};
+ }
+ return {
+ x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
+ y:ev.clientY + document.body.scrollTop - document.body.clientTop
+ };
+ },
+
+ /** Given a target element and a mouse event, get the mouse offset from that element.
+ To do this we need the element's position and the mouse position */
+ getMouseOffset: function(target, ev) {
+ ev = ev || window.event;
+
+ var docPos = this.getPosition(target);
+ var mousePos = this.mouseCoords(ev);
+ return {x:mousePos.x - docPos.x, y:mousePos.y - docPos.y};
+ },
+
+ /** Get the position of an element by going up the DOM tree and adding up all the offsets */
+ getPosition: function(e){
+ var left = 0;
+ var top = 0;
+ /** Safari fix -- thanks to Luis Chato for this! */
+ if (e.offsetHeight == 0) {
+ /** Safari 2 doesn't correctly grab the offsetTop of a table row
+ this is detailed here:
+ http://jacob.peargrove.com/blog/2006/technical/table-row-offsettop-bug-in-safari/
+ the solution is likewise noted there, grab the offset of a table cell in the row - the firstChild.
+ note that firefox will return a text node as a first child, so designing a more thorough
+ solution may need to take that into account, for now this seems to work in firefox, safari, ie */
+ e = e.firstChild; // a table cell
+ }
+ if (e && e.offsetParent) {
+ while (e.offsetParent){
+ left += e.offsetLeft;
+ top += e.offsetTop;
+ e = e.offsetParent;
+ }
+
+ left += e.offsetLeft;
+ top += e.offsetTop;
+ }
+
+ return {x:left, y:top};
+ },
+
+ mousemove: function(ev) {
+ if (jQuery.tableDnD.dragObject == null) {
+ return;
+ }
+
+ var dragObj = jQuery(jQuery.tableDnD.dragObject);
+ var config = jQuery.tableDnD.currentTable.tableDnDConfig;
+ var mousePos = jQuery.tableDnD.mouseCoords(ev);
+ var y = mousePos.y - jQuery.tableDnD.mouseOffset.y;
+ //auto scroll the window
+ var yOffset = window.pageYOffset;
+ if (document.all) {
+ // Windows version
+ //yOffset=document.body.scrollTop;
+ if (typeof document.compatMode != 'undefined' &&
+ document.compatMode != 'BackCompat') {
+ yOffset = document.documentElement.scrollTop;
+ }
+ else if (typeof document.body != 'undefined') {
+ yOffset=document.body.scrollTop;
+ }
+
+ }
+
+ if (mousePos.y-yOffset < config.scrollAmount) {
+ window.scrollBy(0, -config.scrollAmount);
+ } else {
+ var windowHeight = window.innerHeight ? window.innerHeight
+ : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
+ if (windowHeight-(mousePos.y-yOffset) < config.scrollAmount) {
+ window.scrollBy(0, config.scrollAmount);
+ }
+ }
+
+
+ if (y != jQuery.tableDnD.oldY) {
+ // work out if we're going up or down...
+ var movingDown = y > jQuery.tableDnD.oldY;
+ // update the old value
+ jQuery.tableDnD.oldY = y;
+ // update the style to show we're dragging
+ if (config.onDragClass) {
+ dragObj.addClass(config.onDragClass);
+ } else {
+ dragObj.css(config.onDragStyle);
+ }
+ // If we're over a row then move the dragged row to there so that the user sees the
+ // effect dynamically
+ var currentRow = jQuery.tableDnD.findDropTargetRow(dragObj, y);
+ if (currentRow) {
+ // TODO worry about what happens when there are multiple TBODIES
+ if (movingDown && jQuery.tableDnD.dragObject != currentRow) {
+ jQuery.tableDnD.dragObject.parentNode.insertBefore(jQuery.tableDnD.dragObject, currentRow.nextSibling);
+ } else if (! movingDown && jQuery.tableDnD.dragObject != currentRow) {
+ jQuery.tableDnD.dragObject.parentNode.insertBefore(jQuery.tableDnD.dragObject, currentRow);
+ }
+ }
+ }
+
+ return false;
+ },
+
+ /** We're only worried about the y position really, because we can only move rows up and down */
+ findDropTargetRow: function(draggedRow, y) {
+ var rows = jQuery.tableDnD.currentTable.rows;
+ for (var i=0; i<rows.length; i++) {
+ var row = rows[i];
+ var rowY = this.getPosition(row).y;
+ var rowHeight = parseInt(row.offsetHeight)/2;
+ if (row.offsetHeight == 0) {
+ rowY = this.getPosition(row.firstChild).y;
+ rowHeight = parseInt(row.firstChild.offsetHeight)/2;
+ }
+ // Because we always have to insert before, we need to offset the height a bit
+ if ((y > rowY - rowHeight) && (y < (rowY + rowHeight))) {
+ // that's the row we're over
+ // If it's the same as the current row, ignore it
+ if (row == draggedRow) {return null;}
+ var config = jQuery.tableDnD.currentTable.tableDnDConfig;
+ if (config.onAllowDrop) {
+ if (config.onAllowDrop(draggedRow, row)) {
+ return row;
+ } else {
+ return null;
+ }
+ } else {
+ // If a row has nodrop class, then don't allow dropping (inspired by John Tarr and Famic)
+ var nodrop = jQuery(row).hasClass("nodrop");
+ if (! nodrop) {
+ return row;
+ } else {
+ return null;
+ }
+ }
+ return row;
+ }
+ }
+ return null;
+ },
+
+ mouseup: function(e) {
+ if (jQuery.tableDnD.currentTable && jQuery.tableDnD.dragObject) {
+ var droppedRow = jQuery.tableDnD.dragObject;
+ var config = jQuery.tableDnD.currentTable.tableDnDConfig;
+ // If we have a dragObject, then we need to release it,
+ // The row will already have been moved to the right place so we just reset stuff
+ if (config.onDragClass) {
+ jQuery(droppedRow).removeClass(config.onDragClass);
+ } else {
+ jQuery(droppedRow).css(config.onDropStyle);
+ }
+ jQuery.tableDnD.dragObject = null;
+ if (config.onDrop) {
+ // Call the onDrop method if there is one
+ config.onDrop(jQuery.tableDnD.currentTable, droppedRow);
+ }
+ jQuery.tableDnD.currentTable = null; // let go of the table too
+ }
+ },
+
+ serialize: function() {
+ if (jQuery.tableDnD.currentTable) {
+ return jQuery.tableDnD.serializeTable(jQuery.tableDnD.currentTable);
+ } else {
+ return "Error: No Table id set, you need to set an id on your table and every row";
+ }
+ },
+
+ serializeTable: function(table) {
+ var result = "";
+ var tableId = table.id;
+ var rows = table.rows;
+ for (var i=0; i<rows.length; i++) {
+ if (result.length > 0) result += "&";
+ var rowId = rows[i].id;
+ if (rowId && rowId && table.tableDnDConfig && table.tableDnDConfig.serializeRegexp) {
+ rowId = rowId.match(table.tableDnDConfig.serializeRegexp)[0];
+ }
+
+ result += tableId + '[]=' + rowId;
+ }
+ return result;
+ },
+
+ serializeTables: function() {
+ var result = "";
+ this.each(function() {
+ // this is now bound to each matching table
+ result += jQuery.tableDnD.serializeTable(this);
+ });
+ return result;
+ }
+
+}
+
+jQuery.fn.extend(
+ {
+ tableDnD : jQuery.tableDnD.build,
+ tableDnDUpdate : jQuery.tableDnD.updateTables,
+ tableDnDSerialize: jQuery.tableDnD.serializeTables
+ }
+);
Modified: incubator/ambari/trunk/mon_dashboard/src/ui/libs/jqgrid/plugins/searchFilter.css
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/mon_dashboard/src/ui/libs/jqgrid/plugins/searchFilter.css?rev=1356336&r1=1356335&r2=1356336&view=diff
==============================================================================
--- incubator/ambari/trunk/mon_dashboard/src/ui/libs/jqgrid/plugins/searchFilter.css (original)
+++ incubator/ambari/trunk/mon_dashboard/src/ui/libs/jqgrid/plugins/searchFilter.css Mon Jul 2 16:45:55 2012
@@ -1,6 +1,27 @@
-.ui-searchFilter { display: none; position: absolute; z-index: 770; overflow: visible;}
-.ui-searchFilter table {position:relative; margin:0em; width:auto}
-.ui-searchFilter table td {margin: 0em; padding: 1px;}
-.ui-searchFilter table td input, .ui-searchFilter table td select {margin: 0.1em;}
-.ui-searchFilter .ui-state-default { cursor: pointer; }
-.ui-searchFilter .divider hr {margin: 1px; }
\ No newline at end of file
+/*
+ *
+ * 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.
+ *
+*/
+
+.ui-searchFilter { display: none; position: absolute; z-index: 770; overflow: visible;}
+.ui-searchFilter table {position:relative; margin:0em; width:auto}
+.ui-searchFilter table td {margin: 0em; padding: 1px;}
+.ui-searchFilter table td input, .ui-searchFilter table td select {margin: 0.1em;}
+.ui-searchFilter .ui-state-default { cursor: pointer; }
+.ui-searchFilter .divider hr {margin: 1px; }
Modified: incubator/ambari/trunk/mon_dashboard/src/ui/libs/jqgrid/plugins/ui.multiselect.css
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/mon_dashboard/src/ui/libs/jqgrid/plugins/ui.multiselect.css?rev=1356336&r1=1356335&r2=1356336&view=diff
==============================================================================
--- incubator/ambari/trunk/mon_dashboard/src/ui/libs/jqgrid/plugins/ui.multiselect.css (original)
+++ incubator/ambari/trunk/mon_dashboard/src/ui/libs/jqgrid/plugins/ui.multiselect.css Mon Jul 2 16:45:55 2012
@@ -1,30 +1,51 @@
-/* Multiselect
-----------------------------------*/
-
-.ui-multiselect { border: solid 1px; font-size: 0.8em; }
-.ui-multiselect ul { -moz-user-select: none; }
-.ui-multiselect li { margin: 0; padding: 0; cursor: default; line-height: 20px; height: 20px; font-size: 11px; list-style: none; }
-.ui-multiselect li a { color: #999; text-decoration: none; padding: 0; display: block; float: left; cursor: pointer;}
-.ui-multiselect li.ui-draggable-dragging { padding-left: 10px; }
-
-.ui-multiselect div.selected { position: relative; padding: 0; margin: 0; border: 0; float:left; }
-.ui-multiselect ul.selected { position: relative; padding: 0; overflow: auto; overflow-x: hidden; background: #fff; margin: 0; list-style: none; border: 0; position: relative; width: 100%; }
-.ui-multiselect ul.selected li { }
-
-.ui-multiselect div.available { position: relative; padding: 0; margin: 0; border: 0; float:left; border-left: 1px solid; }
-.ui-multiselect ul.available { position: relative; padding: 0; overflow: auto; overflow-x: hidden; background: #fff; margin: 0; list-style: none; border: 0; width: 100%; }
-.ui-multiselect ul.available li { padding-left: 10px; }
-
-.ui-multiselect .ui-state-default { border: none; margin-bottom: 1px; position: relative; padding-left: 20px;}
-.ui-multiselect .ui-state-hover { border: none; }
-.ui-multiselect .ui-widget-header {border: none; font-size: 11px; margin-bottom: 1px;}
-
-.ui-multiselect .add-all { float: right; padding: 7px;}
-.ui-multiselect .remove-all { float: right; padding: 7px;}
-.ui-multiselect .search { float: left; padding: 4px;}
-.ui-multiselect .count { float: left; padding: 7px;}
-
-.ui-multiselect li span.ui-icon-arrowthick-2-n-s { position: absolute; left: 2px; }
-.ui-multiselect li a.action { position: absolute; right: 2px; top: 2px; }
-
-.ui-multiselect input.search { height: 14px; padding: 1px; opacity: 0.5; margin: 4px; width: 100px; }
\ No newline at end of file
+/*
+ *
+ * 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.
+ *
+*/
+
+/* Multiselect
+----------------------------------*/
+
+.ui-multiselect { border: solid 1px; font-size: 0.8em; }
+.ui-multiselect ul { -moz-user-select: none; }
+.ui-multiselect li { margin: 0; padding: 0; cursor: default; line-height: 20px; height: 20px; font-size: 11px; list-style: none; }
+.ui-multiselect li a { color: #999; text-decoration: none; padding: 0; display: block; float: left; cursor: pointer;}
+.ui-multiselect li.ui-draggable-dragging { padding-left: 10px; }
+
+.ui-multiselect div.selected { position: relative; padding: 0; margin: 0; border: 0; float:left; }
+.ui-multiselect ul.selected { position: relative; padding: 0; overflow: auto; overflow-x: hidden; background: #fff; margin: 0; list-style: none; border: 0; position: relative; width: 100%; }
+.ui-multiselect ul.selected li { }
+
+.ui-multiselect div.available { position: relative; padding: 0; margin: 0; border: 0; float:left; border-left: 1px solid; }
+.ui-multiselect ul.available { position: relative; padding: 0; overflow: auto; overflow-x: hidden; background: #fff; margin: 0; list-style: none; border: 0; width: 100%; }
+.ui-multiselect ul.available li { padding-left: 10px; }
+
+.ui-multiselect .ui-state-default { border: none; margin-bottom: 1px; position: relative; padding-left: 20px;}
+.ui-multiselect .ui-state-hover { border: none; }
+.ui-multiselect .ui-widget-header {border: none; font-size: 11px; margin-bottom: 1px;}
+
+.ui-multiselect .add-all { float: right; padding: 7px;}
+.ui-multiselect .remove-all { float: right; padding: 7px;}
+.ui-multiselect .search { float: left; padding: 4px;}
+.ui-multiselect .count { float: left; padding: 7px;}
+
+.ui-multiselect li span.ui-icon-arrowthick-2-n-s { position: absolute; left: 2px; }
+.ui-multiselect li a.action { position: absolute; right: 2px; top: 2px; }
+
+.ui-multiselect input.search { height: 14px; padding: 1px; opacity: 0.5; margin: 4px; width: 100px; }
Modified: incubator/ambari/trunk/mon_dashboard/src/ui/libs/jqgrid/plugins/ui.multiselect.js
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/mon_dashboard/src/ui/libs/jqgrid/plugins/ui.multiselect.js?rev=1356336&r1=1356335&r2=1356336&view=diff
==============================================================================
--- incubator/ambari/trunk/mon_dashboard/src/ui/libs/jqgrid/plugins/ui.multiselect.js (original)
+++ incubator/ambari/trunk/mon_dashboard/src/ui/libs/jqgrid/plugins/ui.multiselect.js Mon Jul 2 16:45:55 2012
@@ -1,314 +1,335 @@
-/*
- * jQuery UI Multiselect
- *
- * Authors:
- * Michael Aufreiter (quasipartikel.at)
- * Yanick Rochon (yanick.rochon[at]gmail[dot]com)
- *
- * Dual licensed under the MIT (MIT-LICENSE.txt)
- * and GPL (GPL-LICENSE.txt) licenses.
- *
- * http://www.quasipartikel.at/multiselect/
- *
- *
- * Depends:
- * ui.core.js
- * ui.sortable.js
- *
- * Optional:
- * localization (http://plugins.jquery.com/project/localisation)
- * scrollTo (http://plugins.jquery.com/project/ScrollTo)
- *
- * Todo:
- * Make batch actions faster
- * Implement dynamic insertion through remote calls
- */
-
-
-(function($) {
-
-$.widget("ui.multiselect", {
- _init: function() {
- this.element.hide();
- this.id = this.element.attr("id");
- this.container = $('<div class="ui-multiselect ui-helper-clearfix ui-widget"></div>').insertAfter(this.element);
- this.count = 0; // number of currently selected options
- this.selectedContainer = $('<div class="selected"></div>').appendTo(this.container);
- this.availableContainer = $('<div class="available"></div>').appendTo(this.container);
- this.selectedActions = $('<div class="actions ui-widget-header ui-helper-clearfix"><span class="count">0 '+$.ui.multiselect.locale.itemsCount+'</span><a href="#" class="remove-all">'+$.ui.multiselect.locale.removeAll+'</a></div>').appendTo(this.selectedContainer);
- this.availableActions = $('<div class="actions ui-widget-header ui-helper-clearfix"><input type="text" class="search empty ui-widget-content ui-corner-all"/><a href="#" class="add-all">'+$.ui.multiselect.locale.addAll+'</a></div>').appendTo(this.availableContainer);
- this.selectedList = $('<ul class="selected connected-list"><li class="ui-helper-hidden-accessible"></li></ul>').bind('selectstart', function(){return false;}).appendTo(this.selectedContainer);
- this.availableList = $('<ul class="available connected-list"><li class="ui-helper-hidden-accessible"></li></ul>').bind('selectstart', function(){return false;}).appendTo(this.availableContainer);
-
- var that = this;
-
- // set dimensions
- this.container.width(this.element.width()+1);
- this.selectedContainer.width(Math.floor(this.element.width()*this.options.dividerLocation));
- this.availableContainer.width(Math.floor(this.element.width()*(1-this.options.dividerLocation)));
-
- // fix list height to match <option> depending on their individual header's heights
- this.selectedList.height(Math.max(this.element.height()-this.selectedActions.height(),1));
- this.availableList.height(Math.max(this.element.height()-this.availableActions.height(),1));
-
- if ( !this.options.animated ) {
- this.options.show = 'show';
- this.options.hide = 'hide';
- }
-
- // init lists
- this._populateLists(this.element.find('option'));
-
- // make selection sortable
- if (this.options.sortable) {
- $("ul.selected").sortable({
- placeholder: 'ui-state-highlight',
- axis: 'y',
- update: function(event, ui) {
- // apply the new sort order to the original selectbox
- that.selectedList.find('li').each(function() {
- if ($(this).data('optionLink'))
- $(this).data('optionLink').remove().appendTo(that.element);
- });
- },
- receive: function(event, ui) {
- ui.item.data('optionLink').attr('selected', true);
- // increment count
- that.count += 1;
- that._updateCount();
- // workaround, because there's no way to reference
- // the new element, see http://dev.jqueryui.com/ticket/4303
- that.selectedList.children('.ui-draggable').each(function() {
- $(this).removeClass('ui-draggable');
- $(this).data('optionLink', ui.item.data('optionLink'));
- $(this).data('idx', ui.item.data('idx'));
- that._applyItemState($(this), true);
- });
-
- // workaround according to http://dev.jqueryui.com/ticket/4088
- setTimeout(function() { ui.item.remove(); }, 1);
- }
- });
- }
-
- // set up livesearch
- if (this.options.searchable) {
- this._registerSearchEvents(this.availableContainer.find('input.search'));
- } else {
- $('.search').hide();
- }
-
- // batch actions
- $(".remove-all").click(function() {
- that._populateLists(that.element.find('option').removeAttr('selected'));
- return false;
- });
- $(".add-all").click(function() {
- that._populateLists(that.element.find('option').attr('selected', 'selected'));
- return false;
- });
- },
- destroy: function() {
- this.element.show();
- this.container.remove();
-
- $.widget.prototype.destroy.apply(this, arguments);
- },
- _populateLists: function(options) {
- this.selectedList.children('.ui-element').remove();
- this.availableList.children('.ui-element').remove();
- this.count = 0;
-
- var that = this;
- var items = $(options.map(function(i) {
- var item = that._getOptionNode(this).appendTo(this.selected ? that.selectedList : that.availableList).show();
-
- if (this.selected) that.count += 1;
- that._applyItemState(item, this.selected);
- item.data('idx', i);
- return item[0];
- }));
-
- // update count
- this._updateCount();
- },
- _updateCount: function() {
- this.selectedContainer.find('span.count').text(this.count+" "+$.ui.multiselect.locale.itemsCount);
- },
- _getOptionNode: function(option) {
- option = $(option);
- var node = $('<li class="ui-state-default ui-element" title="'+option.text()+'"><span class="ui-icon"/>'+option.text()+'<a href="#" class="action"><span class="ui-corner-all ui-icon"/></a></li>').hide();
- node.data('optionLink', option);
- return node;
- },
- // clones an item with associated data
- // didn't find a smarter away around this
- _cloneWithData: function(clonee) {
- var clone = clonee.clone();
- clone.data('optionLink', clonee.data('optionLink'));
- clone.data('idx', clonee.data('idx'));
- return clone;
- },
- _setSelected: function(item, selected) {
- item.data('optionLink').attr('selected', selected);
-
- if (selected) {
- var selectedItem = this._cloneWithData(item);
- item[this.options.hide](this.options.animated, function() { $(this).remove(); });
- selectedItem.appendTo(this.selectedList).hide()[this.options.show](this.options.animated);
-
- this._applyItemState(selectedItem, true);
- return selectedItem;
- } else {
-
- // look for successor based on initial option index
- var items = this.availableList.find('li'), comparator = this.options.nodeComparator;
- var succ = null, i = item.data('idx'), direction = comparator(item, $(items[i]));
-
- // TODO: test needed for dynamic list populating
- if ( direction ) {
- while (i>=0 && i<items.length) {
- direction > 0 ? i++ : i--;
- if ( direction != comparator(item, $(items[i])) ) {
- // going up, go back one item down, otherwise leave as is
- succ = items[direction > 0 ? i : i+1];
- break;
- }
- }
- } else {
- succ = items[i];
- }
-
- var availableItem = this._cloneWithData(item);
- succ ? availableItem.insertBefore($(succ)) : availableItem.appendTo(this.availableList);
- item[this.options.hide](this.options.animated, function() { $(this).remove(); });
- availableItem.hide()[this.options.show](this.options.animated);
-
- this._applyItemState(availableItem, false);
- return availableItem;
- }
- },
- _applyItemState: function(item, selected) {
- if (selected) {
- if (this.options.sortable)
- item.children('span').addClass('ui-icon-arrowthick-2-n-s').removeClass('ui-helper-hidden').addClass('ui-icon');
- else
- item.children('span').removeClass('ui-icon-arrowthick-2-n-s').addClass('ui-helper-hidden').removeClass('ui-icon');
- item.find('a.action span').addClass('ui-icon-minus').removeClass('ui-icon-plus');
- this._registerRemoveEvents(item.find('a.action'));
-
- } else {
- item.children('span').removeClass('ui-icon-arrowthick-2-n-s').addClass('ui-helper-hidden').removeClass('ui-icon');
- item.find('a.action span').addClass('ui-icon-plus').removeClass('ui-icon-minus');
- this._registerAddEvents(item.find('a.action'));
- }
-
- this._registerHoverEvents(item);
- },
- // taken from John Resig's liveUpdate script
- _filter: function(list) {
- var input = $(this);
- var rows = list.children('li'),
- cache = rows.map(function(){
-
- return $(this).text().toLowerCase();
- });
-
- var term = $.trim(input.val().toLowerCase()), scores = [];
-
- if (!term) {
- rows.show();
- } else {
- rows.hide();
-
- cache.each(function(i) {
- if (this.indexOf(term)>-1) { scores.push(i); }
- });
-
- $.each(scores, function() {
- $(rows[this]).show();
- });
- }
- },
- _registerHoverEvents: function(elements) {
- elements.removeClass('ui-state-hover');
- elements.mouseover(function() {
- $(this).addClass('ui-state-hover');
- });
- elements.mouseout(function() {
- $(this).removeClass('ui-state-hover');
- });
- },
- _registerAddEvents: function(elements) {
- var that = this;
- elements.click(function() {
- var item = that._setSelected($(this).parent(), true);
- that.count += 1;
- that._updateCount();
- return false;
- })
- // make draggable
- .each(function() {
- $(this).parent().draggable({
- connectToSortable: 'ul.selected',
- helper: function() {
- var selectedItem = that._cloneWithData($(this)).width($(this).width() - 50);
- selectedItem.width($(this).width());
- return selectedItem;
- },
- appendTo: '.ui-multiselect',
- containment: '.ui-multiselect',
- revert: 'invalid'
- });
- });
- },
- _registerRemoveEvents: function(elements) {
- var that = this;
- elements.click(function() {
- that._setSelected($(this).parent(), false);
- that.count -= 1;
- that._updateCount();
- return false;
- });
- },
- _registerSearchEvents: function(input) {
- var that = this;
-
- input.focus(function() {
- $(this).addClass('ui-state-active');
- })
- .blur(function() {
- $(this).removeClass('ui-state-active');
- })
- .keypress(function(e) {
- if (e.keyCode == 13)
- return false;
- })
- .keyup(function() {
- that._filter.apply(this, [that.availableList]);
- });
- }
-});
-
-$.extend($.ui.multiselect, {
- defaults: {
- sortable: true,
- searchable: true,
- animated: 'fast',
- show: 'slideDown',
- hide: 'slideUp',
- dividerLocation: 0.6,
- nodeComparator: function(node1,node2) {
- var text1 = node1.text(),
- text2 = node2.text();
- return text1 == text2 ? 0 : (text1 < text2 ? -1 : 1);
- }
- },
- locale: {
- addAll:'Add all',
- removeAll:'Remove all',
- itemsCount:'items selected'
- }
-});
-
-})(jQuery);
+/*
+ *
+ * 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.
+ *
+*/
+
+/*
+ * jQuery UI Multiselect
+ *
+ * Authors:
+ * Michael Aufreiter (quasipartikel.at)
+ * Yanick Rochon (yanick.rochon[at]gmail[dot]com)
+ *
+ * Dual licensed under the MIT (MIT-LICENSE.txt)
+ * and GPL (GPL-LICENSE.txt) licenses.
+ *
+ * http://www.quasipartikel.at/multiselect/
+ *
+ *
+ * Depends:
+ * ui.core.js
+ * ui.sortable.js
+ *
+ * Optional:
+ * localization (http://plugins.jquery.com/project/localisation)
+ * scrollTo (http://plugins.jquery.com/project/ScrollTo)
+ *
+ * Todo:
+ * Make batch actions faster
+ * Implement dynamic insertion through remote calls
+ */
+
+
+(function($) {
+
+$.widget("ui.multiselect", {
+ _init: function() {
+ this.element.hide();
+ this.id = this.element.attr("id");
+ this.container = $('<div class="ui-multiselect ui-helper-clearfix ui-widget"></div>').insertAfter(this.element);
+ this.count = 0; // number of currently selected options
+ this.selectedContainer = $('<div class="selected"></div>').appendTo(this.container);
+ this.availableContainer = $('<div class="available"></div>').appendTo(this.container);
+ this.selectedActions = $('<div class="actions ui-widget-header ui-helper-clearfix"><span class="count">0 '+$.ui.multiselect.locale.itemsCount+'</span><a href="#" class="remove-all">'+$.ui.multiselect.locale.removeAll+'</a></div>').appendTo(this.selectedContainer);
+ this.availableActions = $('<div class="actions ui-widget-header ui-helper-clearfix"><input type="text" class="search empty ui-widget-content ui-corner-all"/><a href="#" class="add-all">'+$.ui.multiselect.locale.addAll+'</a></div>').appendTo(this.availableContainer);
+ this.selectedList = $('<ul class="selected connected-list"><li class="ui-helper-hidden-accessible"></li></ul>').bind('selectstart', function(){return false;}).appendTo(this.selectedContainer);
+ this.availableList = $('<ul class="available connected-list"><li class="ui-helper-hidden-accessible"></li></ul>').bind('selectstart', function(){return false;}).appendTo(this.availableContainer);
+
+ var that = this;
+
+ // set dimensions
+ this.container.width(this.element.width()+1);
+ this.selectedContainer.width(Math.floor(this.element.width()*this.options.dividerLocation));
+ this.availableContainer.width(Math.floor(this.element.width()*(1-this.options.dividerLocation)));
+
+ // fix list height to match <option> depending on their individual header's heights
+ this.selectedList.height(Math.max(this.element.height()-this.selectedActions.height(),1));
+ this.availableList.height(Math.max(this.element.height()-this.availableActions.height(),1));
+
+ if ( !this.options.animated ) {
+ this.options.show = 'show';
+ this.options.hide = 'hide';
+ }
+
+ // init lists
+ this._populateLists(this.element.find('option'));
+
+ // make selection sortable
+ if (this.options.sortable) {
+ $("ul.selected").sortable({
+ placeholder: 'ui-state-highlight',
+ axis: 'y',
+ update: function(event, ui) {
+ // apply the new sort order to the original selectbox
+ that.selectedList.find('li').each(function() {
+ if ($(this).data('optionLink'))
+ $(this).data('optionLink').remove().appendTo(that.element);
+ });
+ },
+ receive: function(event, ui) {
+ ui.item.data('optionLink').attr('selected', true);
+ // increment count
+ that.count += 1;
+ that._updateCount();
+ // workaround, because there's no way to reference
+ // the new element, see http://dev.jqueryui.com/ticket/4303
+ that.selectedList.children('.ui-draggable').each(function() {
+ $(this).removeClass('ui-draggable');
+ $(this).data('optionLink', ui.item.data('optionLink'));
+ $(this).data('idx', ui.item.data('idx'));
+ that._applyItemState($(this), true);
+ });
+
+ // workaround according to http://dev.jqueryui.com/ticket/4088
+ setTimeout(function() { ui.item.remove(); }, 1);
+ }
+ });
+ }
+
+ // set up livesearch
+ if (this.options.searchable) {
+ this._registerSearchEvents(this.availableContainer.find('input.search'));
+ } else {
+ $('.search').hide();
+ }
+
+ // batch actions
+ $(".remove-all").click(function() {
+ that._populateLists(that.element.find('option').removeAttr('selected'));
+ return false;
+ });
+ $(".add-all").click(function() {
+ that._populateLists(that.element.find('option').attr('selected', 'selected'));
+ return false;
+ });
+ },
+ destroy: function() {
+ this.element.show();
+ this.container.remove();
+
+ $.widget.prototype.destroy.apply(this, arguments);
+ },
+ _populateLists: function(options) {
+ this.selectedList.children('.ui-element').remove();
+ this.availableList.children('.ui-element').remove();
+ this.count = 0;
+
+ var that = this;
+ var items = $(options.map(function(i) {
+ var item = that._getOptionNode(this).appendTo(this.selected ? that.selectedList : that.availableList).show();
+
+ if (this.selected) that.count += 1;
+ that._applyItemState(item, this.selected);
+ item.data('idx', i);
+ return item[0];
+ }));
+
+ // update count
+ this._updateCount();
+ },
+ _updateCount: function() {
+ this.selectedContainer.find('span.count').text(this.count+" "+$.ui.multiselect.locale.itemsCount);
+ },
+ _getOptionNode: function(option) {
+ option = $(option);
+ var node = $('<li class="ui-state-default ui-element" title="'+option.text()+'"><span class="ui-icon"/>'+option.text()+'<a href="#" class="action"><span class="ui-corner-all ui-icon"/></a></li>').hide();
+ node.data('optionLink', option);
+ return node;
+ },
+ // clones an item with associated data
+ // didn't find a smarter away around this
+ _cloneWithData: function(clonee) {
+ var clone = clonee.clone();
+ clone.data('optionLink', clonee.data('optionLink'));
+ clone.data('idx', clonee.data('idx'));
+ return clone;
+ },
+ _setSelected: function(item, selected) {
+ item.data('optionLink').attr('selected', selected);
+
+ if (selected) {
+ var selectedItem = this._cloneWithData(item);
+ item[this.options.hide](this.options.animated, function() { $(this).remove(); });
+ selectedItem.appendTo(this.selectedList).hide()[this.options.show](this.options.animated);
+
+ this._applyItemState(selectedItem, true);
+ return selectedItem;
+ } else {
+
+ // look for successor based on initial option index
+ var items = this.availableList.find('li'), comparator = this.options.nodeComparator;
+ var succ = null, i = item.data('idx'), direction = comparator(item, $(items[i]));
+
+ // TODO: test needed for dynamic list populating
+ if ( direction ) {
+ while (i>=0 && i<items.length) {
+ direction > 0 ? i++ : i--;
+ if ( direction != comparator(item, $(items[i])) ) {
+ // going up, go back one item down, otherwise leave as is
+ succ = items[direction > 0 ? i : i+1];
+ break;
+ }
+ }
+ } else {
+ succ = items[i];
+ }
+
+ var availableItem = this._cloneWithData(item);
+ succ ? availableItem.insertBefore($(succ)) : availableItem.appendTo(this.availableList);
+ item[this.options.hide](this.options.animated, function() { $(this).remove(); });
+ availableItem.hide()[this.options.show](this.options.animated);
+
+ this._applyItemState(availableItem, false);
+ return availableItem;
+ }
+ },
+ _applyItemState: function(item, selected) {
+ if (selected) {
+ if (this.options.sortable)
+ item.children('span').addClass('ui-icon-arrowthick-2-n-s').removeClass('ui-helper-hidden').addClass('ui-icon');
+ else
+ item.children('span').removeClass('ui-icon-arrowthick-2-n-s').addClass('ui-helper-hidden').removeClass('ui-icon');
+ item.find('a.action span').addClass('ui-icon-minus').removeClass('ui-icon-plus');
+ this._registerRemoveEvents(item.find('a.action'));
+
+ } else {
+ item.children('span').removeClass('ui-icon-arrowthick-2-n-s').addClass('ui-helper-hidden').removeClass('ui-icon');
+ item.find('a.action span').addClass('ui-icon-plus').removeClass('ui-icon-minus');
+ this._registerAddEvents(item.find('a.action'));
+ }
+
+ this._registerHoverEvents(item);
+ },
+ // taken from John Resig's liveUpdate script
+ _filter: function(list) {
+ var input = $(this);
+ var rows = list.children('li'),
+ cache = rows.map(function(){
+
+ return $(this).text().toLowerCase();
+ });
+
+ var term = $.trim(input.val().toLowerCase()), scores = [];
+
+ if (!term) {
+ rows.show();
+ } else {
+ rows.hide();
+
+ cache.each(function(i) {
+ if (this.indexOf(term)>-1) { scores.push(i); }
+ });
+
+ $.each(scores, function() {
+ $(rows[this]).show();
+ });
+ }
+ },
+ _registerHoverEvents: function(elements) {
+ elements.removeClass('ui-state-hover');
+ elements.mouseover(function() {
+ $(this).addClass('ui-state-hover');
+ });
+ elements.mouseout(function() {
+ $(this).removeClass('ui-state-hover');
+ });
+ },
+ _registerAddEvents: function(elements) {
+ var that = this;
+ elements.click(function() {
+ var item = that._setSelected($(this).parent(), true);
+ that.count += 1;
+ that._updateCount();
+ return false;
+ })
+ // make draggable
+ .each(function() {
+ $(this).parent().draggable({
+ connectToSortable: 'ul.selected',
+ helper: function() {
+ var selectedItem = that._cloneWithData($(this)).width($(this).width() - 50);
+ selectedItem.width($(this).width());
+ return selectedItem;
+ },
+ appendTo: '.ui-multiselect',
+ containment: '.ui-multiselect',
+ revert: 'invalid'
+ });
+ });
+ },
+ _registerRemoveEvents: function(elements) {
+ var that = this;
+ elements.click(function() {
+ that._setSelected($(this).parent(), false);
+ that.count -= 1;
+ that._updateCount();
+ return false;
+ });
+ },
+ _registerSearchEvents: function(input) {
+ var that = this;
+
+ input.focus(function() {
+ $(this).addClass('ui-state-active');
+ })
+ .blur(function() {
+ $(this).removeClass('ui-state-active');
+ })
+ .keypress(function(e) {
+ if (e.keyCode == 13)
+ return false;
+ })
+ .keyup(function() {
+ that._filter.apply(this, [that.availableList]);
+ });
+ }
+});
+
+$.extend($.ui.multiselect, {
+ defaults: {
+ sortable: true,
+ searchable: true,
+ animated: 'fast',
+ show: 'slideDown',
+ hide: 'slideUp',
+ dividerLocation: 0.6,
+ nodeComparator: function(node1,node2) {
+ var text1 = node1.text(),
+ text2 = node2.text();
+ return text1 == text2 ? 0 : (text1 < text2 ? -1 : 1);
+ }
+ },
+ locale: {
+ addAll:'Add all',
+ removeAll:'Remove all',
+ itemsCount:'items selected'
+ }
+});
+
+})(jQuery);
Modified: incubator/ambari/trunk/mon_dashboard/src/ui/libs/jqgrid/src/JsonXml.js
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/mon_dashboard/src/ui/libs/jqgrid/src/JsonXml.js?rev=1356336&r1=1356335&r2=1356336&view=diff
==============================================================================
--- incubator/ambari/trunk/mon_dashboard/src/ui/libs/jqgrid/src/JsonXml.js (original)
+++ incubator/ambari/trunk/mon_dashboard/src/ui/libs/jqgrid/src/JsonXml.js Mon Jul 2 16:45:55 2012
@@ -1,339 +1,360 @@
-/*
- The below work is licensed under Creative Commons GNU LGPL License.
-
- Original work:
-
- License: http://creativecommons.org/licenses/LGPL/2.1/
- Author: Stefan Goessner/2006
- Web: http://goessner.net/
-
- Modifications made:
-
- Version: 0.9-p5
- Description: Restructured code, JSLint validated (no strict whitespaces),
- added handling of empty arrays, empty strings, and int/floats values.
- Author: Michael Schøler/2008-01-29
- Web: http://michael.hinnerup.net/blog/2008/01/26/converting-json-to-xml-and-xml-to-json/
-
- Description: json2xml added support to convert functions as CDATA
- so it will be easy to write characters that cause some problems when convert
- Author: Tony Tomov
-*/
-
-/*global alert */
-var xmlJsonClass = {
- // Param "xml": Element or document DOM node.
- // Param "tab": Tab or indent string for pretty output formatting omit or use empty string "" to supress.
- // Returns: JSON string
- xml2json: function(xml, tab) {
- if (xml.nodeType === 9) {
- // document node
- xml = xml.documentElement;
- }
- var nws = this.removeWhite(xml);
- var obj = this.toObj(nws);
- var json = this.toJson(obj, xml.nodeName, "\t");
- return "{\n" + tab + (tab ? json.replace(/\t/g, tab) : json.replace(/\t|\n/g, "")) + "\n}";
- },
-
- // Param "o": JavaScript object
- // Param "tab": tab or indent string for pretty output formatting omit or use empty string "" to supress.
- // Returns: XML string
- json2xml: function(o, tab) {
- var toXml = function(v, name, ind) {
- var xml = "";
- var i, n;
- if (v instanceof Array) {
- if (v.length === 0) {
- xml += ind + "<"+name+">__EMPTY_ARRAY_</"+name+">\n";
- }
- else {
- for (i = 0, n = v.length; i < n; i += 1) {
- var sXml = ind + toXml(v[i], name, ind+"\t") + "\n";
- xml += sXml;
- }
- }
- }
- else if (typeof(v) === "object") {
- var hasChild = false;
- xml += ind + "<" + name;
- var m;
- for (m in v) if (v.hasOwnProperty(m)) {
- if (m.charAt(0) === "@") {
- xml += " " + m.substr(1) + "=\"" + v[m].toString() + "\"";
- }
- else {
- hasChild = true;
- }
- }
- xml += hasChild ? ">" : "/>";
- if (hasChild) {
- for (m in v) if (v.hasOwnProperty(m)) {
- if (m === "#text") {
- xml += v[m];
- }
- else if (m === "#cdata") {
- xml += "<![CDATA[" + v[m] + "]]>";
- }
- else if (m.charAt(0) !== "@") {
- xml += toXml(v[m], m, ind+"\t");
- }
- }
- xml += (xml.charAt(xml.length - 1) === "\n" ? ind : "") + "</" + name + ">";
- }
- }
- else if (typeof(v) === "function") {
- xml += ind + "<" + name + ">" + "<![CDATA[" + v + "]]>" + "</" + name + ">";
- }
- else {
- if (v === undefined ) { v = ""; }
- if (v.toString() === "\"\"" || v.toString().length === 0) {
- xml += ind + "<" + name + ">__EMPTY_STRING_</" + name + ">";
- }
- else {
- xml += ind + "<" + name + ">" + v.toString() + "</" + name + ">";
- }
- }
- return xml;
- };
- var xml = "";
- var m;
- for (m in o) if (o.hasOwnProperty(m)) {
- xml += toXml(o[m], m, "");
- }
- return tab ? xml.replace(/\t/g, tab) : xml.replace(/\t|\n/g, "");
- },
- // Internal methods
- toObj: function(xml) {
- var o = {};
- var FuncTest = /function/i;
- if (xml.nodeType === 1) {
- // element node ..
- if (xml.attributes.length) {
- // element with attributes ..
- var i;
- for (i = 0; i < xml.attributes.length; i += 1) {
- o["@" + xml.attributes[i].nodeName] = (xml.attributes[i].nodeValue || "").toString();
- }
- }
- if (xml.firstChild) {
- // element has child nodes ..
- var textChild = 0, cdataChild = 0, hasElementChild = false;
- var n;
- for (n = xml.firstChild; n; n = n.nextSibling) {
- if (n.nodeType === 1) {
- hasElementChild = true;
- }
- else if (n.nodeType === 3 && n.nodeValue.match(/[^ \f\n\r\t\v]/)) {
- // non-whitespace text
- textChild += 1;
- }
- else if (n.nodeType === 4) {
- // cdata section node
- cdataChild += 1;
- }
- }
- if (hasElementChild) {
- if (textChild < 2 && cdataChild < 2) {
- // structured element with evtl. a single text or/and cdata node ..
- this.removeWhite(xml);
- for (n = xml.firstChild; n; n = n.nextSibling) {
- if (n.nodeType === 3) {
- // text node
- o["#text"] = this.escape(n.nodeValue);
- }
- else if (n.nodeType === 4) {
- // cdata node
- if (FuncTest.test(n.nodeValue)) {
- o[n.nodeName] = [o[n.nodeName], n.nodeValue];
- } else {
- o["#cdata"] = this.escape(n.nodeValue);
- }
- }
- else if (o[n.nodeName]) {
- // multiple occurence of element ..
- if (o[n.nodeName] instanceof Array) {
- o[n.nodeName][o[n.nodeName].length] = this.toObj(n);
- }
- else {
- o[n.nodeName] = [o[n.nodeName], this.toObj(n)];
- }
- }
- else {
- // first occurence of element ..
- o[n.nodeName] = this.toObj(n);
- }
- }
- }
- else {
- // mixed content
- if (!xml.attributes.length) {
- o = this.escape(this.innerXml(xml));
- }
- else {
- o["#text"] = this.escape(this.innerXml(xml));
- }
- }
- }
- else if (textChild) {
- // pure text
- if (!xml.attributes.length) {
- o = this.escape(this.innerXml(xml));
- if (o === "__EMPTY_ARRAY_") {
- o = "[]";
- } else if (o === "__EMPTY_STRING_") {
- o = "";
- }
- }
- else {
- o["#text"] = this.escape(this.innerXml(xml));
- }
- }
- else if (cdataChild) {
- // cdata
- if (cdataChild > 1) {
- o = this.escape(this.innerXml(xml));
- }
- else {
- for (n = xml.firstChild; n; n = n.nextSibling) {
- if(FuncTest.test(xml.firstChild.nodeValue)) {
- o = xml.firstChild.nodeValue;
- break;
- } else {
- o["#cdata"] = this.escape(n.nodeValue);
- }
- }
- }
- }
- }
- if (!xml.attributes.length && !xml.firstChild) {
- o = null;
- }
- }
- else if (xml.nodeType === 9) {
- // document.node
- o = this.toObj(xml.documentElement);
- }
- else {
- alert("unhandled node type: " + xml.nodeType);
- }
- return o;
- },
- toJson: function(o, name, ind, wellform) {
- if(wellform === undefined) wellform = true;
- var json = name ? ("\"" + name + "\"") : "", tab = "\t", newline = "\n";
- if(!wellform) {
- tab= ""; newline= "";
- }
-
- if (o === "[]") {
- json += (name ? ":[]" : "[]");
- }
- else if (o instanceof Array) {
- var n, i, ar=[];
- for (i = 0, n = o.length; i < n; i += 1) {
- ar[i] = this.toJson(o[i], "", ind + tab, wellform);
- }
- json += (name ? ":[" : "[") + (ar.length > 1 ? (newline + ind + tab + ar.join(","+newline + ind + tab) + newline + ind) : ar.join("")) + "]";
- }
- else if (o === null) {
- json += (name && ":") + "null";
- }
- else if (typeof(o) === "object") {
- var arr = [], m;
- for (m in o) {
- if (o.hasOwnProperty(m)) {
- arr[arr.length] = this.toJson(o[m], m, ind + tab, wellform);
- }
- }
- json += (name ? ":{" : "{") + (arr.length > 1 ? (newline + ind + tab + arr.join(","+newline + ind + tab) + newline + ind) : arr.join("")) + "}";
- }
- else if (typeof(o) === "string") {
- /*
- var objRegExp = /(^-?\d+\.?\d*$)/;
- var FuncTest = /function/i;
- var os = o.toString();
- if (objRegExp.test(os) || FuncTest.test(os) || os==="false" || os==="true") {
- // int or float
- json += (name && ":") + "\"" +os + "\"";
- }
- else {
- */
- json += (name && ":") + "\"" + o.replace(/\\/g,'\\\\').replace(/\"/g,'\\"') + "\"";
- //}
- }
- else {
- json += (name && ":") + "\"" + o.toString()+ "\"";
- }
- return json;
- },
- innerXml: function(node) {
- var s = "";
- if ("innerHTML" in node) {
- s = node.innerHTML;
- }
- else {
- var asXml = function(n) {
- var s = "", i;
- if (n.nodeType === 1) {
- s += "<" + n.nodeName;
- for (i = 0; i < n.attributes.length; i += 1) {
- s += " " + n.attributes[i].nodeName + "=\"" + (n.attributes[i].nodeValue || "").toString() + "\"";
- }
- if (n.firstChild) {
- s += ">";
- for (var c = n.firstChild; c; c = c.nextSibling) {
- s += asXml(c);
- }
- s += "</" + n.nodeName + ">";
- }
- else {
- s += "/>";
- }
- }
- else if (n.nodeType === 3) {
- s += n.nodeValue;
- }
- else if (n.nodeType === 4) {
- s += "<![CDATA[" + n.nodeValue + "]]>";
- }
- return s;
- };
- for (var c = node.firstChild; c; c = c.nextSibling) {
- s += asXml(c);
- }
- }
- return s;
- },
- escape: function(txt) {
- return txt.replace(/[\\]/g, "\\\\").replace(/[\"]/g, '\\"').replace(/[\n]/g, '\\n').replace(/[\r]/g, '\\r');
- },
- removeWhite: function(e) {
- e.normalize();
- var n;
- for (n = e.firstChild; n; ) {
- if (n.nodeType === 3) {
- // text node
- if (!n.nodeValue.match(/[^ \f\n\r\t\v]/)) {
- // pure whitespace text node
- var nxt = n.nextSibling;
- e.removeChild(n);
- n = nxt;
- }
- else {
- n = n.nextSibling;
- }
- }
- else if (n.nodeType === 1) {
- // element node
- this.removeWhite(n);
- n = n.nextSibling;
- }
- else {
- // any other node
- n = n.nextSibling;
- }
- }
- return e;
- }
-};
\ No newline at end of file
+/*
+ *
+ * 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.
+ *
+*/
+
+/*
+ The below work is licensed under Creative Commons GNU LGPL License.
+
+ Original work:
+
+ License: http://creativecommons.org/licenses/LGPL/2.1/
+ Author: Stefan Goessner/2006
+ Web: http://goessner.net/
+
+ Modifications made:
+
+ Version: 0.9-p5
+ Description: Restructured code, JSLint validated (no strict whitespaces),
+ added handling of empty arrays, empty strings, and int/floats values.
+ Author: Michael Schøler/2008-01-29
+ Web: http://michael.hinnerup.net/blog/2008/01/26/converting-json-to-xml-and-xml-to-json/
+
+ Description: json2xml added support to convert functions as CDATA
+ so it will be easy to write characters that cause some problems when convert
+ Author: Tony Tomov
+*/
+
+/*global alert */
+var xmlJsonClass = {
+ // Param "xml": Element or document DOM node.
+ // Param "tab": Tab or indent string for pretty output formatting omit or use empty string "" to supress.
+ // Returns: JSON string
+ xml2json: function(xml, tab) {
+ if (xml.nodeType === 9) {
+ // document node
+ xml = xml.documentElement;
+ }
+ var nws = this.removeWhite(xml);
+ var obj = this.toObj(nws);
+ var json = this.toJson(obj, xml.nodeName, "\t");
+ return "{\n" + tab + (tab ? json.replace(/\t/g, tab) : json.replace(/\t|\n/g, "")) + "\n}";
+ },
+
+ // Param "o": JavaScript object
+ // Param "tab": tab or indent string for pretty output formatting omit or use empty string "" to supress.
+ // Returns: XML string
+ json2xml: function(o, tab) {
+ var toXml = function(v, name, ind) {
+ var xml = "";
+ var i, n;
+ if (v instanceof Array) {
+ if (v.length === 0) {
+ xml += ind + "<"+name+">__EMPTY_ARRAY_</"+name+">\n";
+ }
+ else {
+ for (i = 0, n = v.length; i < n; i += 1) {
+ var sXml = ind + toXml(v[i], name, ind+"\t") + "\n";
+ xml += sXml;
+ }
+ }
+ }
+ else if (typeof(v) === "object") {
+ var hasChild = false;
+ xml += ind + "<" + name;
+ var m;
+ for (m in v) if (v.hasOwnProperty(m)) {
+ if (m.charAt(0) === "@") {
+ xml += " " + m.substr(1) + "=\"" + v[m].toString() + "\"";
+ }
+ else {
+ hasChild = true;
+ }
+ }
+ xml += hasChild ? ">" : "/>";
+ if (hasChild) {
+ for (m in v) if (v.hasOwnProperty(m)) {
+ if (m === "#text") {
+ xml += v[m];
+ }
+ else if (m === "#cdata") {
+ xml += "<![CDATA[" + v[m] + "]]>";
+ }
+ else if (m.charAt(0) !== "@") {
+ xml += toXml(v[m], m, ind+"\t");
+ }
+ }
+ xml += (xml.charAt(xml.length - 1) === "\n" ? ind : "") + "</" + name + ">";
+ }
+ }
+ else if (typeof(v) === "function") {
+ xml += ind + "<" + name + ">" + "<![CDATA[" + v + "]]>" + "</" + name + ">";
+ }
+ else {
+ if (v === undefined ) { v = ""; }
+ if (v.toString() === "\"\"" || v.toString().length === 0) {
+ xml += ind + "<" + name + ">__EMPTY_STRING_</" + name + ">";
+ }
+ else {
+ xml += ind + "<" + name + ">" + v.toString() + "</" + name + ">";
+ }
+ }
+ return xml;
+ };
+ var xml = "";
+ var m;
+ for (m in o) if (o.hasOwnProperty(m)) {
+ xml += toXml(o[m], m, "");
+ }
+ return tab ? xml.replace(/\t/g, tab) : xml.replace(/\t|\n/g, "");
+ },
+ // Internal methods
+ toObj: function(xml) {
+ var o = {};
+ var FuncTest = /function/i;
+ if (xml.nodeType === 1) {
+ // element node ..
+ if (xml.attributes.length) {
+ // element with attributes ..
+ var i;
+ for (i = 0; i < xml.attributes.length; i += 1) {
+ o["@" + xml.attributes[i].nodeName] = (xml.attributes[i].nodeValue || "").toString();
+ }
+ }
+ if (xml.firstChild) {
+ // element has child nodes ..
+ var textChild = 0, cdataChild = 0, hasElementChild = false;
+ var n;
+ for (n = xml.firstChild; n; n = n.nextSibling) {
+ if (n.nodeType === 1) {
+ hasElementChild = true;
+ }
+ else if (n.nodeType === 3 && n.nodeValue.match(/[^ \f\n\r\t\v]/)) {
+ // non-whitespace text
+ textChild += 1;
+ }
+ else if (n.nodeType === 4) {
+ // cdata section node
+ cdataChild += 1;
+ }
+ }
+ if (hasElementChild) {
+ if (textChild < 2 && cdataChild < 2) {
+ // structured element with evtl. a single text or/and cdata node ..
+ this.removeWhite(xml);
+ for (n = xml.firstChild; n; n = n.nextSibling) {
+ if (n.nodeType === 3) {
+ // text node
+ o["#text"] = this.escape(n.nodeValue);
+ }
+ else if (n.nodeType === 4) {
+ // cdata node
+ if (FuncTest.test(n.nodeValue)) {
+ o[n.nodeName] = [o[n.nodeName], n.nodeValue];
+ } else {
+ o["#cdata"] = this.escape(n.nodeValue);
+ }
+ }
+ else if (o[n.nodeName]) {
+ // multiple occurence of element ..
+ if (o[n.nodeName] instanceof Array) {
+ o[n.nodeName][o[n.nodeName].length] = this.toObj(n);
+ }
+ else {
+ o[n.nodeName] = [o[n.nodeName], this.toObj(n)];
+ }
+ }
+ else {
+ // first occurence of element ..
+ o[n.nodeName] = this.toObj(n);
+ }
+ }
+ }
+ else {
+ // mixed content
+ if (!xml.attributes.length) {
+ o = this.escape(this.innerXml(xml));
+ }
+ else {
+ o["#text"] = this.escape(this.innerXml(xml));
+ }
+ }
+ }
+ else if (textChild) {
+ // pure text
+ if (!xml.attributes.length) {
+ o = this.escape(this.innerXml(xml));
+ if (o === "__EMPTY_ARRAY_") {
+ o = "[]";
+ } else if (o === "__EMPTY_STRING_") {
+ o = "";
+ }
+ }
+ else {
+ o["#text"] = this.escape(this.innerXml(xml));
+ }
+ }
+ else if (cdataChild) {
+ // cdata
+ if (cdataChild > 1) {
+ o = this.escape(this.innerXml(xml));
+ }
+ else {
+ for (n = xml.firstChild; n; n = n.nextSibling) {
+ if(FuncTest.test(xml.firstChild.nodeValue)) {
+ o = xml.firstChild.nodeValue;
+ break;
+ } else {
+ o["#cdata"] = this.escape(n.nodeValue);
+ }
+ }
+ }
+ }
+ }
+ if (!xml.attributes.length && !xml.firstChild) {
+ o = null;
+ }
+ }
+ else if (xml.nodeType === 9) {
+ // document.node
+ o = this.toObj(xml.documentElement);
+ }
+ else {
+ alert("unhandled node type: " + xml.nodeType);
+ }
+ return o;
+ },
+ toJson: function(o, name, ind, wellform) {
+ if(wellform === undefined) wellform = true;
+ var json = name ? ("\"" + name + "\"") : "", tab = "\t", newline = "\n";
+ if(!wellform) {
+ tab= ""; newline= "";
+ }
+
+ if (o === "[]") {
+ json += (name ? ":[]" : "[]");
+ }
+ else if (o instanceof Array) {
+ var n, i, ar=[];
+ for (i = 0, n = o.length; i < n; i += 1) {
+ ar[i] = this.toJson(o[i], "", ind + tab, wellform);
+ }
+ json += (name ? ":[" : "[") + (ar.length > 1 ? (newline + ind + tab + ar.join(","+newline + ind + tab) + newline + ind) : ar.join("")) + "]";
+ }
+ else if (o === null) {
+ json += (name && ":") + "null";
+ }
+ else if (typeof(o) === "object") {
+ var arr = [], m;
+ for (m in o) {
+ if (o.hasOwnProperty(m)) {
+ arr[arr.length] = this.toJson(o[m], m, ind + tab, wellform);
+ }
+ }
+ json += (name ? ":{" : "{") + (arr.length > 1 ? (newline + ind + tab + arr.join(","+newline + ind + tab) + newline + ind) : arr.join("")) + "}";
+ }
+ else if (typeof(o) === "string") {
+ /*
+ var objRegExp = /(^-?\d+\.?\d*$)/;
+ var FuncTest = /function/i;
+ var os = o.toString();
+ if (objRegExp.test(os) || FuncTest.test(os) || os==="false" || os==="true") {
+ // int or float
+ json += (name && ":") + "\"" +os + "\"";
+ }
+ else {
+ */
+ json += (name && ":") + "\"" + o.replace(/\\/g,'\\\\').replace(/\"/g,'\\"') + "\"";
+ //}
+ }
+ else {
+ json += (name && ":") + "\"" + o.toString()+ "\"";
+ }
+ return json;
+ },
+ innerXml: function(node) {
+ var s = "";
+ if ("innerHTML" in node) {
+ s = node.innerHTML;
+ }
+ else {
+ var asXml = function(n) {
+ var s = "", i;
+ if (n.nodeType === 1) {
+ s += "<" + n.nodeName;
+ for (i = 0; i < n.attributes.length; i += 1) {
+ s += " " + n.attributes[i].nodeName + "=\"" + (n.attributes[i].nodeValue || "").toString() + "\"";
+ }
+ if (n.firstChild) {
+ s += ">";
+ for (var c = n.firstChild; c; c = c.nextSibling) {
+ s += asXml(c);
+ }
+ s += "</" + n.nodeName + ">";
+ }
+ else {
+ s += "/>";
+ }
+ }
+ else if (n.nodeType === 3) {
+ s += n.nodeValue;
+ }
+ else if (n.nodeType === 4) {
+ s += "<![CDATA[" + n.nodeValue + "]]>";
+ }
+ return s;
+ };
+ for (var c = node.firstChild; c; c = c.nextSibling) {
+ s += asXml(c);
+ }
+ }
+ return s;
+ },
+ escape: function(txt) {
+ return txt.replace(/[\\]/g, "\\\\").replace(/[\"]/g, '\\"').replace(/[\n]/g, '\\n').replace(/[\r]/g, '\\r');
+ },
+ removeWhite: function(e) {
+ e.normalize();
+ var n;
+ for (n = e.firstChild; n; ) {
+ if (n.nodeType === 3) {
+ // text node
+ if (!n.nodeValue.match(/[^ \f\n\r\t\v]/)) {
+ // pure whitespace text node
+ var nxt = n.nextSibling;
+ e.removeChild(n);
+ n = nxt;
+ }
+ else {
+ n = n.nextSibling;
+ }
+ }
+ else if (n.nodeType === 1) {
+ // element node
+ this.removeWhite(n);
+ n = n.nextSibling;
+ }
+ else {
+ // any other node
+ n = n.nextSibling;
+ }
+ }
+ return e;
+ }
+};
Modified: incubator/ambari/trunk/mon_dashboard/src/ui/libs/jqgrid/src/css/ellipsis-xbl.xml
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/mon_dashboard/src/ui/libs/jqgrid/src/css/ellipsis-xbl.xml?rev=1356336&r1=1356335&r2=1356336&view=diff
==============================================================================
--- incubator/ambari/trunk/mon_dashboard/src/ui/libs/jqgrid/src/css/ellipsis-xbl.xml (original)
+++ incubator/ambari/trunk/mon_dashboard/src/ui/libs/jqgrid/src/css/ellipsis-xbl.xml Mon Jul 2 16:45:55 2012
@@ -1,13 +1,34 @@
-<?xml version="1.0"?>
-<bindings
- xmlns="http://www.mozilla.org/xbl"
- xmlns:xbl="http://www.mozilla.org/xbl"
- xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
- <binding id="ellipsis">
- <content>
- <xul:window><!-- xul:window tag required for FF2 -->
- <xul:description crop="end" xbl:inherits="value=xbl:text"><children/></xul:description>
- </xul:window>
- </content>
- </binding>
-</bindings>
+<?xml version="1.0"?>
+<!--
+
+ 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.
+
+-->
+
+<bindings
+ xmlns="http://www.mozilla.org/xbl"
+ xmlns:xbl="http://www.mozilla.org/xbl"
+ xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+ <binding id="ellipsis">
+ <content>
+ <xul:window><!-- xul:window tag required for FF2 -->
+ <xul:description crop="end" xbl:inherits="value=xbl:text"><children/></xul:description>
+ </xul:window>
+ </content>
+ </binding>
+</bindings>