|
var selectedFolder; |
|
var dialog; |
|
|
|
function doGet() { |
|
var app = UiApp.createApplication(); |
|
var heading = app.createHTML("<h1>Folders for</h1>"); |
|
app.add(heading); |
|
var allFoldersIterator = DriveApp.getFolders(); |
|
var text = app.createTextArea().setName("text").setId("output"); |
|
app.add(text); |
|
var tree = app.createTree(); |
|
var rootFolder = DriveApp.getRootFolder(); |
|
var treeRoot = app.createTreeItem(rootFolder.getName()).setId(rootFolder.getId()); |
|
var handler = app.createServerHandler("folderSelected"); |
|
tree.addItem(treeRoot); |
|
tree.addSelectionHandler(handler); |
|
treeRoot.setState(true); |
|
createBranch(rootFolder, treeRoot, app); |
|
app.add(tree); |
|
var selectedFolderIdBox = app.createTextBox().setName("selectedFolderIdBox").setId("selectedFolderIdBox"); |
|
app.add(selectedFolderIdBox); |
|
return app; |
|
} |
|
|
|
function createBranch(folder, branch, app) { |
|
var children = folder.getFolders(); |
|
while (children.hasNext()) { |
|
child = children.next(); |
|
Logger.log("Folder id: " + child.getId()); |
|
var subBranch = app.createTreeItem(child.getName()).setId(child.getId()); |
|
branch.addItem(subBranch); |
|
createBranch(child, subBranch, app); |
|
} |
|
} |
|
|
|
function folderSelected(eventInfo) { |
|
var app = UiApp.getActiveApplication(); |
|
var parameter = eventInfo.parameter; |
|
Logger.log("Selected " + eventInfo.parameter.selected); |
|
selectedFolder = DriveApp.getFolderById(eventInfo.parameter.selected); |
|
var selectedFolderIdBox = app.getElementById("selectedFolderIdBox"); |
|
selectedFolderIdBox.setValue(eventInfo.parameter.selected); |
|
var okHandler = app.createServerHandler("okResetPermissions"); |
|
okHandler.addCallbackElement(selectedFolderIdBox); |
|
dialog = app.createDialogBox(true, true); |
|
var panel = app.createFlowPanel(); |
|
dialog.add(panel); |
|
dialog.setId("confirmationDialog"); |
|
dialog.setPopupPosition(100, 100).setSize(500, 500); |
|
panel.add(app.createLabel("Do you want to reset permissions for all files found in folder " + selectedFolder.getName() + " and its subfolders?\n (Click outside of the dialog box to cancel)")); |
|
panel.add(app.createButton("Do it!", okHandler)); |
|
dialog.show(); |
|
return app; |
|
} |
|
|
|
function okResetPermissions(eventInfo) { |
|
var selectedFolderId = eventInfo.parameter.selectedFolderIdBox; |
|
var selectedFolder = DriveApp.getFolderById(selectedFolderId); |
|
Logger.log("Resetting permissions on " + selectedFolder.getName()); |
|
var app = UiApp.getActiveApplication(); |
|
app.getElementById("confirmationDialog").hide(); |
|
Logger.log("Confirmation dialog hidden"); |
|
var progressIndicator = app.createDialogBox(false, true); |
|
progressIndicator.setId("progressIndicator"); |
|
progressIndicator.setPopupPosition(100, 100).setSize(500, 500); |
|
var label = app.createLabel("Working ..."); |
|
progressIndicator.add(label); |
|
progressIndicator.show(); |
|
doResetPermissions(selectedFolder, function() { |
|
var app = UiApp.getActiveApplication(); |
|
var progressIndicator = app.getElementById("progressIndicator"); |
|
progressIndicator.hide(); |
|
return app; |
|
}); |
|
return app; |
|
} |
|
|
|
function doResetPermissions(selectedFolder, callback) { |
|
Logger.log("Resetting permissions on folder " + selectedFolder.getName()); |
|
var sharingAccess = selectedFolder.getSharingAccess(); |
|
var sharingPermission = selectedFolder.getSharingPermission(); |
|
var files = selectedFolder.getFiles(); |
|
while (files.hasNext()) { |
|
var file = files.next(); |
|
Logger.log(" Resetting permissions on file " + file.getName()); |
|
file.setSharing(sharingAccess, sharingPermission); |
|
var viewers = file.getViewers(); |
|
for (var i = 0; i < viewers.length; i++) { |
|
Logger.log(" Removing viewer " + viewers[i].getEmail()); |
|
file.removeViewer(viewers[i]); |
|
} |
|
var editors = file.getEditors(); |
|
for (var i = 0; i < editors.length; i++) { |
|
Logger.log(" Removing editor " + editors[i].getEmail()); |
|
file.removeEditor(editors[i]); |
|
} |
|
} |
|
var children = selectedFolder.getFolders(); |
|
while (children.hasNext()) { |
|
var child = children.next(); |
|
doResetPermissions(child); |
|
} |
|
if (callback) { |
|
callback(); |
|
} |
|
} |
r
Exception: UiApp has been deprecated. Please use HtmlService instead.
doGet @ Código.gs:5
Any Solution?