Merge branch 'master' of git@github.com:plainblack/webgui

This commit is contained in:
daviddelikat 2009-10-28 09:15:34 -05:00
commit 9db3e02444
38 changed files with 898 additions and 228 deletions

View file

@ -13,7 +13,7 @@ if ( typeof WebGUI.AssetManager == "undefined" ) {
// Keep track of the open more menus
WebGUI.AssetManager.MoreMenusDisplayed = {};
WebGUI.AssetManager.CrumbMoreMenu;
WebGUI.AssetManager.CrumbMoreMenu = undefined;
// Append something to a url:
WebGUI.AssetManager.appendToUrl = function ( url, params ) {
var components = [ url ];
@ -25,15 +25,14 @@ WebGUI.AssetManager.appendToUrl = function ( url, params ) {
}
components.push(params);
return components.join('');
}
};
/*---------------------------------------------------------------------------
WebGUI.AssetManager.addHighlightToRow ( child )
Highlight the row containing this element by adding to it the "highlight"
class
*/
WebGUI.AssetManager.addHighlightToRow
= function ( child ) {
WebGUI.AssetManager.addHighlightToRow = function ( child ) {
var row = WebGUI.AssetManager.findRow( child );
if ( !YAHOO.util.Dom.hasClass( row, "highlight" ) ) {
YAHOO.util.Dom.addClass( row, "highlight" );
@ -44,16 +43,15 @@ WebGUI.AssetManager.addHighlightToRow
WebGUI.AssetManager.buildMoreMenu ( url, linkElement )
Build a WebGUI style "More" menu for the asset referred to by url
*/
WebGUI.AssetManager.buildMoreMenu
= function ( url, linkElement, isNotLocked ) {
WebGUI.AssetManager.buildMoreMenu = function ( url, linkElement, isNotLocked ) {
// Build a more menu
var rawItems = WebGUI.AssetManager.MoreMenuItems;
var menuItems = [];
var isLocked = !isNotLocked;
for ( var i = 0; i < rawItems.length; i++ ) {
var itemUrl = rawItems[i].url.match( /<url>/ )
? rawItems[i].url.replace( /<url>(?:\?(.*))?/, WebGUI.AssetManager.appendToUrl(url, "$1") )
: url + rawItems[i].url
var itemUrl = rawItems[i].url
? WebGUI.AssetManager.appendToUrl(url, rawItems[i].url)
: url
;
if (! (itemUrl.match( /func=edit;/) && isLocked )) {
menuItems.push( { "url" : itemUrl, "text" : rawItems[i].label } );
@ -63,7 +61,7 @@ WebGUI.AssetManager.buildMoreMenu
"zindex" : 1000,
"clicktohide" : true,
"position" : "dynamic",
"context" : [ linkElement, "tl", "bl" ],
"context" : [ linkElement, "tl", "bl", ["beforeShow", "windowResize"] ],
"itemdata" : menuItems
};
@ -74,8 +72,7 @@ WebGUI.AssetManager.buildMoreMenu
WebGUI.AssetManager.findRow ( child )
Find the row that contains this child element.
*/
WebGUI.AssetManager.findRow
= function ( child ) {
WebGUI.AssetManager.findRow = function ( child ) {
var node = child;
while ( node ) {
if ( node.tagName == "TR" ) {
@ -114,7 +111,7 @@ WebGUI.AssetManager.formatActions = function ( elCell, oRecord, oColumn, orderNu
var options = WebGUI.AssetManager.buildMoreMenu(oRecord.getData( 'url' ), more, oRecord.getData( 'actions' ));
var menu = new YAHOO.widget.Menu( "moreMenu" + oRecord.getData( 'assetId' ), options );
YAHOO.util.Event.onDOMReady( function () { menu.render( document.getElementById( 'assetManager' ) ) } );
YAHOO.util.Event.onDOMReady( function () { menu.render( document.getElementById( 'assetManager' ) ); } );
YAHOO.util.Event.addListener( more, "click", function (e) { YAHOO.util.Event.stopEvent(e); menu.show(); menu.focus(); }, null, menu );
};
@ -202,8 +199,9 @@ WebGUI.AssetManager.BuildQueryString = function ( state, dt ) {
WebGUI.AssetManager.formatRevisionDate = function ( elCell, oRecord, oColumn, orderNumber ) {
var revisionDate = new Date( oRecord.getData( "revisionDate" ) * 1000 );
var minutes = revisionDate.getMinutes();
if (minutes < 10)
if (minutes < 10) {
minutes = "0" + minutes;
}
elCell.innerHTML = revisionDate.getFullYear() + '-' + ( revisionDate.getMonth() + 1 )
+ '-' + revisionDate.getDate() + ' ' + ( revisionDate.getHours() )
+ ':' + minutes
@ -308,7 +306,7 @@ WebGUI.AssetManager.initDataTable = function (o) {
WebGUI.AssetManager.DataTable.handleDataReturnPayload = function(oRequest, oResponse, oPayload) {
oPayload.totalRecords = oResponse.meta.totalRecords;
return oPayload;
}
};
};

View file

@ -130,11 +130,11 @@ YAHOO.WebGUI.Form.DatePicker = {
],
NAVIGATOR: {
strings : {
'submit' : YAHOO.WebGUI.Form.DatePicker.i18n.get('WebGUI', 'submit'),
'cancel' : YAHOO.WebGUI.Form.DatePicker.i18n.get('WebGUI', 'cancel'),
'month' : YAHOO.WebGUI.Form.DatePicker.i18n.get('DateTime', 'Month'),
'year' : YAHOO.WebGUI.Form.DatePicker.i18n.get('DateTime', 'Year'),
'invalid year' : YAHOO.WebGUI.Form.DatePicker.i18n.get('Form_Date', 'Invalid year')
'submit' : YAHOO.WebGUI.Form.DatePicker.i18n.get('WebGUI', 'submit'),
'cancel' : YAHOO.WebGUI.Form.DatePicker.i18n.get('WebGUI', 'cancel'),
'month' : YAHOO.WebGUI.Form.DatePicker.i18n.get('DateTime', 'Month'),
'year' : YAHOO.WebGUI.Form.DatePicker.i18n.get('DateTime', 'Year'),
'invalidYear' : YAHOO.WebGUI.Form.DatePicker.i18n.get('Form_Date', 'Invalid year')
}
}
};

View file

@ -7,33 +7,40 @@ if (typeof WebGUI.Map == "undefined") {
}
// Keep track of all points on all maps and how to focus on them
// A hash (map) of hashes (markers)
WebGUI.Map.markers = {};
// Keep a loading dialog
WebGUI.Map.loadingDialog = undefined;
/**
* WebGUI.Map.deletePoint( map, mgr, mapUrl, marker )
* WebGUI.Map.deletePoint( map, mgr, marker )
* Delete a point from the map.
* NOTE: We assume the user has already confirmed this action
*/
WebGUI.Map.deletePoint
= function ( map, mgr, mapUrl, marker ) {
= function ( map, mgr, marker ) {
var callback = function ( text, code ) {
WebGUI.Map.hideLoading();
var response = YAHOO.lang.JSON.parse( text );
// remove the marker from the map
if ( !response.error ) {
mgr.removeMarker( marker );
delete WebGUI.Map.markers[ map.assetId ][ marker.assetId ];
}
};
GDownloadUrl( mapUrl + '?func=ajaxDeletePoint;assetId=' + marker.assetId, callback);
WebGUI.Map.showLoading();
GDownloadUrl( map.url + '?func=ajaxDeletePoint;assetId=' + marker.assetId, callback);
};
/**
* WebGUI.Map.editPoint( map, mgr, mapUrl, marker )
* WebGUI.Map.editPoint( map, mgr, marker )
* Edit a point on the map.
* up the edit box. mgr is the Marker Manager to add the marker
* to. mapUrl is the URL of the map asset
* to.
*/
WebGUI.Map.editPoint
= function ( map, mgr, mapUrl, marker ) {
= function ( map, mgr, marker ) {
var assetId = '';
if ( !marker ) {
marker = new GMarker( map.getCenter(), { draggable: true } );
@ -44,28 +51,13 @@ WebGUI.Map.editPoint
assetId = "new";
marker.assetId = "new";
GEvent.addListener( marker, "dragend", function (latlng) {
WebGUI.Map.setPointLocation( marker, latlng, mapUrl );
WebGUI.Map.setPointLocation( marker, latlng );
} );
}
else {
assetId = marker.assetId;
}
// Create a loading dialog
var loadingDialog = new YAHOO.widget.Panel("loading", { width:"240px",
fixedcenter:true,
close:false,
draggable:false,
zindex:4,
modal:true,
visible:false
}
);
loadingDialog.setHeader("Loading, please wait...");
loadingDialog.setBody('<img src="' + map.extrasUrl + '/yui-webgui/build/map/assets/loading.gif" />');
loadingDialog.render(document.body);
// Callback should open the window with the form
var callback = function (text, code) {
YAHOO.util.Dom.addClass( document.body, "yui-skin-sam" );
@ -84,7 +76,7 @@ WebGUI.Map.editPoint
var lng = marker.getLatLng().lng();
this.form.elements['latitude'].value = lat;
this.form.elements['longitude'].value = lng;
WebGUI.Map.showLoading();
this.submit();
}
@ -104,6 +96,7 @@ WebGUI.Map.editPoint
// Update marker info
var point = YAHOO.lang.JSON.parse( o.responseText );
marker.assetId = point.assetId;
marker.title = point.title;
GEvent.clearListeners( marker, "click" );
GEvent.clearListeners( marker, "infowindowbeforeclose" );
@ -125,7 +118,7 @@ WebGUI.Map.editPoint
editButton.type = "button";
editButton.value = "Edit";
GEvent.addDomListener( editButton, "click", function () {
WebGUI.Map.editPoint( map, mgr, mapUrl, marker );
WebGUI.Map.editPoint( map, mgr, marker );
} );
divButton.appendChild( editButton );
@ -134,52 +127,69 @@ WebGUI.Map.editPoint
deleteButton.value = "Delete"; // Replace with i18n
GEvent.addDomListener( deleteButton, "click", function () {
if ( confirm("Are you sure you want to delete this point?") ) {
WebGUI.Map.deletePoint( map, mgr, mapUrl, marker );
WebGUI.Map.deletePoint( map, mgr, marker );
}
} );
divButton.appendChild( deleteButton );
}
marker.bindInfoWindow( infoWin );
GEvent.addListener( marker, "dragend", function (latlng) {
WebGUI.Map.setPointLocation( marker, latlng, mapUrl );
WebGUI.Map.setPointLocation( marker, latlng );
} );
WebGUI.Map.hideLoading();
WebGUI.Map.markers[map.assetId][marker.assetId] = marker;
WebGUI.Map.updateSelectPoint( map );
}
};
// Hide the loading dialog
loadingDialog.hide();
WebGUI.Map.hideLoading();
};
// Show the loading dialog
loadingDialog.show();
WebGUI.Map.showLoading();
// Get the form
GDownloadUrl( mapUrl + '?func=ajaxEditPoint;assetId=' + assetId, callback );
GDownloadUrl( map.url + '?func=ajaxEditPoint;assetId=' + assetId, callback );
};
/**
* WebGUI.Map.focusOn( assetId )
* WebGUI.Map.focusOn( pointId )
* Pan the appropriate map to view the appropriate map point
*/
WebGUI.Map.focusOn
= function ( assetId ) {
var marker = WebGUI.Map.markers[assetId];
= function ( pointId ) {
var marker;
for ( var mapId in WebGUI.Map.markers ) {
if ( WebGUI.Map.markers[mapId][pointId] ) {
marker = WebGUI.Map.markers[mapId][pointId];
break;
}
}
if ( !marker ) return;
var map = marker.map;
var infoWin = marker.infoWin;
if ( map.getZoom() < 5 ) {
map.setZoom(6);
if ( map.getZoom() <= 4 ) {
map.setZoom(5);
}
map.panTo( marker.getLatLng() );
marker.openInfoWindow( marker.infoWin );
};
WebGUI.Map.hideLoading
= function () {
WebGUI.Map.loadingDialog.hide();
};
/**
* WebGUI.Map.preparePoints ( map, mgr, mapUrl, points )
* WebGUI.Map.preparePoints ( map, mgr, points )
* Prepare the points from WebGUI into Google Map GMarkers
*/
WebGUI.Map.preparePoints
= function ( map, mgr, mapUrl, points ) {
= function ( map, mgr, points ) {
WebGUI.Map.markers[map.assetId] = {};
// Transform points into markers
var markers = [];
for ( var i = 0; i < points.length; i++ ) (function(i){ // Create closure for callbacks
@ -190,6 +200,7 @@ WebGUI.Map.preparePoints
draggable: point.canEdit
} );
marker.assetId = point.assetId;
marker.title = point.title;
marker.map = map;
// Create info window
@ -205,7 +216,7 @@ WebGUI.Map.preparePoints
editButton.type = "button";
editButton.value = "Edit"; // Replace with i18n
GEvent.addDomListener( editButton, "click", function () {
WebGUI.Map.editPoint( map, mgr, mapUrl, marker );
WebGUI.Map.editPoint( map, mgr, marker );
} );
divButton.appendChild( editButton );
@ -214,19 +225,19 @@ WebGUI.Map.preparePoints
deleteButton.value = "Delete"; // Replace with i18n
GEvent.addDomListener( deleteButton, "click", function () {
if ( confirm("Are you sure you want to delete this point?") ) {
WebGUI.Map.deletePoint( map, mgr, mapUrl, marker );
WebGUI.Map.deletePoint( map, mgr, marker );
}
} );
divButton.appendChild( deleteButton );
infoWin.appendChild( divButton );
GEvent.addListener( marker, "dragend", function (latlng) {
WebGUI.Map.setPointLocation( marker, latlng, mapUrl );
WebGUI.Map.setPointLocation( marker, latlng );
} );
}
// Keep info
WebGUI.Map.markers[point.assetId] = marker;
WebGUI.Map.markers[map.assetId][point.assetId] = marker;
marker.bindInfoWindow( infoWin );
@ -251,25 +262,85 @@ WebGUI.Map.setCenter
;
var callback = function ( text, code ) {
// TODO: Notify the poor user
WebGUI.Map.hideLoading();
};
WebGUI.Map.showLoading();
GDownloadUrl(url,callback);
};
/**
* WebGUI.Map.setPointLocation( marker, latlng, mapUrl, assetId )
* WebGUI.Map.setPointLocation( marker, latlng )
* Update the point's location in the database.
*/
WebGUI.Map.setPointLocation
= function ( marker, latlng, mapUrl, assetId ) {
var url = mapUrl + '?func=ajaxSetPointLocation'
= function ( marker, latlng ) {
var url = marker.map.url + '?func=ajaxSetPointLocation'
+ ';assetId=' + marker.assetId
+ ';latitude=' + latlng.lat()
+ ';longitude=' + latlng.lng()
;
var callback = function ( text, code ) {
// TODO: Notify the poor user
WebGUI.Map.hideLoading();
};
WebGUI.Map.showLoading();
GDownloadUrl(url, callback);
};
WebGUI.Map.showLoading
= function () {
// Create a loading dialog
if ( !WebGUI.Map.loadingDialog ) {
var loadingDialog = new YAHOO.widget.Panel("loading", { width:"240px",
fixedcenter:true,
close:false,
draggable:false,
zindex:4,
modal:true,
visible:false
}
);
loadingDialog.setHeader("Loading, please wait...");
loadingDialog.setBody('<img src="' + getWebguiProperty('extrasURL') + '/yui-webgui/build/map/assets/loading.gif" />');
loadingDialog.render(document.body);
WebGUI.Map.loadingDialog = loadingDialog;
}
WebGUI.Map.loadingDialog.show();
};
WebGUI.Map.updateSelectPoint
= function (map) {
var select = document.getElementById( 'selectPoint_' + map.assetId );
if ( !select) {
return;
}
// Clear old points
while ( select.options.length > 1 ) {
select.length = 1;
}
var markers = WebGUI.Map.markers[map.assetId];
var sorted = [];
for ( var pointId in markers ) {
sorted.push( pointId );
}
sorted.sort( function (a,b) {
var ma = WebGUI.Map.markers[map.assetId][a];
var mb = WebGUI.Map.markers[map.assetId][b];
if ( ma.title > mb.title ) { return 1; }
else if ( ma.title < mb.title ) { return -1; }
else { return 0; }
} );
// Add new points
for ( var i = 0; i < sorted.length; i++ ) {
select.options[ select.options.length ]
= new Option( markers[sorted[i]].title, sorted[i] );
}
};