javascript - Sidebar functionality in google sheets: clicking a button to open a new 'page' within the sidebar -

I'm build a scheduling tool for equipment in my pany. I am running a script in Google sheets that

I'm build a scheduling tool for equipment in my pany. I am running a script in Google sheets that has a sidebar. I would like to have the user select a button (i.e., Make Reservation) which leads to another page in the sidebar where I can take in user input. I am not sure how to trigger this event with the current code I have. I have one HTML code file and one Google scripts file.

Can someone help me or lead me in the right direction here based on the code below?

HTML/CSS Code:

<!DOCTYPE html>
<html>
    <head>
        <base target="_top">
        <link rel="stylesheet" href=".css">
        <!-- The CSS package above applies Google styling to buttons and other elements. -->    
    </head>

<body>

    <center>
        <div class = "sidebar header-logo">
            <img alt="Add-on logo" class="logo"  src="img.png" width="250" height="35.75">
        </div>
    </center>
    <form>

    <style>

    .button1 {
        position: absolute;
        transition: .5s ease;
        top: 50%;
        left: 5%;   
    }

    .button2 {
        position: absolute;
        top: 0%;
        left: 115%;
    }

    .button3 {
        position: absolute;
        top: 115%;
        left: 0%;   
    }

    .button4 {
        position: absolute;
        top: 0%;
        left: -100%;   
    }

    .text {
        position: absolute;
        top: 150px;
        color: #000000;
        font-size:12pt;  
    }
    </style>

    <div class = "text" align = "center">
        <center>
            <b>What would you like to do today?</b>
        </center>
    </div>

    <div class="button1" id="button-bar">
        <form action="">
            <button class="blue" id="run-translation">Make a Reservation</button>

    <div class="button2" id="button-bar">
        <form action="">
            <button class="blue" id="run-translation">Cancel Reservation</button>

    <div class="button3" id="button-bar">
        <form action="">
            <button class="blue" id="run-translation">Request Maintenance</button>

    <div class="button4" id="button-bar">
        <form action="">
            <button class="blue" id="run-translation">Report Site Bug</button>
        </form>

    <script src="//ajax.googleapis/ajax/libs/jquery/1.9.1/jquery.min.js">
    </script>


    <script>
        window.writeData = function() {
            var formObj = document.getElementById('myForm');

            google.script.run.myServerFunctionName(formObj);
        };

        $(function() {
            $('#run-translation').click(runTranslation);
            $('#insert-text').click(insertText);
            google.script.run.withSuccessHandler(loadPreferences)
                  .withFailureHandler(showError).getPreferences();
        });

        function runTranslation() {
            var win = window.open("", '_blank');
            win.focus();
        }

    </script>
</body>
</html>

Google Apps Script Code:

function onOpen(){
    //
    var ui = SpreadsheetApp.getUi();

    ui.createMenu('Scheduling Controls')      
      .addItem('Show sidebar', 'showSidebar')
      .addToUi();
}

function showSidebar() {
    doGet();
    var html = HtmlService.createHtmlOutputFromFile('Sidebar')
                          .setSandboxMode(HtmlService.SandboxMode.IFRAME)
                          .setTitle('Scheduling Tool')
                          .setWidth(300);
     SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
                   .showSidebar(html);


}

function doGet() {
    return HtmlService
            .createTemplateFromFile('Sidebar')
            .evaluate()
            .setSandboxMode(HtmlService.SandboxMode.IFRAME);
}

I'm build a scheduling tool for equipment in my pany. I am running a script in Google sheets that has a sidebar. I would like to have the user select a button (i.e., Make Reservation) which leads to another page in the sidebar where I can take in user input. I am not sure how to trigger this event with the current code I have. I have one HTML code file and one Google scripts file.

Can someone help me or lead me in the right direction here based on the code below?

HTML/CSS Code:

<!DOCTYPE html>
<html>
    <head>
        <base target="_top">
        <link rel="stylesheet" href="https://ssl.gstatic./docs/script/css/add-ons1.css">
        <!-- The CSS package above applies Google styling to buttons and other elements. -->    
    </head>

<body>

    <center>
        <div class = "sidebar header-logo">
            <img alt="Add-on logo" class="logo"  src="img.png" width="250" height="35.75">
        </div>
    </center>
    <form>

    <style>

    .button1 {
        position: absolute;
        transition: .5s ease;
        top: 50%;
        left: 5%;   
    }

    .button2 {
        position: absolute;
        top: 0%;
        left: 115%;
    }

    .button3 {
        position: absolute;
        top: 115%;
        left: 0%;   
    }

    .button4 {
        position: absolute;
        top: 0%;
        left: -100%;   
    }

    .text {
        position: absolute;
        top: 150px;
        color: #000000;
        font-size:12pt;  
    }
    </style>

    <div class = "text" align = "center">
        <center>
            <b>What would you like to do today?</b>
        </center>
    </div>

    <div class="button1" id="button-bar">
        <form action="http://google.">
            <button class="blue" id="run-translation">Make a Reservation</button>

    <div class="button2" id="button-bar">
        <form action="http://google.">
            <button class="blue" id="run-translation">Cancel Reservation</button>

    <div class="button3" id="button-bar">
        <form action="http://google.">
            <button class="blue" id="run-translation">Request Maintenance</button>

    <div class="button4" id="button-bar">
        <form action="http://google.">
            <button class="blue" id="run-translation">Report Site Bug</button>
        </form>

    <script src="//ajax.googleapis./ajax/libs/jquery/1.9.1/jquery.min.js">
    </script>


    <script>
        window.writeData = function() {
            var formObj = document.getElementById('myForm');

            google.script.run.myServerFunctionName(formObj);
        };

        $(function() {
            $('#run-translation').click(runTranslation);
            $('#insert-text').click(insertText);
            google.script.run.withSuccessHandler(loadPreferences)
                  .withFailureHandler(showError).getPreferences();
        });

        function runTranslation() {
            var win = window.open("http://google.", '_blank');
            win.focus();
        }

    </script>
</body>
</html>

Google Apps Script Code:

function onOpen(){
    //
    var ui = SpreadsheetApp.getUi();

    ui.createMenu('Scheduling Controls')      
      .addItem('Show sidebar', 'showSidebar')
      .addToUi();
}

function showSidebar() {
    doGet();
    var html = HtmlService.createHtmlOutputFromFile('Sidebar')
                          .setSandboxMode(HtmlService.SandboxMode.IFRAME)
                          .setTitle('Scheduling Tool')
                          .setWidth(300);
     SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
                   .showSidebar(html);


}

function doGet() {
    return HtmlService
            .createTemplateFromFile('Sidebar')
            .evaluate()
            .setSandboxMode(HtmlService.SandboxMode.IFRAME);
}
Share Improve this question edited Aug 19, 2016 at 23:45 user229044 240k41 gold badges344 silver badges347 bronze badges asked Jul 7, 2016 at 15:27 Issab0bissaIssab0bissa 411 silver badge2 bronze badges 3
  • Your code lacks of many closing tags. – lorond Commented Jul 7, 2016 at 15:46
  • It seems that you want to hide and show content. You will need to learn how to structure HTML, identify different HTML elements, and show and hide them. Here is some documentation on how to hide an HTML element: Documentation - style.display none – Alan Wells Commented Jul 7, 2016 at 16:34
  • I will take care of the closing tags. Thank you. Not sure if hiding / showing content is what I am looking for , since the buttons/text would still be in the same position and place which would pose issues. – Issab0bissa Commented Jul 7, 2016 at 16:55
Add a ment  | 

1 Answer 1

Reset to default 4

Alright, first of all, I'm assuming that this application is an add-on, since it's in your spreadsheet. That means you don't need that pesky doGet(). The doGet is only necessary on standalone script.

Luckily, what you are trying to achieve is very easy in a GAS add-on. All you need to do is call a .run() function to your .gs to handle it. So, your HTML should look like this.

<button onclick='doMyStuff()'>button</button>
<script>
  function doMyStuff() {
    google.script.run.setUpNewSidebar();
  }
</script>

So, now at .gs:

function setUpNewSidebar() {
  var ui = HtmlService.createHtmlOutputFromFile('newSidebar')
           .setTitle('Report Builder')
           .setSandboxMode(HtmlService.SandboxMode.IFRAME);
         SpreadsheetApp.getUi().showSidebar(ui);
} 

If this IS a standalone script, heavily consider changing this to be an add-on. They are much easier to use and they will most likely work better.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745661835a4638882.html

相关推荐

  • 论文检测,文章检测,降AI率的工具

    1:文字滚筒鸭文字滚筒鸭作为市面上少见的全免费平台,文字滚筒鸭支持文章 AI 率检测、头条文章原创度分析、作文质量评估等多元场景,甚至能一键对比原文与改写后的相似度,所有功能统统 0 收费!精准算法秒出检测结果,不用充值会员,也无需分享裂变

    1小时前
    20
  • 精品网络时代:联通AS9929与10099的强强联合

    中国联通的网络架构犹如一座精心设计的立交桥系统,由AS4837、AS9929和AS10099三张骨干网共同构建。这三张网络各司其职又相互配合,形成了联通独具特色的网络服务体系。联通AS4837、AS9929和AS10099线路介绍一、线路组

    1小时前
    20
  • Kibana Alerting: 突破扩展性限制,实现50倍规模提升

    在过去的几年里,Kibana告警一直是许多大型组织的首选监控解决方案。随着使用的不断增加,用户创建的告警规则数量也在增长。越来越多的组织依赖Kibana进行大规模告警,我们看到了提高效率和确保未来工作负载性能的机会。在Kibana 8.16

    1小时前
    20
  • 怎么用html写出哆啦A梦?

    用HTML和CSS来画哆啦A梦(Doraemon)是一项有趣且具有挑战性的任务。虽然HTML和CSS主要用于网页布局和样式,但通过巧妙的组合和定位,可以创建出相对简单的图形和图案。下面是一个简单的示例,展示了如何用HTML和CSS绘制哆啦A

    1小时前
    00
  • 流固耦合:基本概念、适用软件及 Abaqus 与 Powerflow 的协同仿真

    在工程和科学研究的诸多领域,流固耦合现象广泛存在且对系统性能有着关键影响。理解流固耦合的本质及其应用,对于优化设计、保障安全运行意义重大。同时,借助专业的流固耦合软件,能够更高效地对相关问题进行分析与模拟。接下来,让我们深入探究流固耦合的奥

    1小时前
    00
  • AI驱动的幼儿跌倒检测——视频安全系统的技术解析

    幼儿跌倒检测系统利用AI视频技术,结合人体姿态识别和实时报警功能,提供了一种智能化解决方案。本文将深入剖析其技术架构、模块实现与应用场景,探讨开源技术如何提升幼儿园安全管理。技术架构与实现项目背景幼儿在活动区域(如教室、操场)易发生跌倒,需

    1小时前
    00
  • MySQL 8.4 配置SSL组复制(八个步骤)

    环境这里有三台MySQL主机,分别是192.168.3.71,72,73,主机名分别对应71.3_mgr1,72.3_mgr2,73.3_mgr3,操作系统均为Oracle Linux 8.10 X64,MySQL版本均为MySQL 8.4

    1小时前
    00
  • 利用小提琴图探索帕尔默企鹅数据

    利用小提琴图探索帕尔默企鹅数据代码语言:javascript代码运行次数:0运行复制import numpy as npimport matplotlib.pyplot as pltimport scipy.stats as stfro

    1小时前
    00
  • MySQL8.4 Enterprise安装Firewall及测试

    参考:.4enfirewall.html1.首先执行安装SQL,路径在baseshare目录下代码语言:javascript代码运行次数:0运行复制cd u01mysql3308baseshare[root@mysql8_3

    1小时前
    00
  • 群体遗传三剑客第三篇:megacc和ggtree进化树分析

    大家好,我是邓飞。之前计划写群体结构三剑客的博文,写了两篇了:搞起来!群体遗传三剑客:PCA、Admixture、进化树群体遗传三剑客第一篇:分组和不分组的PCA分析,添加解释百分比群体遗传三剑客第二篇:Admixture群体结构分析今天介

    1小时前
    00
  • AI生态暗战升级,科技巨头铁幕下的终极博弈

    一场围绕AI与智能体的标准、协议及生态的暗战已然蓄势待发。在美剧《权力的游戏》中,不到终局,主角归属始终成谜。如今的AI行业,正上演着同样扣人心弦的戏码。这并非是传统意义上的军事或政治博弈,而是一场围绕AI与智能体的标准、协议及生态展开的暗

    1小时前
    00
  • 电脑分区后进不了系统怎么办,修复教程

    电脑分区后进不了系统&#xff0c;可能的原因有多种&#xff0c;包括分区操作不当导致系统文件丢失或损坏、BIOS设置错误、引导文件未正确配置等。针对这些问题&#xff0c;可以尝试以下解决方法&#xff1

    1小时前
    00
  • 取消Win10开机系统选择倒计时,让电脑秒进系统

    取消Win10开机系统选择倒计时,让电脑秒进系统 近期,不少Win10用户反映在开机时会遇到一个选择系统的倒计时画面,这在一定程度上延缓了开机进程。对于追求高效启动体验的用户来说,这无疑是一个不必要的步骤。那么,如何取消这个倒计时,让电脑

    1小时前
    00
  • 国产之光!!让你的Docker管理更优雅!

    大家好,我是热爱开源的了不起!我们都知道,Docker是个好东西,能帮我们把应用打包成容器,方便部署和管理。但问题来了,Docker的命令行操作对新手来说有点复杂,一不小心就容易出错。而且,有时候我们只是想简单地管理一下容器,却得记住一堆命

    44分钟前
    00
  • 如何打造高效AI智能体?

    作者|Barry Zhang, Anthropic地址|出品|码个蛋(ID:codeegg)整理|陈宇明最近看到了 Anthropic 那篇著名的《Building effective agents》作者之一 Barry Zhang 在 2

    41分钟前
    00
  • 长读长测序揭示结直肠癌异常可变剪接图谱与新型治疗靶点

    徐州医科大学肿瘤研究所董东郑骏年教授团队在Genome Medicine杂志发表题为“Long-read sequencing reveals the landscape of aberrant alternative splicing

    34分钟前
    00
  • 国产车载通信测试方案:车规级CAN SIC芯片测试技术解析

    随着智能网联汽车的快速发展,车辆内部电子控制单元(ECU)数量激增,动力总成、高级驾驶辅助系统(ADAS)、车身控制等功能对车载通信网络的稳定性与速率提出了更高要求。传统CAN FD总线在复杂拓扑中面临信号振铃、通信速率受限(实际速率通常低

    33分钟前
    00
  • CUT&amp;amp;Tag 数据处理和分析教程(7)

    过滤某些项目可能需要对比对质量分数进行更严格的过滤。本文细讨论了bowtie如何分配质量分数,并举例说明。MAPQ(x) = -10 * log10log10(P(x is mapped wrongly)) = -10 * log10(p)

    17分钟前
    10
  • 大模型驱动金融数据应用的实战探索

    近年来,人工智能技术的飞速发展正在重塑全球各行各业的生态格局,金融行业作为数据密集型领域,更是首当其冲。大模型凭借其强大的自然语言处理、逻辑推理和生成能力,逐渐成为金融数据应用的核心驱动力。本文将从行业背景与趋势、核心场景重构、产品能力提升

    6分钟前
    00
  • maxwell遇到的一则问题

    结论和原因maxwell的元数据库里面没有存储全部的schema数据(就是少数据了),导致相关表的DDL校验失败。PS:我这里maxwell的作用只是采集库表修改情况的统计粗粒度指标,因为之前maxwell在运行报错的时候,直接修改了pos

    2分钟前
    00

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信