document.js 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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/view/document extends a view interface up to the browser document. When vwf/view/document
  15. /// is active, scripts on the main page may make (reflected) kernel calls:
  16. ///
  17. /// window.vwf_view.kernel.createChild( nodeID, childName, childComponent, childURI, function( childID ) {
  18. /// ...
  19. /// } );
  20. ///
  21. /// And receive view calls:
  22. ///
  23. /// window.vwf_view.createdNode = function( nodeID, childID, childExtendsID, childImplementsIDs,
  24. /// childSource, childType, childIndex, childName, callback /- ( ready ) -/ ) {
  25. /// ...
  26. /// }
  27. ///
  28. /// @module vwf/view/document
  29. /// @requires vwf/view
  30. define( [ "module", "vwf/view", "vwf/utility", "jquery" ], function( module, view, utility, jQuery ) {
  31. return view.load( module, {
  32. // == Module Definition ====================================================================
  33. initialize: function() {
  34. window.vwf_view = this;
  35. },
  36. // == Model API ============================================================================
  37. createdNode: function( nodeID, childID, childExtendsID, childImplementsIDs,
  38. childSource, childType, childURI, childName, callback /* ( ready ) */ ) {
  39. var self = this;
  40. // At the root node of the application, load the UI chrome if available.
  41. if ( childID == this.kernel.application() &&
  42. ( window.location.protocol == "http:" || window.location.protocol == "https:" ) ) {
  43. // Suspend the queue.
  44. callback( false );
  45. // Load the file and insert it into the main page.
  46. var container = jQuery( "body" ).append( "<div />" ).children( ":last" );
  47. container.load( "admin/chrome", function( responseText, textStatus ) {
  48. // If the overlay attached a `createdNode` handler, forward this first call
  49. // since the overlay will have missed it.
  50. if ( self.createdNode !== Object.getPrototypeOf( self ).createdNode ) {
  51. self.createdNode( nodeID, childID, childExtendsID, childImplementsIDs,
  52. childSource, childType, childURI, childName );
  53. }
  54. // Remove the container div if an error occurred or if we received an empty
  55. // result. The server sends an empty document when the application doesn't
  56. // provide a chrome file.
  57. if ( ! ( textStatus == "success" || textStatus == "notmodified" ) || responseText == "" ) {
  58. container.remove();
  59. }
  60. // Resume the queue.
  61. callback( true );
  62. } );
  63. }
  64. },
  65. }, function( viewFunctionName ) {
  66. // == View API =============================================================================
  67. } );
  68. } );