document.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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"], function( module, view, utility) {
  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. let container = document.createElement("div");
  48. document.querySelector("body").appendChild(container);
  49. //var container = document.querySelector("body").append( "<div />" ).children( ":last" );
  50. fetch("admin/chrome", {
  51. method: 'get'
  52. }).then(function(response) {
  53. return response.text();
  54. }).catch(function(err) {
  55. container.remove();
  56. // Resume the queue.
  57. callback( true );
  58. }).then(function(responseText) {
  59. // If the overlay attached a `createdNode` handler, forward this first call
  60. // since the overlay will have missed it.
  61. if ( self.createdNode !== Object.getPrototypeOf( self ).createdNode ) {
  62. self.createdNode( nodeID, childID, childExtendsID, childImplementsIDs,
  63. childSource, childType, childURI, childName );
  64. }
  65. // Remove the container div if an error occurred or if we received an empty
  66. // result. The server sends an empty document when the application doesn't
  67. // provide a chrome file.
  68. if ( responseText == "" ) {
  69. container.remove();
  70. }
  71. // Resume the queue.
  72. callback( true );
  73. });
  74. // container.load( "admin/chrome", function( responseText, textStatus ) {
  75. // // If the overlay attached a `createdNode` handler, forward this first call
  76. // // since the overlay will have missed it.
  77. // if ( self.createdNode !== Object.getPrototypeOf( self ).createdNode ) {
  78. // self.createdNode( nodeID, childID, childExtendsID, childImplementsIDs,
  79. // childSource, childType, childURI, childName );
  80. // }
  81. // // Remove the container div if an error occurred or if we received an empty
  82. // // result. The server sends an empty document when the application doesn't
  83. // // provide a chrome file.
  84. // if ( ! ( textStatus == "success" || textStatus == "notmodified" ) || responseText == "" ) {
  85. // container.remove();
  86. // }
  87. // // Resume the queue.
  88. // callback( true );
  89. // } );
  90. }
  91. },
  92. }, function( viewFunctionName ) {
  93. // == View API =============================================================================
  94. } );
  95. } );