-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCode.gs
95 lines (84 loc) · 2.76 KB
/
Code.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
* Author: Gaurav Grover (gauravgrover95@gmail.com)
* Date: 14/06/2016
* Purpose: To set basic required functions for the script
*/
/**
* Simple Trigger Function
* Triggers let Apps Script run a function automatically when a certain event occurs.
* This function executes automatically on opening of the document
* Creates Custom Menu for the Spreadsheet
*/
function onOpen() {
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
.createMenu('Orders')
.addItem('Reimport', 'reimport')
.addItem('Clear', 'clear')
.addItem('Import', 'import')
.addItem('Import Settings', 'showImportSettingsDialog')
.addItem('User Settings', 'showUserSettingsDialog')
// .addItem('Settings', 'showSidebar')
.addToUi();
}
/**
* Shows Dialog Box for User Settings option in the menu
*/
function showUserSettingsDialog() {
var html = HtmlService.createHtmlOutputFromFile('User_Settings')
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setWidth(300)
.setHeight(250);
SpreadsheetApp.getUi()
.showModalDialog(html, 'User Settings');
}
/**
* Saves the user preferences and authentication variables
* @param {url} string url of the site from where data is to be imported
* @param {consumer_key} string consumer key of the wc-api provided to the user received from User_Settings.html
* @param {consumer_secret} string consumer secret of the wc-api provided to the user received from User_Settings.html
*/
function saveUserSetttings(url, consumer_key, consumer_secret) {
documentProperties.setProperty('SITE_URL',url);
userProperties.setProperty('CONSUMER_KEY', consumer_key)
userProperties.setProperty('CONSUMER_SECRET', consumer_secret);
SpreadsheetApp.flush();
Utilities.sleep(5000);
}
/**
* Opens Dialog Box for Import Settings option in the menu
* Opens interface coded in Import_Settings.html
*/
function showImportSettingsDialog() {
var html = HtmlService.createHtmlOutputFromFile('Import_Settings')
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setWidth(420)
.setHeight(320);
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
.showModalDialog(html, 'Import Settings');
}
/**
* Function used to refresh the data and sync new data from the API
*/
function reimport() {
clear();
import();
}
/**
* Clears the whole worksheet
*/
function clear() {
currentSheet.clear();
}
/**
* Shows Sidebar for Detailed Session Settings.
* Opens interface coded in Settings.html
*/
//function showSidebar() {
// var html = HtmlService.createHtmlOutputFromFile('Settings')
// .setSandboxMode(HtmlService.SandboxMode.IFRAME)
// .setTitle('Orders')
// .setWidth(100);
//
// SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
// .showSidebar(html);
//}