admin.js 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. "use strict";
  2. // Copyright 2012 United States Government, as represented by the Secretary of Defense, Under
  3. // Secretary of Defense (Personnel & Readiness).
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
  6. // in compliance with the License. You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software distributed under the License
  11. // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
  12. // or implied. See the License for the specific language governing permissions and limitations under
  13. // the License.
  14. /// vwf/admin
  15. /// module to provide outside of an application context functionality
  16. ///
  17. ///
  18. /// @module vwf/admin
  19. /// @requires rsvp
  20. define( [ "rsvp" ] , function( rsvp ) {
  21. // Helper function that takes the URL from the browser and attempts to generate
  22. // the application path and instance ID that are in use.
  23. function getPathInformation( ) {
  24. var result = {}
  25. result[ "applicationPath" ] = undefined;
  26. result[ "instanceID" ] = undefined;
  27. var app = window.location.pathname;
  28. var pathSplit = app.split( '/' );
  29. if ( pathSplit[ 0 ] == "" ) {
  30. pathSplit.shift( );
  31. }
  32. if ( pathSplit[ pathSplit.length - 1 ] == "" ) {
  33. pathSplit.pop( );
  34. }
  35. if ( ( pathSplit.length > 0 ) && ( pathSplit[ pathSplit.length - 1 ].length == 16 ) ) {
  36. result[ "instanceID" ] = pathSplit.pop( );
  37. }
  38. if ( pathSplit.length > 0 ) {
  39. result[ "applicationPath" ] = "/" + pathSplit.join("/") + "/";
  40. }
  41. else {
  42. result[ "applicationPath" ] = "/";
  43. }
  44. return result;
  45. };
  46. var exports = {
  47. // getSaveStates: Returns all save states that have been saved for this particular instance.
  48. // Implemented via a jQuery getJSON call with an interface derived from the rsvp Promise implementation.
  49. getSaveStates: function( ) {
  50. var pathInformation = getPathInformation( );
  51. var promise = new require( 'rsvp' ).Promise( function( resolve, reject ) {
  52. if ( pathInformation[ "instanceID" ] ) {
  53. var requestURL = pathInformation[ "applicationPath" ] + pathInformation[ "instanceID" ] + "/saves";
  54. $.getJSON( requestURL ).done( function( data ) {
  55. resolve( data );
  56. } ).fail( function( jqxhr, textStatus, error) {
  57. reject( { "error": error } );
  58. } );
  59. }
  60. else {
  61. reject( { "error": "getSaveStates could not identify current instance to get save states from" } );
  62. }
  63. } );
  64. return promise;
  65. },
  66. application: {
  67. // application.getSaveStates: Returns all save states that have been saved for this application, across all instances
  68. // Implemented via a jQuery getJSON call with an interface derived from the rsvp Promise implementation.
  69. getSaveStates: function( ) {
  70. var pathInformation = getPathInformation( );
  71. var promise = new require( 'rsvp' ).Promise( function( resolve, reject ) {
  72. var requestURL = pathInformation[ "applicationPath" ] + "saves";
  73. $.getJSON( requestURL ).done( function( data ) {
  74. resolve( data );
  75. } ).fail( function( jqxhr, textStatus, error) {
  76. reject( { "error": error } );
  77. } );
  78. } );
  79. return promise;
  80. }
  81. }
  82. };
  83. return exports;
  84. } );