mirror of
https://github.com/google/blockly.git
synced 2026-01-30 20:20:09 +01:00
Blockly Factory: Global Self Bug Fix (#616)
* fix bug with global self * cleaned up code, moved warn into block lib controller, check for starter block in FactoryUtils.savedBlockChanges
This commit is contained in:
@@ -287,7 +287,7 @@ AppController.prototype.onTab = function() {
|
||||
if (this.lastSelectedTab == AppController.BLOCK_FACTORY &&
|
||||
this.selectedTab != AppController.BLOCK_FACTORY) {
|
||||
|
||||
var hasUnsavedChanges = !BlockFactory.isStarterBlock() &&
|
||||
var hasUnsavedChanges =
|
||||
!FactoryUtils.savedBlockChanges(this.blockLibraryController);
|
||||
if (hasUnsavedChanges &&
|
||||
!confirm('You have unsaved changes in Block Factory.')) {
|
||||
@@ -531,7 +531,8 @@ AppController.prototype.assignBlockFactoryClickHandlers = function() {
|
||||
.addEventListener('click', function() {
|
||||
// If there are unsaved changes warn user, check if they'd like to
|
||||
// proceed with unsaved changes, and act accordingly.
|
||||
var proceedWithUnsavedChanges = FactoryUtils.warnIfUnsavedChanges();
|
||||
var proceedWithUnsavedChanges =
|
||||
self.blockLibraryController.warnIfUnsavedChanges();
|
||||
if (!proceedWithUnsavedChanges) {
|
||||
return;
|
||||
}
|
||||
@@ -625,8 +626,7 @@ AppController.prototype.onresize = function(event) {
|
||||
* before actually refreshing.
|
||||
*/
|
||||
AppController.prototype.confirmLeavePage = function() {
|
||||
if (!BlockFactory.isStarterBlock() &&
|
||||
!FactoryUtils.savedBlockChanges(this.blockLibraryController)) {
|
||||
if (!FactoryUtils.savedBlockChanges(this.blockLibraryController)) {
|
||||
// When a string is assigned to the returnValue Event property, a dialog box
|
||||
// appears, asking the users for confirmation to leave the page.
|
||||
return 'You will lose any unsaved changes. Are you sure you want ' +
|
||||
@@ -649,7 +649,7 @@ AppController.prototype.init = function() {
|
||||
this.assignBlockFactoryClickHandlers();
|
||||
|
||||
this.onresize();
|
||||
self = this;
|
||||
var self = this;
|
||||
window.addEventListener('resize', function() {
|
||||
self.onresize();
|
||||
});
|
||||
|
||||
@@ -254,6 +254,21 @@ BlockLibraryController.prototype.setNoneSelected = function() {
|
||||
this.view.setSelectedBlockType(null);
|
||||
};
|
||||
|
||||
/**
|
||||
* If there are unsaved changes to the block in open in Block Factory
|
||||
* and the block is not the starter block, check if user wants to proceed,
|
||||
* knowing that it will cause them to lose their changes.
|
||||
*
|
||||
* @return {boolean} Whether or not to proceed.
|
||||
*/
|
||||
BlockLibraryController.prototype.warnIfUnsavedChanges = function() {
|
||||
if (!FactoryUtils.savedBlockChanges(this)) {
|
||||
return confirm('You have unsaved changes. By proceeding without saving ' +
|
||||
' your block first, you will lose these changes.');
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add select handler for an option of a given block type. The handler will to
|
||||
* update the view and the selected block accordingly.
|
||||
@@ -283,7 +298,7 @@ BlockLibraryController.prototype.addOptionSelectHandler = function(blockType) {
|
||||
return function() {
|
||||
// If there are unsaved changes warn user, check if they'd like to
|
||||
// proceed with unsaved changes, and act accordingly.
|
||||
var proceedWithUnsavedChanges = FactoryUtils.warnIfUnsavedChanges();
|
||||
var proceedWithUnsavedChanges = self.warnIfUnsavedChanges();
|
||||
if (!proceedWithUnsavedChanges) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -963,7 +963,8 @@ FactoryUtils.isProcedureBlock = function(block) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns whether or not a block's changes has been saved to the Block Library.
|
||||
* Returns whether or not a modified block's changes has been saved to the
|
||||
* Block Library.
|
||||
* TODO(quachtina96): move into the Block Factory Controller once made.
|
||||
*
|
||||
* @param {!BlockLibraryController} blockLibraryController - Block Library
|
||||
@@ -972,6 +973,9 @@ FactoryUtils.isProcedureBlock = function(block) {
|
||||
* the given Block Library.
|
||||
*/
|
||||
FactoryUtils.savedBlockChanges = function(blockLibraryController) {
|
||||
if (BlockFactory.isStarterBlock()) {
|
||||
return true;
|
||||
}
|
||||
var blockType = blockLibraryController.getCurrentBlockType();
|
||||
var currentXml = Blockly.Xml.workspaceToDom(BlockFactory.mainWorkspace);
|
||||
|
||||
@@ -983,18 +987,3 @@ FactoryUtils.savedBlockChanges = function(blockLibraryController) {
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* If there are unsaved changes to the block in open in Block Factory
|
||||
* and the block is not the starter block, check if user wants to proceed,
|
||||
* knowing that it will cause them to lose their changes.
|
||||
*
|
||||
* @return {boolean} Whether or not to proceed.
|
||||
*/
|
||||
FactoryUtils.warnIfUnsavedChanges = function() {
|
||||
if (!BlockFactory.isStarterBlock() &&
|
||||
!FactoryUtils.savedBlockChanges(self.blockLibraryController)) {
|
||||
return confirm('You have unsaved changes. By proceeding without saving ' +
|
||||
' your block first, you will lose these changes.');
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user