diff --git a/app/app/components/section/trello/type-editor.js b/app/app/components/section/trello/type-editor.js index 5974177d..b8b40af1 100644 --- a/app/app/components/section/trello/type-editor.js +++ b/app/app/components/section/trello/type-editor.js @@ -8,21 +8,34 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, { isDirty: false, waiting: false, authenticated: false, - config: { - appKey: "", - board: null, - list: null, - cards: null - }, + config: {}, boards: null, lists: null, - hasAppKey: function() { - console.log(is.not.empty(this.get('config.appKey'))); - return is.empty(this.get('config.appKey')) ? false : true; - }.property('config'), + didReceiveAttrs() { + let config = {}; - didReceiveAttrs() {}, + try { + config = JSON.parse(this.get('meta.config')); + } catch (e) {} + + if (is.empty(config)) { + config = { + appKey: "", + token: "", + board: null, + list: null, + cards: null + }; + } + + this.set('config', config); + + if (this.get('config.appKey') !== "" && + this.get('config.token') !== "") { + this.send('auth'); + } + }, willDestroyElement() { this.destroyTooltips(); @@ -30,30 +43,52 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, { getBoardLists() { let self = this; + let boards = this.get('boards'); let board = this.get('config.board'); + this.set('waiting', true); + + if (board === null) { + if (boards.length) { + board = boards[0]; + this.set('config.board', board); + } + } else { + this.set('config.board', boards.findBy('id', board.id)); + } Trello.get(`boards/${board.id}/lists/open`, function(lists) { - self.set('lists', lists); - - if (lists.length) { - self.set('config.list', lists[0]); + let savedLists = self.get('config.lists'); + if (savedLists === null) { + savedLists = []; } - self.getListCards(); + lists.forEach(function(list) { + let saved = savedLists.findBy("id", list.id); + let included = true; + if (is.not.undefined(saved)) { + included = saved.included; + } + list.included = included; + }); + + self.set('config.lists', lists); + self.set('waiting', false); + + // self.getListCards(); }); }, - getListCards() { - let self = this; - let list = this.get('config.list'); + // getListCards() { + // let self = this; + // let list = this.get('config.list'); - Trello.get(`lists/${list.id}/cards`, - function(cards) { - self.set('config.cards', cards); - console.log(cards); - }); - }, + // Trello.get(`lists/${list.id}/cards`, + // function(cards) { + // self.set('config.cards', cards); + // console.log(cards); + // }); + // }, actions: { isDirty() { @@ -64,18 +99,29 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, { window.open("https://trello.com/app-key", "Trello App Key", ""); }, - getAuthToken() { - let appKey = this.get('config.appKey'); - let self = this; + onListCheckbox(id) { + let lists = this.get('config.lists'); + let list = lists.findBy('id', id); - if (is.empty(appKey)) { - $("#trello-appkey").addClass("error").focus(); + if (list !== null) { + Ember.set(list, 'included', !list.included); + } + }, + + auth() { + if (this.get('config.appKey') === "") { + $("#trello-appkey").addClass('error').focus(); + this.set('authenticated', false); return; } - Ember.$.getScript("https://api.trello.com/1/client.js?key=" + appKey, function() { + let self = this; + self.set('waiting', true); + + Ember.$.getScript("https://api.trello.com/1/client.js?key=" + this.get('config.appKey'), function() { Trello.authorize({ type: "popup", + // interactive: false, name: "Documize", scope: { read: true, @@ -85,22 +131,16 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, { persist: true, success: function() { self.set('authenticated', true); + self.set('config.token', Trello.token()); Trello.get("members/me/boards?fields=id,name,url,closed,prefs,idOrganization", function(boards) { + self.set('waiting', false); self.set('boards', boards.filterBy("closed", false)); - let board = boards.length ? boards[0] : null; - self.set('config.board', board); self.getBoardLists(); }); - - Trello.get("members/me/organizations", - function(orgs) { - self.set('orgs', orgs); - console.log(orgs); - }); - }, error: function(error) { + self.set('waiting', false); self.showNotification("Unable to authenticate"); console.log(error); } @@ -109,14 +149,16 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, { }, onBoardChange(board) { + this.set('isDirty', true); this.set('config.board', board); + this.set('config.lists', []); this.getBoardLists(); }, - onListChange(list) { - this.set('config.list', list); - this.getListCards(); - }, + // onListChange(list) { + // this.set('config.list', list); + // this.getListCards(); + // }, onCancel() { this.attrs.onCancel(); @@ -126,6 +168,10 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, { let page = this.get('page'); let meta = this.get('meta'); page.set('title', title); + // meta.set('rawBody', JSON.stringify(this.get("items"))); + meta.set('rawBody', ''); + meta.set('config', JSON.stringify(this.get('config'))); + meta.set('externalSource', true); this.attrs.onAction(page, meta); } diff --git a/app/app/styles/widget/widget-input.scss b/app/app/styles/widget/widget-input.scss index c3849ac0..95398f72 100644 --- a/app/app/styles/widget/widget-input.scss +++ b/app/app/styles/widget/widget-input.scss @@ -186,3 +186,13 @@ .form-divider { margin-top: 30px; } + + +.widget-checkbox { + color: $color-link; + cursor: pointer; +} + +.checkbox-gray { + color: $color-gray !important; +} \ No newline at end of file diff --git a/app/app/templates/components/section/trello/type-editor.hbs b/app/app/templates/components/section/trello/type-editor.hbs index 81dbad32..5be096b7 100644 --- a/app/app/templates/components/section/trello/type-editor.hbs +++ b/app/app/templates/components/section/trello/type-editor.hbs @@ -2,6 +2,8 @@ .board { width: 100%; padding: 10px; + white-space: nowrap; + overflow: auto } .board-title { @@ -14,7 +16,7 @@ background-color: #e2e4e6; padding: 10px; border-radius: 3px; - margin-top: 10px; + margin: 10px 10px 0 0; max-width: 300px; } @@ -22,23 +24,12 @@ font-weight: bold; color: #4c4c4c; font-size: 14px; - margin-bottom: 10px; + margin: 5px; } -.card { - color: #4c4c4c; - border-bottom: 1px solid #CDD2D4; - background-color: #fff; - border-radius: 3px; - padding: 7px 7px; - margin: 5px 0; - font-size: 14px; - font-family: "Helvetica Neue",Arial,Helvetica,sans-serif; - line-height: 18px; - overflow: hidden; - word-wrap: break-word; +.list-checkbox { + vertical-align: text-bottom; } - {{#section/base-editor document=document folder=folder page=page busy=waiting tip="Trello, yellow, mellow" isDirty=(action 'isDirty') onCancel=(action 'onCancel') onAction=(action 'onAction')}} @@ -47,63 +38,60 @@