fix project viewer
This commit is contained in:
@@ -141,8 +141,7 @@ define(
|
||||
.then(function (id) {
|
||||
program.data.projectId = id;
|
||||
program.ttfManager.setState('new');
|
||||
program.projectViewer.show(program.project.items());
|
||||
program.projectViewer.select(id);
|
||||
program.projectViewer.show(program.project.items(), id);
|
||||
program.loading.show('保存成功...', 400);
|
||||
}, function () {
|
||||
program.loading.show('保存失败...', 400);
|
||||
|
||||
@@ -401,6 +401,7 @@ define(
|
||||
*/
|
||||
function bindProject(program) {
|
||||
program.projectViewer.on('open', function (e) {
|
||||
var oldProjectId = program.data.projectId;
|
||||
program.project.get(e.projectId).then(function (imported) {
|
||||
if (imported) {
|
||||
if (program.ttfManager.isChanged() && !window.confirm('是否放弃保存当前编辑项目?')) {
|
||||
@@ -412,7 +413,12 @@ define(
|
||||
program.viewer.focus();
|
||||
}
|
||||
}, function () {
|
||||
program.loading.error('打开项目失败!', 1000);
|
||||
if (window.confirm('打开项目失败,是否删除项目?')) {
|
||||
var fnRemoveProject = function () {
|
||||
program.projectViewer.show(program.project.items(), oldProjectId);
|
||||
};
|
||||
program.project.remove(e.projectId, true).then(fnRemoveProject, fnRemoveProject);
|
||||
}
|
||||
});
|
||||
|
||||
})
|
||||
|
||||
@@ -107,9 +107,11 @@ define(
|
||||
* 删除一个项目
|
||||
*
|
||||
* @param {string} id 项目名称
|
||||
* @param {boolean} force 是否强制删除,
|
||||
* 有些项目数据损坏可以强制删除此项目索引
|
||||
* @return {Array} 现有项目列表
|
||||
*/
|
||||
remove: function (id) {
|
||||
remove: function (id, force) {
|
||||
var list = this.items();
|
||||
for (var i = list.length - 1; i >= 0; i--) {
|
||||
if (list[i].id === id) {
|
||||
@@ -125,6 +127,7 @@ define(
|
||||
storage.setItem('project-list', JSON.stringify(list));
|
||||
resolver.resolve(list);
|
||||
}, function () {
|
||||
force && storage.setItem('project-list', JSON.stringify(list));
|
||||
resolver.reject(id);
|
||||
});
|
||||
|
||||
|
||||
@@ -29,11 +29,9 @@ define(
|
||||
var action = target.attr('data-action');
|
||||
var id = target.parents('[data-id]').attr('data-id');
|
||||
if ('del' === action) {
|
||||
|
||||
if (!window.confirm('是否删除项目?')) {
|
||||
return;
|
||||
}
|
||||
|
||||
me.current && me.current.remove();
|
||||
me.current = null;
|
||||
}
|
||||
@@ -64,8 +62,9 @@ define(
|
||||
* 显示项目组
|
||||
*
|
||||
* @param {Array} projects 项目组
|
||||
* @param {string} selectedId 选中的项目名称
|
||||
*/
|
||||
ProjectViewer.prototype.show = function (projects) {
|
||||
ProjectViewer.prototype.show = function (projects, selectedId) {
|
||||
var str = '';
|
||||
(projects || []).forEach(function (proj) {
|
||||
str += '<dl data-id="' + proj.id + '">'
|
||||
@@ -78,6 +77,9 @@ define(
|
||||
});
|
||||
|
||||
this.main.html(str);
|
||||
if (undefined !== selectedId) {
|
||||
this.select(selectedId);
|
||||
}
|
||||
};
|
||||
|
||||
require('common/observable').mixin(ProjectViewer.prototype);
|
||||
|
||||
Reference in New Issue
Block a user