From a058067ed056984c3689256f3db948066eab99d1 Mon Sep 17 00:00:00 2001 From: nuintun Date: Tue, 24 Nov 2015 12:23:27 +0800 Subject: [PATCH] update files --- index.html | 4 +- static/css/index.css | 6 -- static/js/app/index.js | 5 +- .../app-configure/app-configure.html | 5 +- static/js/components/app-configure/index.js | 48 +++++-------- static/js/components/app-main/app-main.html | 2 +- static/js/components/app-main/index.js | 2 +- static/js/components/dynamic-item/index.js | 2 +- static/js/components/project-base/index.js | 36 ++++++---- .../components/project-base/project-base.html | 4 +- .../js/components/project-configure/index.js | 71 +++++++------------ .../project-configure/project-configure.html | 25 +++++-- 12 files changed, 100 insertions(+), 110 deletions(-) diff --git a/index.html b/index.html index d2a3546..1a095a2 100644 --- a/index.html +++ b/index.html @@ -11,7 +11,7 @@
+ :unique.sync="unique">
@@ -25,7 +25,7 @@ + :unique.sync="unique"> diff --git a/static/css/index.css b/static/css/index.css index 89fad40..ed39b9f 100644 --- a/static/css/index.css +++ b/static/css/index.css @@ -478,16 +478,10 @@ header [class*=" icon-"] { .ui-sub-item .ui-item-error { margin: 5px 0 -10px; } -.ui-submit-tips:before, .ui-item-error span:before { content: '* '; font-weight: bold;; } -.ui-submit-tips { - color: #f00; - text-align: center; - padding: 0 0 15px; -} .ui-no-data { position: absolute; top: 32px; diff --git a/static/js/app/index.js b/static/js/app/index.js index f1c9e0e..5d4050b 100644 --- a/static/js/app/index.js +++ b/static/js/app/index.js @@ -25,7 +25,7 @@ window.addEventListener('DOMContentLoaded', function (){ configure: configure }, computed: { - uniqueProjects: function (){ + unique: function (){ var cache = {}; this.configure.projects.forEach(function (project){ @@ -56,7 +56,8 @@ window.addEventListener('DOMContentLoaded', function (){ configure.projects = configure.projects || []; app.configure = configure; - app.$broadcast('configure-refresh'); + app.$broadcast('reset-input'); + app.$broadcast('reset-error'); } else { init(configure); } diff --git a/static/js/components/app-configure/app-configure.html b/static/js/components/app-configure/app-configure.html index ebdb07e..b5217a2 100644 --- a/static/js/components/app-configure/app-configure.html +++ b/static/js/components/app-configure/app-configure.html @@ -16,10 +16,9 @@
-
{{ submitError }}
-
+
    -
  • +
  • diff --git a/static/js/components/app-configure/index.js b/static/js/components/app-configure/index.js index 31889c3..316c7be 100644 --- a/static/js/components/app-configure/index.js +++ b/static/js/components/app-configure/index.js @@ -19,7 +19,7 @@ module.exports = Vue.component('app-configure', { twoWay: true, required: true }, - uniqueProjects: { + unique: { type: Object, required: true } @@ -28,49 +28,39 @@ module.exports = Vue.component('app-configure', { return { name: '', path: '', - submitError: '', showPopup: false } }, methods: { - focus: function (event){ - if (event.target.type === 'text') { - this.submitError = ''; - } - }, appConfigure: function (command, configure){ ipc.send('app-configure', command, configure); }, hidePopup: function (){ this.showPopup = false; - this.name = ''; - this.path = ''; - this.submitError = ''; + // clean input + var base = this.$refs.base; - // clean error - this.$broadcast('reset-error'); + base.$emit('reset-input'); + base.$emit('reset-error'); }, add: function (){ - this.$broadcast('submit'); + var base = this.$refs.base; - if (this.name && this.path) { - if (this.uniqueProjects[this.name]) { - this.submitError = '项目已存在'; - } else { - this.showPopup = false; - this.configure.projects.push({ name: this.name, path: this.path, env: [], command: [] }); + if (base.isValid()) { + this.showPopup = false; - this.name = ''; - this.path = ''; - this.submitError = ''; + this.configure.projects.push({ + name: this.name, + path: this.path, + env: [], + command: [] + }); - // clean error - this.$broadcast('reset-error'); - - // send message - this.$dispatch('change-active', this.configure.projects.length - 1, true); - this.$dispatch('save-configure'); - } + // clean input + base.$emit('reset-input'); + // send message + this.$dispatch('change-active', this.configure.projects.length - 1, true); + this.$dispatch('save-configure'); } } }, diff --git a/static/js/components/app-main/app-main.html b/static/js/components/app-main/app-main.html index 28e10fa..db199a9 100644 --- a/static/js/components/app-main/app-main.html +++ b/static/js/components/app-main/app-main.html @@ -1,7 +1,7 @@ + :unique.sync="unique">
    diff --git a/static/js/components/app-main/index.js b/static/js/components/app-main/index.js index 2db63c9..873fb42 100644 --- a/static/js/components/app-main/index.js +++ b/static/js/components/app-main/index.js @@ -24,7 +24,7 @@ module.exports = Vue.component('app-main', { twoWay: true, required: true }, - uniqueProjects: { + unique: { type: Object, required: true } diff --git a/static/js/components/dynamic-item/index.js b/static/js/components/dynamic-item/index.js index 87ae696..4d755a1 100644 --- a/static/js/components/dynamic-item/index.js +++ b/static/js/components/dynamic-item/index.js @@ -95,7 +95,7 @@ module.exports = Vue.component('dynamic-item', { this.nameError = ''; this.valueError = ''; }, - 'reset-item-input': function (){ + 'reset-input': function (){ this.name = ''; this.value = ''; } diff --git a/static/js/components/project-base/index.js b/static/js/components/project-base/index.js index bae54b0..05c6f82 100644 --- a/static/js/components/project-base/index.js +++ b/static/js/components/project-base/index.js @@ -18,6 +18,10 @@ module.exports = Vue.component('project-base', { twoWay: true, default: '' }, + unique: { + type: Object, + required: true + }, path: { type: String, twoWay: true, @@ -31,23 +35,19 @@ module.exports = Vue.component('project-base', { }; }, methods: { - focus: function (key, event){ - if (event.target.type === 'text') { - this[key] = ''; - } - } - }, - events: { - 'reset-error': function (){ - this.nameError = ''; - this.pathError = ''; + focus: function (key){ + this[key] = ''; }, - 'submit': function (){ + isValid: function (){ this.name = this.name.trim(); this.path = this.path.trim(); if (this.name) { - this.nameError = ''; + if (this.unique[this.name]) { + this.nameError = '项目已存在'; + } else { + this.nameError = ''; + } } else { this.nameError = '项目名称不能为空'; } @@ -57,6 +57,18 @@ module.exports = Vue.component('project-base', { } else { this.pathError = '项目路径不能为空'; } + + return !this.nameError && !this.pathError; + } + }, + events: { + 'reset-error': function (){ + this.nameError = ''; + this.pathError = ''; + }, + 'reset-input': function (){ + this.name = ''; + this.path = ''; } } }); diff --git a/static/js/components/project-base/project-base.html b/static/js/components/project-base/project-base.html index 2bc5915..f944dca 100644 --- a/static/js/components/project-base/project-base.html +++ b/static/js/components/project-base/project-base.html @@ -1,12 +1,12 @@
  • - +
  • {{ nameError }}
  • -
  • +
  • diff --git a/static/js/components/project-configure/index.js b/static/js/components/project-configure/index.js index ee5afa2..8d76fd2 100644 --- a/static/js/components/project-configure/index.js +++ b/static/js/components/project-configure/index.js @@ -24,76 +24,55 @@ module.exports = Vue.component('project-configure', { type: Object, required: true }, - uniqueProjects: { + unique: { type: Object, - twoWay: true, required: true } }, data: function (){ return { - nameError: '', - pathError: '', - submitError: '', - projectClone: null + clone: null } }, watch: { project: function (project){ - this.projectClone = util.clone(project); + this.reset(); + this.clone = util.clone(project); } }, methods: { - focus: function (event){ - if (event.target.type === 'text') { - this.submitError = ''; - } + reset: function (){ + // clean item input + var base = this.$refs.base; + var env = this.$refs.env; + var command = this.$refs.command; + + base.$emit('reset-error'); + env.$emit('reset-error'); + command.$emit('reset-error'); + env.$emit('reset-input'); + command.$emit('reset-input'); }, edit: function (){ - var name = this.projectClone.name; - var originName = this.project.name; + if (this.$refs.base.isValid()) { + this.show = false; - if (this.projectClone.name && this.projectClone.path) { - if (name !== originName && this.uniqueProjects[name]) { - this.submitError = '项目已存在'; - } else { - this.show = false; + // send message + this.$dispatch('edit', util.clone(this.clone)); - // clean error - this.submitError = ''; - - // send message - this.$dispatch('edit', util.clone(this.projectClone)); - - // clean error - this.$broadcast('reset-error'); - // clean input - this.$broadcast('reset-item-input'); - } + // clean item input + this.reset(); } }, cancel: function (){ this.show = false; - this.submitError = ''; - this.projectClone = util.clone(this.project); + this.clone = util.clone(this.project); - // clean error - this.$broadcast('reset-error'); - // clean input - this.$broadcast('reset-item-input'); - } - }, - events: { - 'configure-refresh': function (){ - this.submitError = ''; - - // clean error - this.$broadcast('reset-error'); - // clean input - this.$broadcast('reset-item-input'); + // clean item input + this.reset(); } }, created: function (){ - this.projectClone = util.clone(this.project); + this.clone = util.clone(this.project); } }); diff --git a/static/js/components/project-configure/project-configure.html b/static/js/components/project-configure/project-configure.html index 6cbabf4..26b112d 100644 --- a/static/js/components/project-configure/project-configure.html +++ b/static/js/components/project-configure/project-configure.html @@ -1,5 +1,5 @@
    - +
    @@ -7,16 +7,31 @@
    -
    {{ submitError }}
      -
    • +
    • +
    • - + +
    • - + +