select new palette after saving

This commit is contained in:
jdescottes 2014-09-16 00:37:24 +02:00
parent f7f9587520
commit fab9c6e836
4 changed files with 39 additions and 22 deletions

View File

@ -65,7 +65,7 @@
}
.colors-list {
overflow : hidden;
overflow : auto;
width : 280px;
}

View File

@ -38,9 +38,10 @@
$.subscribe(Events.CURRENT_COLORS_UPDATED, this.fillColorListContainer.bind(this));
$.subscribe(Events.PRIMARY_COLOR_SELECTED, this.highlightSelectedColors.bind(this));
$.subscribe(Events.SECONDARY_COLOR_SELECTED, this.highlightSelectedColors.bind(this));
$.subscribe(Events.USER_SETTINGS_CHANGED, $.proxy(this.onUserSettingsChange_, this));
this.fillPaletteList();
this.selectPaletteFromUserSettings();
this.updateFromUserSettings();
this.fillColorListContainer();
};
@ -77,7 +78,7 @@
ns.PalettesListController.prototype.getSelectedPaletteColors_ = function () {
var colors = [];
var paletteId = this.colorPaletteSelect_.value;
var paletteId = pskl.UserSettings.get(pskl.UserSettings.SELECTED_PALETTE);
if (paletteId === Constants.CURRENT_COLORS_PALETTE_ID) {
colors = this.usedColorService.getCurrentColors();
} else {
@ -94,18 +95,25 @@
return colors;
};
ns.PalettesListController.prototype.selectPaletteFromUserSettings = function () {
this.selectPalette(pskl.UserSettings.get(pskl.UserSettings.SELECTED_PALETTE));
ns.PalettesListController.prototype.selectPalette = function (paletteId) {
pskl.UserSettings.set(pskl.UserSettings.SELECTED_PALETTE, paletteId);
};
ns.PalettesListController.prototype.selectPalette = function (paletteId) {
ns.PalettesListController.prototype.onUserSettingsChange_ = function (evt, name, value) {
if (name == pskl.UserSettings.SELECTED_PALETTE) {
this.updateFromUserSettings();
}
};
ns.PalettesListController.prototype.updateFromUserSettings = function () {
var paletteId = pskl.UserSettings.get(pskl.UserSettings.SELECTED_PALETTE);
this.fillColorListContainer();
this.colorPaletteSelect_.value = paletteId;
};
ns.PalettesListController.prototype.onPaletteSelected_ = function (evt) {
var paletteId = this.colorPaletteSelect_.value;
pskl.UserSettings.set(pskl.UserSettings.SELECTED_PALETTE, paletteId);
this.fillColorListContainer();
this.selectPalette(paletteId);
};
ns.PalettesListController.prototype.onCreatePaletteClick_ = function (evt) {
@ -191,7 +199,6 @@
ns.PalettesListController.prototype.onPaletteListUpdated = function () {
this.fillPaletteList();
this.selectPaletteFromUserSettings();
this.fillColorListContainer();
this.updateFromUserSettings();
};
})();

View File

@ -120,16 +120,22 @@
};
ns.CreatePaletteController.prototype.onSubmitButtonClick_ = function (evt) {
this.paletteService.savePalette(this.palette);
this.saveAndSelectPalette_(this.palette);
this.closeDialog();
};
ns.CreatePaletteController.prototype.onCloneButtonClick_ = function (evt) {
var palette = new pskl.model.Palette(pskl.utils.Uuid.generate(), this.palette.name, this.palette.colors);
this.paletteService.savePalette(palette);
var uuid = pskl.utils.Uuid.generate();
var palette = new pskl.model.Palette(uuid, this.palette.name, this.palette.colors);
this.saveAndSelectPalette_(palette);
this.closeDialog();
};
ns.CreatePaletteController.prototype.saveAndSelectPalette_ = function (palette) {
this.paletteService.savePalette(palette);
pskl.UserSettings.set(pskl.UserSettings.SELECTED_PALETTE, palette.id);
};
ns.CreatePaletteController.prototype.onImportFileButtonClick_ = function () {
this.hiddenFileInput.click();
};

View File

@ -9,7 +9,7 @@
ns.PaletteImportService = function () {};
ns.PaletteImportService.prototype.read = function (file, onSuccess, onError) {
var reader = this.getFileReader_(file, onSuccess, onError);
var reader = this.getReader_(file, onSuccess, onError);
if (reader) {
reader.read();
} else {
@ -21,20 +21,24 @@
return file.type.indexOf('image') === 0;
};
ns.PaletteImportService.prototype.getFileReader_ = function (file, onSuccess, onError) {
ns.PaletteImportService.prototype.getReader_ = function (file, onSuccess, onError) {
var readerClass = this.getReaderClass_(file);
var reader = null;
if (readerClass) {
reader = new readerClass(file, onSuccess, onError);
return new readerClass(file, onSuccess, onError);
} else {
return null;
}
return reader;
};
ns.PaletteImportService.prototype.getReaderClass_ = function (file) {
var extension = this.getExtension_(file);
return fileReaders[extension];
var readerClass;
if (this.isImage_(file)) {
readerClass = ns.PaletteImageReader;
} else {
var extension = this.getExtension_(file);
readerClass = fileReaders[extension];
}
return readerClass;
};
ns.PaletteImportService.prototype.getExtension_ = function (file) {