mirror of
https://github.com/google/blockly.git
synced 2026-01-21 15:57:10 +01:00
Blockly Factory: Workspace Factory Import Buttons (#578)
* Split import into 2 buttons, made file endings consistent * Nit spelling * Nit removed logging message
This commit is contained in:
committed by
picklesrus
parent
37fae54a59
commit
66eff965c9
@@ -143,9 +143,9 @@ BlockExporterController.prototype.export = function() {
|
||||
// Get block definition code in the selected format for the blocks.
|
||||
var blockDefs = this.tools.getBlockDefs(blockXmlMap,
|
||||
definitionFormat);
|
||||
// Download the file.
|
||||
// Download the file, using .js file ending for JSON or Javascript.
|
||||
FactoryUtils.createAndDownloadFile(
|
||||
blockDefs, blockDef_filename, definitionFormat);
|
||||
blockDefs, blockDef_filename, 'javascript');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,9 +158,15 @@ BlockExporterController.prototype.export = function() {
|
||||
// Get generator stub code in the selected language for the blocks.
|
||||
var genStubs = this.tools.getGeneratorCode(blockXmlMap,
|
||||
language);
|
||||
// Get the correct file extension.
|
||||
if (language == 'JavaScript') {
|
||||
var fileType = 'javascript';
|
||||
} else {
|
||||
var fileType = 'plain';
|
||||
}
|
||||
// Download the file.
|
||||
FactoryUtils.createAndDownloadFile(
|
||||
genStubs, generatorStub_filename, language);
|
||||
genStubs, generatorStub_filename, fileType);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -124,16 +124,22 @@
|
||||
<div id="workspaceFactoryContent">
|
||||
<p>
|
||||
<div class="dropdown">
|
||||
<button id="button_import">Import</button>
|
||||
<div id="dropdownDiv_import" class="dropdown-content">
|
||||
<input type="file" id="input_importToolbox" class="inputfile"></input>
|
||||
<label for="input_importToolbox">Toolbox</label>
|
||||
<input type="file" id="input_importPreload" class="inputfile"</input>
|
||||
<label for="input_importPreload">Workspace Blocks</label>
|
||||
<input type="file" id="input_importCategoryJson" class="inputfile"</input>
|
||||
<label for="input_importCategoryJson">Blocks from JSON</label>
|
||||
<input type="file" id="input_importCategoryJs" class="inputfile"</input>
|
||||
<label for="input_importCategoryJs">Blocks from Javascript</label>
|
||||
<button id="button_importBlocks">Import Custom Blocks</button>
|
||||
<div id="dropdownDiv_importBlocks" class="dropdown-content">
|
||||
<input type="file" id="input_importBlocksJson" accept=".js, .json, .txt" class="inputfile"</input>
|
||||
<label for="input_importBlocksJson">From JSON</label>
|
||||
<input type="file" id="input_importBlocksJs" accept=".js, .txt" class="inputfile"</input>
|
||||
<label for="input_importBlocksJs">From Javascript</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="dropdown">
|
||||
<button id="button_load">Load to Edit</button>
|
||||
<div id="dropdownDiv_load" class="dropdown-content">
|
||||
<input type="file" id="input_loadToolbox" accept=".xml" class="inputfile"></input>
|
||||
<label for="input_loadToolbox">Toolbox</label>
|
||||
<input type="file" id="input_loadPreload" accept=".xml" class="inputfile"</input>
|
||||
<label for="input_loadPreload">Workspace Blocks</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -366,7 +366,7 @@ WorkspaceFactoryController.prototype.exportOptionsFile = function() {
|
||||
this.generateNewOptions();
|
||||
// TODO(evd2014): Use Regex to prettify JSON generated.
|
||||
var data = new Blob([JSON.stringify(this.model.options)],
|
||||
{type: 'text/plain'});
|
||||
{type: 'text/javascript'});
|
||||
this.view.createAndDownloadFile(fileName, data);
|
||||
};
|
||||
|
||||
|
||||
@@ -232,7 +232,9 @@ WorkspaceFactoryInit.assignWorkspaceFactoryClickHandlers_ =
|
||||
('click',
|
||||
function() {
|
||||
document.getElementById('dropdownDiv_export').classList.toggle("show");
|
||||
document.getElementById('dropdownDiv_import').classList.remove("show");
|
||||
document.getElementById('dropdownDiv_load').classList.remove("show");
|
||||
document.getElementById('dropdownDiv_importBlocks').classList.
|
||||
remove("show");
|
||||
})
|
||||
|
||||
document.getElementById('button_print').addEventListener
|
||||
@@ -296,47 +298,64 @@ WorkspaceFactoryInit.assignWorkspaceFactoryClickHandlers_ =
|
||||
remove("show");
|
||||
});
|
||||
|
||||
document.getElementById('button_import').addEventListener
|
||||
document.getElementById('button_importBlocks').addEventListener
|
||||
('click',
|
||||
function() {
|
||||
document.getElementById('dropdownDiv_import').classList.toggle("show");
|
||||
document.getElementById('dropdownDiv_importBlocks').classList.
|
||||
toggle("show");
|
||||
document.getElementById('dropdownDiv_export').classList.remove("show");
|
||||
document.getElementById('dropdownDiv_load').classList.remove("show");
|
||||
});
|
||||
|
||||
document.getElementById('input_importToolbox').addEventListener
|
||||
document.getElementById('button_load').addEventListener
|
||||
('click',
|
||||
function() {
|
||||
document.getElementById('dropdownDiv_load').classList.toggle("show");
|
||||
document.getElementById('dropdownDiv_export').classList.remove("show");
|
||||
document.getElementById('dropdownDiv_importBlocks').classList.
|
||||
remove("show");
|
||||
});
|
||||
|
||||
document.getElementById('input_loadToolbox').addEventListener
|
||||
('change',
|
||||
function() {
|
||||
controller.importFile(event.target.files[0],
|
||||
WorkspaceFactoryController.MODE_TOOLBOX);
|
||||
document.getElementById('dropdownDiv_import').classList.remove("show");
|
||||
document.getElementById('dropdownDiv_load').classList.remove("show");
|
||||
});
|
||||
|
||||
document.getElementById('input_importPreload').addEventListener
|
||||
document.getElementById('input_loadPreload').addEventListener
|
||||
('change',
|
||||
function() {
|
||||
controller.importFile(event.target.files[0],
|
||||
WorkspaceFactoryController.MODE_PRELOAD);
|
||||
document.getElementById('dropdownDiv_import').classList.remove("show");
|
||||
document.getElementById('dropdownDiv_load').classList.remove("show");
|
||||
});
|
||||
|
||||
document.getElementById('input_importCategoryJson').addEventListener
|
||||
document.getElementById('input_importBlocksJson').addEventListener
|
||||
('change',
|
||||
function() {
|
||||
controller.importBlocks(event.target.files[0],'JSON');
|
||||
document.getElementById('dropdownDiv_import').classList.remove("show");
|
||||
document.getElementById('dropdownDiv_importBlocks').classList.
|
||||
remove("show");
|
||||
});
|
||||
|
||||
document.getElementById('input_importCategoryJs').addEventListener
|
||||
document.getElementById('input_importBlocksJs').addEventListener
|
||||
('change',
|
||||
function() {
|
||||
controller.importBlocks(event.target.files[0],'JavaScript');
|
||||
document.getElementById('dropdownDiv_import').classList.remove("show");
|
||||
document.getElementById('dropdownDiv_importBlocks').classList.
|
||||
remove("show");
|
||||
});
|
||||
|
||||
document.getElementById('button_clear').addEventListener
|
||||
('click',
|
||||
function() {
|
||||
controller.clearToolbox();
|
||||
document.getElementById('dropdownDiv_importBlocks').classList.
|
||||
remove("show");
|
||||
document.getElementById('dropdownDiv_export').classList.remove("show");
|
||||
document.getElementById('dropdownDiv_load').classList.remove("show");
|
||||
});
|
||||
|
||||
document.getElementById('dropdown_addShadow').addEventListener
|
||||
|
||||
Reference in New Issue
Block a user