如何使用 Google Apps Script 中的 javascript 从模态对话框模板更新侧边栏模板中的 html? [英] How to update html in sidebar template from modal dialog template with javascript in Google Apps Script?

查看:18
本文介绍了如何使用 Google Apps Script 中的 javascript 从模态对话框模板更新侧边栏模板中的 html?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在模态对话框中有一个表单.提交表单后,该对话框将关闭并在后台执行一些操作.关闭模式对话框后,我还想更新侧边栏中的 html(不刷新侧边栏).我在侧边栏中有一个带有加载程序"ID 的 div,其中隐藏了类(防止它可见).在模式对话框关闭时,我想删除隐藏在加载程序"div 中的类.我如何从模态对话框模板访问加载器"div?

I have a form in a modal dialog. After submiting a form that dialog closes and does some actions in the background. After closing the modal dialog I also want to update html in the sidebar (without refreshing the sidebar). I have a div with "loader" id in the sidebar with class hidden (which prevents it to be visible). On modal dialog close I want to remove class hidden from the "loader" div. How do I access that "loader" div from the modal dialog template?

推荐答案

您可以使用浏览器 sessionStorage,设置计时器,并不断轮询"可用信息.

You could use the browser sessionStorage, set a timer, and continuously "poll" for available information.

感谢评论,提出了一种无需投票的变体:

Thanks to a comment, a variation was suggested which eliminates the need for polling:

$(window).bind('storage',
  function(e){if(e.key === "newValuesWereEntered"){doSomething()}});

脚本标签:

<script>
  //Use a timer to keep checking for a completed action from another dialog
  var theTimer;

  window.setTheTimer = function() {
    //To Do - Hide the Spinner
    if (typeof(Storage) === "undefined") {
      alert('HTML5 Storage is not supported.  This App will not work in this browser.  Please update your browser.');
      return;
    }

    try {
    window.sessionStorage.setItem("newValuesWereEntered","n"); //Make sure check value is reset
    } catch(e) {
      alert(e.error + ' You may have this apps cookies blocked in this browser, and/or this browser tab.  Check cookie blocking.');
      return;
    };
    theTimer = window.setInterval(monitorForTheResponse, 500); //Every 1/2 second, check for response value
  };

  window.monitorForTheResponse = function() {
    var was_a_newValueEntered,dlgInfo;
    was_a_newValueEntered = window.sessionStorage.getItem("newValuesWereEntered");
    if (was_a_newValueEntered === 'y') {//Dialog just wrote value to window.sessionStorage
      window.sessionStorage.setItem("newValuesWereEntered","n");//Reset
      clearTimeout(theTimer);//turn off timer
      //Get submitted values
      dlgInfo = window.sessionStorage.getItem("newValuesToTransfer");

      //To Do - Run code to display new value
    };
  };
</script>

具有传递给侧边栏的值的对话框必须将该值保存到会话存储中

The dialog that has the value to pass to the sidebar must save that value to session storage

window.theValueWasSavedOrEntered = function() {
  var arry,objectOfNewValues,strJSON;
  try{
  if (typeof(Storage) !== "undefined") {//Browser has local storage      
    window.sessionStorage.setItem("newValuesWereEntered","y"); //Set to yes      
    objectOfNewValues = {};

    objectOfNewValues.valueOne = arry[0];
    objectOfNewValues.valueTwo = arry[1];

    strJSON = JSON.stringify(objectOfNewValues);
    window.sessionStorage.setItem("newValuesWereEntered","y"); //Set to yes
    window.sessionStorage.setItem("newValuesToTransfer", strJSON);
  };

  google.script.host.close();
  } catch(e) {
    SendErr({'message':'ERROR: ' + e.stack + ' message: ' + e.message});
  };
};

这篇关于如何使用 Google Apps Script 中的 javascript 从模态对话框模板更新侧边栏模板中的 html?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆