Fixed group default selection in twitter/facebook admin screen.
This commit is contained in:
parent
97c516efcc
commit
082e087797
2 changed files with 239 additions and 188 deletions
|
@ -66,6 +66,7 @@ class Index extends App.ControllerSubContent
|
||||||
|
|
||||||
if @channel_id
|
if @channel_id
|
||||||
@edit(undefined, @channel_id)
|
@edit(undefined, @channel_id)
|
||||||
|
@channel_id = undefined
|
||||||
|
|
||||||
show: (params) =>
|
show: (params) =>
|
||||||
for key, value of params
|
for key, value of params
|
||||||
|
@ -73,48 +74,10 @@ class Index extends App.ControllerSubContent
|
||||||
@[key] = value
|
@[key] = value
|
||||||
|
|
||||||
configApp: =>
|
configApp: =>
|
||||||
external_credential = App.ExternalCredential.findByAttribute('name', 'facebook')
|
new AppConfig(
|
||||||
contentInline = $(App.view('facebook/app_config')(
|
|
||||||
external_credential: external_credential
|
|
||||||
callbackUrl: @callbackUrl
|
|
||||||
))
|
|
||||||
contentInline.find('.js-select').on('click', (e) =>
|
|
||||||
@selectAll(e)
|
|
||||||
)
|
|
||||||
modal = new App.ControllerModal(
|
|
||||||
head: 'Connect Facebook App'
|
|
||||||
container: @el.parents('.content')
|
container: @el.parents('.content')
|
||||||
contentInline: contentInline
|
callbackUrl: @callbackUrl
|
||||||
shown: true
|
load: @load
|
||||||
button: 'Connect'
|
|
||||||
cancel: true
|
|
||||||
small: true
|
|
||||||
onSubmit: (e) =>
|
|
||||||
@formDisable(e)
|
|
||||||
|
|
||||||
# verify app credentals
|
|
||||||
@ajax(
|
|
||||||
id: 'facebook_app_verify'
|
|
||||||
type: 'POST'
|
|
||||||
url: "#{@apiPath}/external_credentials/facebook/app_verify"
|
|
||||||
data: JSON.stringify(modal.formParams())
|
|
||||||
processData: true
|
|
||||||
success: (data, status, xhr) =>
|
|
||||||
if data.attributes
|
|
||||||
if !external_credential
|
|
||||||
external_credential = new App.ExternalCredential
|
|
||||||
external_credential.load(name: 'facebook', credentials: modal.formParams())
|
|
||||||
external_credential.save(
|
|
||||||
done: =>
|
|
||||||
@load()
|
|
||||||
modal.close()
|
|
||||||
fail: ->
|
|
||||||
modal.element().find('.alert').removeClass('hidden').text('Unable to create entry.')
|
|
||||||
)
|
|
||||||
return
|
|
||||||
@formEnable(e)
|
|
||||||
modal.element().find('.alert').removeClass('hidden').text(data.error || 'Unable to verify App.')
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
new: (e) ->
|
new: (e) ->
|
||||||
|
@ -128,59 +91,11 @@ class Index extends App.ControllerSubContent
|
||||||
if !channel
|
if !channel
|
||||||
@navigate '#channels/facebook'
|
@navigate '#channels/facebook'
|
||||||
return
|
return
|
||||||
if !channel.options.sync
|
|
||||||
channel.options.sync = {}
|
|
||||||
if !channel.options.sync.wall
|
|
||||||
channel.options.sync.wall = {}
|
|
||||||
if !channel.options.sync.pages
|
|
||||||
channel.options.sync.pages = {}
|
|
||||||
content = $( App.view('facebook/account_edit')(channel: channel) )
|
|
||||||
|
|
||||||
groupSelection = (selected_id, el, prefix) ->
|
new AccountEdit(
|
||||||
selection = App.UiElement.select.render(
|
channel: channel
|
||||||
name: "#{prefix}::group_id"
|
|
||||||
multiple: false
|
|
||||||
limit: 100
|
|
||||||
null: false
|
|
||||||
relation: 'Group'
|
|
||||||
nulloption: true
|
|
||||||
value: selected_id
|
|
||||||
class: 'form-control--small'
|
|
||||||
)
|
|
||||||
el.html(selection)
|
|
||||||
|
|
||||||
groupSelection(channel.options.sync.wall.group_id, content.find('.js-wall .js-groups'), 'wall')
|
|
||||||
if channel.options.pages
|
|
||||||
for page in channel.options.pages
|
|
||||||
pageConfigured = false
|
|
||||||
for page_id, pageParams of channel.options.sync.pages
|
|
||||||
if page.id is page_id
|
|
||||||
pageConfigured = true
|
|
||||||
groupSelection(pageParams.group_id, content.find(".js-groups[data-page-id=#{page.id}]"), "pages::#{page.id}")
|
|
||||||
if !pageConfigured
|
|
||||||
groupSelection('', content.find(".js-groups[data-page-id=#{page.id}]"), "pages::#{page.id}")
|
|
||||||
|
|
||||||
modal = new App.ControllerModal(
|
|
||||||
head: 'Facebook Account'
|
|
||||||
container: @el.parents('.content')
|
container: @el.parents('.content')
|
||||||
contentInline: content
|
load: @load
|
||||||
shown: true
|
|
||||||
cancel: true
|
|
||||||
onSubmit: (e) =>
|
|
||||||
@formDisable(e)
|
|
||||||
channel.options.sync = modal.formParams()
|
|
||||||
@ajax(
|
|
||||||
id: 'channel_facebook_update'
|
|
||||||
type: 'POST'
|
|
||||||
url: "#{@apiPath}/channels/facebook_verify/#{channel.id}"
|
|
||||||
data: JSON.stringify(channel.attributes())
|
|
||||||
processData: true
|
|
||||||
success: (data, status, xhr) =>
|
|
||||||
@load()
|
|
||||||
modal.close()
|
|
||||||
fail: =>
|
|
||||||
@formEnable(e)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
delete: (e) =>
|
delete: (e) =>
|
||||||
|
@ -199,4 +114,115 @@ class Index extends App.ControllerSubContent
|
||||||
container: @el.closest('.content')
|
container: @el.closest('.content')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
class AppConfig extends App.ControllerModal
|
||||||
|
head: 'Connect Facebook App'
|
||||||
|
shown: true
|
||||||
|
button: 'Connect'
|
||||||
|
buttonCancel: true
|
||||||
|
small: true
|
||||||
|
|
||||||
|
content: ->
|
||||||
|
@external_credential = App.ExternalCredential.findByAttribute('name', 'facebook')
|
||||||
|
content = $(App.view('facebook/app_config')(
|
||||||
|
external_credential: @external_credential
|
||||||
|
callbackUrl: @callbackUrl
|
||||||
|
))
|
||||||
|
content.find('.js-select').on('click', (e) =>
|
||||||
|
@selectAll(e)
|
||||||
|
)
|
||||||
|
content
|
||||||
|
|
||||||
|
onClosed: =>
|
||||||
|
return if !@isChanged
|
||||||
|
@isChanged = false
|
||||||
|
@load()
|
||||||
|
|
||||||
|
onSubmit: (e) =>
|
||||||
|
@formDisable(e)
|
||||||
|
|
||||||
|
# verify app credentals
|
||||||
|
@ajax(
|
||||||
|
id: 'facebook_app_verify'
|
||||||
|
type: 'POST'
|
||||||
|
url: "#{@apiPath}/external_credentials/facebook/app_verify"
|
||||||
|
data: JSON.stringify(@formParams())
|
||||||
|
processData: true
|
||||||
|
success: (data, status, xhr) =>
|
||||||
|
if data.attributes
|
||||||
|
if !@external_credential
|
||||||
|
@external_credential = new App.ExternalCredential
|
||||||
|
@external_credential.load(name: 'facebook', credentials: @formParams())
|
||||||
|
@external_credential.save(
|
||||||
|
done: =>
|
||||||
|
@isChanged = true
|
||||||
|
@close()
|
||||||
|
fail: ->
|
||||||
|
@el.find('.alert').removeClass('hidden').text('Unable to create entry.')
|
||||||
|
)
|
||||||
|
return
|
||||||
|
@formEnable(e)
|
||||||
|
@el.find('.alert').removeClass('hidden').text(data.error || 'Unable to verify App.')
|
||||||
|
)
|
||||||
|
|
||||||
|
class AccountEdit extends App.ControllerModal
|
||||||
|
head: 'Facebook Account'
|
||||||
|
shown: true
|
||||||
|
buttonCancel: true
|
||||||
|
|
||||||
|
content: ->
|
||||||
|
if !@channel.options.sync
|
||||||
|
@channel.options.sync = {}
|
||||||
|
if !@channel.options.sync.wall
|
||||||
|
@channel.options.sync.wall = {}
|
||||||
|
if !@channel.options.sync.pages
|
||||||
|
@channel.options.sync.pages = {}
|
||||||
|
content = $( App.view('facebook/account_edit')(channel: @channel) )
|
||||||
|
|
||||||
|
groupSelection = (selected_id, el, prefix) ->
|
||||||
|
selection = App.UiElement.select.render(
|
||||||
|
name: "#{prefix}::group_id"
|
||||||
|
multiple: false
|
||||||
|
limit: 100
|
||||||
|
null: false
|
||||||
|
relation: 'Group'
|
||||||
|
nulloption: true
|
||||||
|
value: selected_id
|
||||||
|
class: 'form-control--small'
|
||||||
|
)
|
||||||
|
el.html(selection)
|
||||||
|
|
||||||
|
groupSelection(@channel.options.sync.wall.group_id, content.find('.js-wall .js-groups'), 'wall')
|
||||||
|
if @channel.options.pages
|
||||||
|
for page in @channel.options.pages
|
||||||
|
pageConfigured = false
|
||||||
|
for page_id, pageParams of @channel.options.sync.pages
|
||||||
|
if page.id is page_id
|
||||||
|
pageConfigured = true
|
||||||
|
groupSelection(pageParams.group_id, content.find(".js-groups[data-page-id=#{page.id}]"), "pages::#{page.id}")
|
||||||
|
if !pageConfigured
|
||||||
|
groupSelection('', content.find(".js-groups[data-page-id=#{page.id}]"), "pages::#{page.id}")
|
||||||
|
|
||||||
|
content
|
||||||
|
|
||||||
|
onClosed: =>
|
||||||
|
return if !@isChanged
|
||||||
|
@isChanged = false
|
||||||
|
@load()
|
||||||
|
|
||||||
|
onSubmit: (e) =>
|
||||||
|
@formDisable(e)
|
||||||
|
@channel.options.sync = @formParams()
|
||||||
|
@ajax(
|
||||||
|
id: 'channel_facebook_update'
|
||||||
|
type: 'POST'
|
||||||
|
url: "#{@apiPath}/channels/facebook_verify/#{@channel.id}"
|
||||||
|
data: JSON.stringify(@channel.attributes())
|
||||||
|
processData: true
|
||||||
|
success: (data, status, xhr) =>
|
||||||
|
@isChanged = true
|
||||||
|
@close()
|
||||||
|
fail: =>
|
||||||
|
@formEnable(e)
|
||||||
|
)
|
||||||
|
|
||||||
App.Config.set('Facebook', { prio: 5100, name: 'Facebook', parent: '#channels', target: '#channels/facebook', controller: Index, permission: ['admin.channel_facebook'] }, 'NavBarAdmin')
|
App.Config.set('Facebook', { prio: 5100, name: 'Facebook', parent: '#channels', target: '#channels/facebook', controller: Index, permission: ['admin.channel_facebook'] }, 'NavBarAdmin')
|
||||||
|
|
|
@ -65,6 +65,7 @@ class Index extends App.ControllerSubContent
|
||||||
|
|
||||||
if @channel_id
|
if @channel_id
|
||||||
@edit(undefined, @channel_id)
|
@edit(undefined, @channel_id)
|
||||||
|
@channel_id = undefined
|
||||||
|
|
||||||
show: (params) =>
|
show: (params) =>
|
||||||
for key, value of params
|
for key, value of params
|
||||||
|
@ -72,48 +73,10 @@ class Index extends App.ControllerSubContent
|
||||||
@[key] = value
|
@[key] = value
|
||||||
|
|
||||||
configApp: =>
|
configApp: =>
|
||||||
external_credential = App.ExternalCredential.findByAttribute('name', 'twitter')
|
new AppConfig(
|
||||||
contentInline = $(App.view('twitter/app_config')(
|
|
||||||
external_credential: external_credential
|
|
||||||
callbackUrl: @callbackUrl
|
|
||||||
))
|
|
||||||
contentInline.find('.js-select').on('click', (e) =>
|
|
||||||
@selectAll(e)
|
|
||||||
)
|
|
||||||
modal = new App.ControllerModal(
|
|
||||||
head: 'Connect Twitter App'
|
|
||||||
container: @el.parents('.content')
|
container: @el.parents('.content')
|
||||||
contentInline: contentInline
|
callbackUrl: @callbackUrl
|
||||||
shown: true
|
load: @load
|
||||||
button: 'Connect'
|
|
||||||
cancel: true
|
|
||||||
small: true
|
|
||||||
onSubmit: (e) =>
|
|
||||||
@formDisable(e)
|
|
||||||
|
|
||||||
# verify app credentals
|
|
||||||
@ajax(
|
|
||||||
id: 'twitter_app_verify'
|
|
||||||
type: 'POST'
|
|
||||||
url: "#{@apiPath}/external_credentials/twitter/app_verify"
|
|
||||||
data: JSON.stringify(modal.formParams())
|
|
||||||
processData: true
|
|
||||||
success: (data, status, xhr) =>
|
|
||||||
if data.attributes
|
|
||||||
if !external_credential
|
|
||||||
external_credential = new App.ExternalCredential
|
|
||||||
external_credential.load(name: 'twitter', credentials: modal.formParams())
|
|
||||||
external_credential.save(
|
|
||||||
done: =>
|
|
||||||
@load()
|
|
||||||
modal.close()
|
|
||||||
fail: ->
|
|
||||||
modal.element().find('.alert').removeClass('hidden').text('Unable to create entry.')
|
|
||||||
)
|
|
||||||
return
|
|
||||||
@formEnable(e)
|
|
||||||
modal.element().find('.alert').removeClass('hidden').text(data.error || 'Unable to verify App.')
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
new: (e) ->
|
new: (e) ->
|
||||||
|
@ -127,7 +90,86 @@ class Index extends App.ControllerSubContent
|
||||||
if !channel
|
if !channel
|
||||||
@navigate '#channels/twitter'
|
@navigate '#channels/twitter'
|
||||||
return
|
return
|
||||||
content = $( App.view('twitter/account_edit')(channel: channel) )
|
|
||||||
|
new AccountEdit(
|
||||||
|
channel: channel
|
||||||
|
container: @el.parents('.content')
|
||||||
|
load: @load
|
||||||
|
)
|
||||||
|
|
||||||
|
delete: (e) =>
|
||||||
|
e.preventDefault()
|
||||||
|
id = $(e.target).closest('.action').data('id')
|
||||||
|
item = App.Channel.find(id)
|
||||||
|
new App.ControllerGenericDestroyConfirm(
|
||||||
|
item: item
|
||||||
|
container: @el.closest('.content')
|
||||||
|
callback: @load
|
||||||
|
)
|
||||||
|
|
||||||
|
description: (e) =>
|
||||||
|
new App.ControllerGenericDescription(
|
||||||
|
description: App.Twitter.description
|
||||||
|
container: @el.closest('.content')
|
||||||
|
)
|
||||||
|
|
||||||
|
class AppConfig extends App.ControllerModal
|
||||||
|
head: 'Connect Twitter App'
|
||||||
|
shown: true
|
||||||
|
button: 'Connect'
|
||||||
|
buttonCancel: true
|
||||||
|
small: true
|
||||||
|
|
||||||
|
content: ->
|
||||||
|
@external_credential = App.ExternalCredential.findByAttribute('name', 'twitter')
|
||||||
|
content = $(App.view('twitter/app_config')(
|
||||||
|
external_credential: @external_credential
|
||||||
|
callbackUrl: @callbackUrl
|
||||||
|
))
|
||||||
|
content.find('.js-select').on('click', (e) =>
|
||||||
|
@selectAll(e)
|
||||||
|
)
|
||||||
|
content
|
||||||
|
|
||||||
|
onClosed: =>
|
||||||
|
return if !@isChanged
|
||||||
|
@isChanged = false
|
||||||
|
@load()
|
||||||
|
|
||||||
|
onSubmit: (e) =>
|
||||||
|
@formDisable(e)
|
||||||
|
|
||||||
|
# verify app credentals
|
||||||
|
@ajax(
|
||||||
|
id: 'twitter_app_verify'
|
||||||
|
type: 'POST'
|
||||||
|
url: "#{@apiPath}/external_credentials/twitter/app_verify"
|
||||||
|
data: JSON.stringify(@formParams())
|
||||||
|
processData: true
|
||||||
|
success: (data, status, xhr) =>
|
||||||
|
if data.attributes
|
||||||
|
if !@external_credential
|
||||||
|
@external_credential = new App.ExternalCredential
|
||||||
|
@external_credential.load(name: 'twitter', credentials: @formParams())
|
||||||
|
@external_credential.save(
|
||||||
|
done: =>
|
||||||
|
@isChanged = true
|
||||||
|
@close()
|
||||||
|
fail: =>
|
||||||
|
@el.find('.alert').removeClass('hidden').text('Unable to create entry.')
|
||||||
|
)
|
||||||
|
return
|
||||||
|
@formEnable(e)
|
||||||
|
@el.find('.alert').removeClass('hidden').text(data.error || 'Unable to verify App.')
|
||||||
|
)
|
||||||
|
|
||||||
|
class AccountEdit extends App.ControllerModal
|
||||||
|
head: 'Twitter Account'
|
||||||
|
shown: true
|
||||||
|
buttonCancel: true
|
||||||
|
|
||||||
|
content: ->
|
||||||
|
content = $( App.view('twitter/account_edit')(channel: @channel) )
|
||||||
|
|
||||||
createGroupSelection = (selected_id, prefix) ->
|
createGroupSelection = (selected_id, prefix) ->
|
||||||
return App.UiElement.select.render(
|
return App.UiElement.select.render(
|
||||||
|
@ -166,8 +208,8 @@ class Index extends App.ControllerSubContent
|
||||||
select = createGroupSelection(item.group_id, 'search')
|
select = createGroupSelection(item.group_id, 'search')
|
||||||
content.find(".js-termGroup[data-index=\"#{i}\"]").replaceWith select
|
content.find(".js-termGroup[data-index=\"#{i}\"]").replaceWith select
|
||||||
|
|
||||||
if channel.options && channel.options.sync && channel.options.sync.search
|
if @channel.options && @channel.options.sync && @channel.options.sync.search
|
||||||
@searchTerms = channel.options.sync.search
|
@searchTerms = @channel.options.sync.search
|
||||||
else
|
else
|
||||||
@searchTerms = []
|
@searchTerms = []
|
||||||
|
|
||||||
|
@ -176,60 +218,43 @@ class Index extends App.ControllerSubContent
|
||||||
content.find('.js-searchTermAdd').click(addSearchTerm)
|
content.find('.js-searchTermAdd').click(addSearchTerm)
|
||||||
content.find('.js-searchTermList').on('click', '.js-searchTermRemove', removeSearchTerm)
|
content.find('.js-searchTermList').on('click', '.js-searchTermRemove', removeSearchTerm)
|
||||||
|
|
||||||
content.find('.js-mentionsGroup').replaceWith createGroupSelection(channel.options.sync.mentions.group_id, 'mentions')
|
content.find('.js-mentionsGroup').replaceWith createGroupSelection(@channel.options.sync.mentions.group_id, 'mentions')
|
||||||
content.find('.js-directMessagesGroup').replaceWith createGroupSelection(channel.options.sync.direct_messages.group_id, 'direct_messages')
|
content.find('.js-directMessagesGroup').replaceWith createGroupSelection(@channel.options.sync.direct_messages.group_id, 'direct_messages')
|
||||||
|
content
|
||||||
|
|
||||||
modal = new App.ControllerModal(
|
onClosed: =>
|
||||||
head: 'Twitter Account'
|
return if !@isChanged
|
||||||
container: @el.parents('.content')
|
@isChanged = false
|
||||||
contentInline: content
|
@load()
|
||||||
shown: true
|
|
||||||
cancel: true
|
|
||||||
onSubmit: (e) =>
|
|
||||||
@formDisable(e)
|
|
||||||
params = modal.formParams()
|
|
||||||
search = []
|
|
||||||
position = 0
|
|
||||||
if params.search
|
|
||||||
if _.isArray(params.search.term)
|
|
||||||
for key in params.search.term
|
|
||||||
item =
|
|
||||||
term: params.search.term[position]
|
|
||||||
group_id: params.search.group_id[position]
|
|
||||||
search.push item
|
|
||||||
position += 1
|
|
||||||
else
|
|
||||||
search.push params.search
|
|
||||||
params.search = search
|
|
||||||
channel.options.sync = params
|
|
||||||
@ajax(
|
|
||||||
id: 'channel_twitter_update'
|
|
||||||
type: 'POST'
|
|
||||||
url: "#{@apiPath}/channels/twitter_verify/#{channel.id}"
|
|
||||||
data: JSON.stringify(channel.attributes())
|
|
||||||
processData: true
|
|
||||||
success: (data, status, xhr) =>
|
|
||||||
@load()
|
|
||||||
modal.close()
|
|
||||||
fail: =>
|
|
||||||
@formEnable(e)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
delete: (e) =>
|
onSubmit: (e) =>
|
||||||
e.preventDefault()
|
@formDisable(e)
|
||||||
id = $(e.target).closest('.action').data('id')
|
params = @formParams()
|
||||||
item = App.Channel.find(id)
|
search = []
|
||||||
new App.ControllerGenericDestroyConfirm(
|
position = 0
|
||||||
item: item
|
if params.search
|
||||||
container: @el.closest('.content')
|
if _.isArray(params.search.term)
|
||||||
callback: @load
|
for key in params.search.term
|
||||||
)
|
item =
|
||||||
|
term: params.search.term[position]
|
||||||
description: (e) =>
|
group_id: params.search.group_id[position]
|
||||||
new App.ControllerGenericDescription(
|
search.push item
|
||||||
description: App.Twitter.description
|
position += 1
|
||||||
container: @el.closest('.content')
|
else
|
||||||
|
search.push params.search
|
||||||
|
params.search = search
|
||||||
|
@channel.options.sync = params
|
||||||
|
@ajax(
|
||||||
|
id: 'channel_twitter_update'
|
||||||
|
type: 'POST'
|
||||||
|
url: "#{@apiPath}/channels/twitter_verify/#{@channel.id}"
|
||||||
|
data: JSON.stringify(@channel.attributes())
|
||||||
|
processData: true
|
||||||
|
success: (data, status, xhr) =>
|
||||||
|
@isChanged = true
|
||||||
|
@close()
|
||||||
|
fail: =>
|
||||||
|
@formEnable(e)
|
||||||
)
|
)
|
||||||
|
|
||||||
App.Config.set('Twitter', { prio: 5000, name: 'Twitter', parent: '#channels', target: '#channels/twitter', controller: Index, permission: ['admin.channel_twitter'] }, 'NavBarAdmin')
|
App.Config.set('Twitter', { prio: 5000, name: 'Twitter', parent: '#channels', target: '#channels/twitter', controller: Index, permission: ['admin.channel_twitter'] }, 'NavBarAdmin')
|
||||||
|
|
Loading…
Reference in a new issue