Uploaded image for project: 'Java Script UI (App and Dialog Fields)'
  1. Java Script UI (App and Dialog Fields)
  2. JSFIELD-4

Make the module agnostic to magnolia's contextPath

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Neutral Neutral
    • 1.1.7
    • 1.1.6
    • None

      Currently the JavaScript Dialog Fields module doesn't load the fieldScript

      form:
        implementationClass: info.magnolia.ui.javascript.form.FormViewWithChangeListener
        properties:
          imagesForUpload:
            $type: javascriptField
            fieldScript: /multi-assets-upload/webresources/upload.html
      

      supplied in the yaml, when magnolia runs on a contextPath different to '/' (e.g. '/magnoliaAuthor').

      Users may also encounter problems referencing their own css/js files (hosted in the modules webresources directory) as there is currently no way to inject the contextPath into the fieldScript.

      Both issues are now resolved by using info.magnolia.init.MagnoliaInitPaths.

      If users want to resolve the contextPath to load their JS/CSS, the following JavaScript could be used in the fieldScript.

          let contextPath;
      
          function loadStyle(href){
              const link = document.createElement('link');
              link.rel  = 'stylesheet';
              link.type = 'text/css';
              link.href = href;
              document.head.appendChild(link);
          }
      
          function loadScript(href){
              const script = document.createElement("script");
              script.type = "text/javascript";
              script.src = href;
              document.head.appendChild(script);
          }
      
          window.addEventListener(
              'message',
              function (event) {
                  if (event.data.action === 'contextPath') {
                      contextPath = event.data.contextPath
                      loadStyle(contextPath + "/.resources/multi-assets-upload/webresources/css/dropzone_5.min.css");
                      loadStyle(contextPath + "/VAADIN/themes/resurface-admincentral/styles.css?v=8.13.1");
                      loadScript(contextPath + "/.resources/multi-assets-upload/webresources/js/dropzone_5.9.3.min.js");
                  }
              },
              false
          );
      

       

        Acceptance criteria

              amanzoni Adrien Manzoni
              mschwarz Markus Schwarz
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: