R33952 - in /trunk/phpgwapi/js/egw_action: egw_action.js egw_action_popup.js test/test_action.html

Author: igel457
New Revision: 33952

URL: http://www.egroupware.org/viewvc/egroupware?rev=33952&view=rev
Log:
Added toggleSelectAll functions, improved egw_action_popup, tested, fixed some bugs

Modified:
trunk/phpgwapi/js/egw_action/egw_action.js
trunk/phpgwapi/js/egw_action/egw_action_popup.js
trunk/phpgwapi/js/egw_action/test/test_action.html

Modified: trunk/phpgwapi/js/egw_action/egw_action.js
URL: http://www.egroupware.org/viewvc/egroupware/trunk/phpgwapi/js/egw_action/egw_action.js?rev=33952&r1=33951&r2=33952&view=diff

— trunk/phpgwapi/js/egw_action/egw_action.js (original)
+++ trunk/phpgwapi/js/egw_action/egw_action.js Sat Feb 26 21:40:27 2011
@@ -552,6 +552,45 @@
}

/**

    • Returns whether all objects in this tree are selected
  • */
    +egwActionObject.prototype.getAllSelected = function()
    +{
  • if (this.getSelected())
  • {
  •   for (var i = 0; i < this.children.length; i++)
    
  •   {
    
  •   	if (!this.children[i].getAllSelected())
    
  •   		return false;
    
  •   }
    
  •   return true;
    
  • }
  • return false;
    +}

+/**

    • Toggles the selection of all objects.
    • @param _select boolean specifies whether the objects should get selected or not.
    • If this parameter is not supplied, the selection will be toggled.
      
  • */
    +egwActionObject.prototype.toggleAllSelected = function(_select)
    +{
  • if (typeof _select == “undefined”)
  • {
  •   _select = !this.getAllSelected();
    
  • }
  • this.setSelected(_select);
  • for (var i = 0; i < this.children.length; i++)
  • {
  •   this.children[i].toggleAllSelected(_select);
    
  • }
    +}

+/**

  • Creates a list which contains all items of the element tree.
  • @param object _obj is used internally to pass references to the array inside
    @@ -856,6 +895,9 @@
    }
    }

+/**

    • Registers the action implementations inside the DOM-Tree.
  • */
    egwActionObject.prototype.registerActions = function()
    {
    var groups = this.getActionImplementationGroups();
    @@ -876,6 +918,9 @@
    }
    }

+/**

    • Calls the onBeforeTrigger function - if it is set - or returns false.
  • */
    egwActionObject.prototype.triggerCallback = function()
    {
    if (this.onBeforeTrigger)
    @@ -885,6 +930,15 @@
    return true;
    }

+/**

    • Executes the action implementation which is associated to the given action type.
    • @param object _implContext is data which should be delivered to the action implementation.
    • E.g. in case of the popup action implementation, the x and y coordinates where the
      
    • menu should open are transmitted.
      
    • @param string _implType is the action type for which the implementation should be
    • executed.
      
  • */
    egwActionObject.prototype.executeActionImplementation = function(_implContext, _implType)
    {
    if (typeof _implType == “string”)
    @@ -892,45 +946,55 @@

    if (typeof _implType == “object” && _implType)
    {

  •   var selectedActions = this.getSelectedLinks(_implType.type, true);
    
  •   this.forceSelection();
    
  •   var selectedActions = this.getSelectedLinks(_implType.type);
      if (selectedActions.selected.length > 0 && egwObjectLength(selectedActions.links) > 0)
      {
    
  •   	_implType.executeImplementation(_implContext,
    
  •   	return _implType.executeImplementation(_implContext,
      		selectedActions.selected, selectedActions.links);
      }
    
    }
    -}

-/**

    • Returns all selected objects, which returned true in their triggerCallback and
    • all action links of those objects, which are of the given implementation type,
    • wheras actionLink properties such as “enabled” and “visible” are accumuleted.
  • */
    -egwActionObject.prototype.getSelectedLinks = function(_implType, _includeThis)
  • return false;
    +}

+/**

    • Forces the object to be inside the currently selected objects. If this is
    • not the case, the object will select itself and deselect all other objects.
  • */
    +egwActionObject.prototype.forceSelection = function()
    +{
  • var selected = this.getSelectedObjects();
  • // Check whether this object is in the list
  • var thisInList = selected.indexOf(this) != -1;
  • // If not, select it
  • if (!thisInList)
  • {
  •   this.setSelected(true);
    
  •   this._ifaceCallback(egwSetBit(this.getState(), EGW_AO_STATE_SELECTED, true),
    
  •   	EGW_AO_SHIFT_STATE_NONE);
    
  •   selected = [this];
    
  • }
    +}

+/**

    • Returns all selected objects, and all action links of those objects, which are
    • of the given implementation type, wheras actionLink properties such as
    • “enabled” and “visible” are accumulated.
    • Objects have the chance to change their action links or to deselect themselves
    • in the onBeforeTrigger event, which is evaluated by the triggerCallback function.
    • @param _actionType is the action type for which the actionLinks should be collected.
    • @returns object An object which contains a “links” and a “selected” section with
    • an array of links/selected objects-
      
  • */
    +egwActionObject.prototype.getSelectedLinks = function(_actionType)
    {
    // Get all objects in this container which are currently selected
    var selected = this.getSelectedObjects();
  • if (_includeThis)

  • {

  •   var thisInList = false;
    
  •   for (var i = 0; i < selected.length; i++)
    
  •   {
    
  •   	if (selected[i] == this)
    
  •   	{
    
  •   		thisInList = true;
    
  •   		break;
    
  •   	}
    
  •   }
    
  •   if (!thisInList)
    
  •   {
    
  •   	this.setSelected(true);
    
  •   	this._ifaceCallback(egwSetBit(this.getState(), EGW_AO_STATE_SELECTED, true),
    
  •   		EGW_AO_SHIFT_STATE_NONE);
    
  •   	selected = [this];
    
  •   }
    
  • }

    var actionLinks = {};
    var testedSelected = [];
    @@ -946,20 +1010,22 @@
    var olink = obj.actionLinks[j]; //object link

    		// Test whether the action type is of the given implementation type
    
  •   		if (olink.actionObj.type == _implType)
    
  •   		if (olink.actionObj.type == _actionType)
      		{
      			if (typeof actionLinks[olink.actionId] == "undefined")
      			{
      				actionLinks[olink.actionId] = {
      					"actionObj": olink.actionObj,
    
  •   					"enabled": i == 0 && (olink.actionObj.allowOnMultiple || selected.length == 1),
    
  •   					"enabled": (testedSelected.length == 1),
      					"visible": false,
      					"cnt": 0
      				}
      			}
    
  •   			// Accumulate the action link properties
      			var llink = actionLinks[olink.actionId];
    
  •   			llink.enabled = llink.enabled && olink.enabled && olink.visible;
    
  •   			llink.enabled = llink.enabled && olink.enabled &&
    
  •   				olink.visible;
      			llink.visible = llink.visible || olink.visible;
      			llink.cnt++;
      		}
    

@@ -967,11 +1033,14 @@
}
}

  • // Check whether all objects supported the action
    for (k in actionLinks)
    {
  •   actionLinks[k].enabled = actionLinks[k].enabled && (actionLinks[k].cnt >= selected.length);
    
  • }
  •   actionLinks[k].enabled = actionLinks[k].enabled &&
    
  •   	(actionLinks[k].cnt >= testedSelected.length) &&
    
  •   	(actionLinks[k].actionObj.allowOnMultiple || 
    
  •   	 actionLinks[k].cnt == 1);
    
  • }

    // Return an object which contains the accumulated actionLinks and all selected
    // objects.
    @@ -1150,7 +1219,12 @@
    */
    function egwActionObjectManager(_id, _manager)
    {

  • return new egwActionObject(_id, null, new egwActionObjectInterface(),
  • var ao = new egwActionObject(_id, null, new egwActionObjectInterface(),
    _manager, EGW_AO_FLAG_IS_CONTAINER);
    -}
  • // The object manager doesn’t allow selections and cannot perform actions
  • ao.triggerCallback = function() {return false;};
  • return ao;
    +}

Modified: trunk/phpgwapi/js/egw_action/egw_action_popup.js
URL: http://www.egroupware.org/viewvc/egroupware/trunk/phpgwapi/js/egw_action/egw_action_popup.js?rev=33952&r1=33951&r2=33952&view=diff

— trunk/phpgwapi/js/egw_action/egw_action_popup.js (original)
+++ trunk/phpgwapi/js/egw_action/egw_action_popup.js Sat Feb 26 21:40:27 2011
@@ -58,17 +58,6 @@

ai.type = "popup";
  • ai.getPageXY = function getPageXY(event)
  • {
  •   // document.body.scrollTop does not work in IE
    
  •   var scrollTop = document.body.scrollTop ? document.body.scrollTop :
    
  •   	document.documentElement.scrollTop;
    
  •   var scrollLeft = document.body.scrollLeft ? document.body.scrollLeft :
    
  •   	document.documentElement.scrollLeft;
    
  •   return {'x': (event.clientX + scrollLeft), 'y': (event.clientY + scrollTop)};
    
  • }
  • ai.doRegisterAction = function(_aoi, _callback, _context)
    {
    var node = _aoi.getDOMNode();
    @@ -78,7 +67,9 @@
    node.oncontextmenu = function(e) {
    //Obtain the event object
    if (!e)
  •   		{
      			e = window.event;
    
  •   		}
    
      		if (_egw_active_menu)
      		{
    

@@ -86,13 +77,15 @@
}
else
{

  •   			_xy = ai.getPageXY(e);
    
  •   			_xy = ai._getPageXY(e);
      			_callback.call(_context, _xy, ai);
      		}
    
      		e.cancelBubble = true;
      		if (e.stopPropagation)
    
  •   		{
      			e.stopPropagation();
    
  •   		}
      		return false;
      	}
      }
    

@@ -103,12 +96,34 @@
//
}

  • /**
    • Builds the context menu and shows it at the given position/DOM-Node.
  • */
    ai.doExecuteImplementation = function(_context, _selected, _links)
    {
  •   //Check whether the 
    
  •   if ((typeof _context.posx != "number" || typeof _context.posy != "number") &&
    
  •       typeof _context.id != "undefined")
    
  •   {
    
  •   	// Calculate context menu position from the given DOM-Node
    
  •   	var node = _context;
    
  •   	x = node.offsetLeft;
    
  •   	y = node.offsetTop;
    
  •   	_context = {"posx": x, "posy": y}
    
  •   }
    
  •   var menu = ai._buildMenu(_links, _selected);
    
  •   menu.showAt(_context.x, _context.y);
    
  • }
  •   menu.showAt(_context.posx, _context.posy);
    
  •   return true;
    
  • }

  • /**

    • Builds the context menu from the given action links
  • */
    ai._buildMenu = function(_links, _selected)
    {
    var menu = new egwMenu();
    @@ -187,6 +202,17 @@
    return menu;
    }

  • ai._getPageXY = function getPageXY(event)

  • {

  •   // document.body.scrollTop does not work in IE
    
  •   var scrollTop = document.body.scrollTop ? document.body.scrollTop :
    
  •   	document.documentElement.scrollTop;
    
  •   var scrollLeft = document.body.scrollLeft ? document.body.scrollLeft :
    
  •   	document.documentElement.scrollLeft;
    
  •   return {'posx': (event.clientX + scrollLeft), 'posy': (event.clientY + scrollTop)};
    
  • }

  • return ai;
    }

Modified: trunk/phpgwapi/js/egw_action/test/test_action.html
URL: http://www.egroupware.org/viewvc/egroupware/trunk/phpgwapi/js/egw_action/test/test_action.html?rev=33952&r1=33951&r2=33952&view=diff

— trunk/phpgwapi/js/egw_action/test/test_action.html (original)
+++ trunk/phpgwapi/js/egw_action/test/test_action.html Sat Feb 26 21:40:27 2011
@@ -5,6 +5,9 @@



+

  •   <!-- JQuery is just used in this example. The egw_action scripts do not
    
  •        need JQuery! -->
      <script src="js/jquery.js"></script>
    
      <!-- Popup stuff -->
    

@@ -64,6 +67,7 @@

File 4
File 5
  •   <button id="performAction">Perform action...</button><button id="selectAll">Select All</button>
      <script>
      	var actionManager = null;
      	var objectManager = null;
    

@@ -256,7 +260,17 @@
obj.updateActionLinks(listboxFolderLinks);

				obj.registerActions();
  •   		})
    
  •   		});
    
  •   		$("#selectAll").click(function() {
    
  •   			objectManager.toggleAllSelected();
    
  •   		});
    
  •   		$("#performAction").click(function(e) {
    
  •   			if (!objectManager.executeActionImplementation(this, "popup"))
    
  •   				alert("Please select one or more objects.");
    
  •   			return false;
    
  •   		});
      	}
      </script>
    

Free Software Download: Index, Search & Analyze Logs and other IT data in
Real-Time with Splunk. Collect, index and harness all the fast moving IT data
generated by your applications, servers and devices whether physical, virtual
or in the cloud. Deliver compliance at lower cost and gain new business
insights. http://p.sf.net/sfu/splunk-dev2dev


eGroupWare-cvs mailing list
eGroupWare-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/egroupware-cvs