update files

This commit is contained in:
Nuintun 2015-11-20 17:45:23 +08:00
parent b31cda4eab
commit 37587ea685
5 changed files with 33 additions and 18 deletions

View File

@ -186,9 +186,7 @@ AppConfigure.prototype = {
});
break;
case 'save':
context.save(configure, function (){
this.showMessageBox('保存成功!', { type: 'info' });
}, function (){
context.save(configure, null, function (){
this.showMessageBox('保存失败!');
});
break;

View File

@ -15,15 +15,19 @@ require('../components/project-base');
require('../components/dynamic-item');
window.addEventListener('DOMContentLoaded', function (){
function normalize(configure){
return JSON.parse(JSON.stringify(configure));
}
var app = new Vue({
el: '#app',
data: {
activeIndex: 0,
configure: { projects: [] }
configure: {}
},
events: {
'save-configure': function (){
ipc.send('app-configure', 'save', normalize(this.configure));
}
}
});

View File

@ -27,9 +27,22 @@ module.exports = Vue.component('app-configure', {
popup: false
}
},
computed: {
uniqueCache: function (){
var cache = {};
this.configure.projects && this.configure.projects.forEach(function (project){
cache[project.name] = true;
});
return cache;
}
},
methods: {
focus: function (){
this.submitError = '';
focus: function (event){
if (event.target.type === 'text') {
this.submitError = '';
}
},
appConfigure: function (command, configure){
ipc.send('app-configure', command, configure);
@ -45,25 +58,23 @@ module.exports = Vue.component('app-configure', {
addProject: function (){
this.$broadcast('submit');
console.log(this.uniqueCache[this.name]);
if (this.name && this.path) {
if (this.$data._cached[this.name]) {
if (this.uniqueCache[this.name]) {
this.submitError = '项目已存在';
} else {
this.popup = false;
this.configure.projects.push({ name: this.name, path: this.path });
this.$data._cached[this.name] = true;
// clean imput
this.name = '';
this.path = '';
this.submitError = '';
this.$dispatch('save-configure');
}
}
}
},
created: function (){
this.configure.projects.forEach(function (project){
this.$data._cached[project.name] = true;
}, this);
}
});

View File

@ -29,8 +29,10 @@ module.exports = Vue.component('project-base', {
};
},
methods: {
focus: function (key){
this[key] = '';
focus: function (key, event){
if (event.target.type === 'text') {
this[key] = '';
}
}
},
events: {

View File

@ -1,12 +1,12 @@
<li>
<label>项目名称:</label>
<input type="text" v-model="name" placeholder="项目名称" lazy @focus="focus('nameError')"/>
<input type="text" v-model="name" placeholder="项目名称" lazy @focus="focus('nameError', $event)"/>
</li>
<li v-show="nameError" class="ui-item-error">
<label class="fn-invisible">&emsp;&emsp;&emsp;&emsp;&emsp;</label>
<span><i class="icon-expand"></i>{{ nameError }}</span>
</li>
<li @focusin="focus('pathError')">
<li @focusin="focus('pathError', $event)">
<directory label="项目路径" :path.sync="path"></directory>
</li>
<li v-show="pathError" class="ui-item-error">