Improved text module.
This commit is contained in:
parent
919b38a6d8
commit
75c4e9141c
3 changed files with 52 additions and 46 deletions
|
@ -2,8 +2,7 @@ $ = jQuery.sub()
|
||||||
|
|
||||||
class App.TextModuleUI extends App.Controller
|
class App.TextModuleUI extends App.Controller
|
||||||
events:
|
events:
|
||||||
'click [data-type=text_module_save]': 'create',
|
'click [data-type=save]': 'create',
|
||||||
'click [data-type=text_module_select]': 'select',
|
|
||||||
'click [data-type=text_module_delete]': 'delete',
|
'click [data-type=text_module_delete]': 'delete',
|
||||||
'click [data-type=edit]': 'select',
|
'click [data-type=edit]': 'select',
|
||||||
'dblclick [data-type=edit]': 'paste',
|
'dblclick [data-type=edit]': 'paste',
|
||||||
|
@ -30,77 +29,69 @@ class App.TextModuleUI extends App.Controller
|
||||||
render: =>
|
render: =>
|
||||||
|
|
||||||
ui = @
|
ui = @
|
||||||
a = $('textarea')
|
ui.Capture = false
|
||||||
|
ui.CaptureList = ''
|
||||||
|
|
||||||
|
# define elements to observe
|
||||||
|
inputElement = $('textarea')
|
||||||
|
|
||||||
# remember active text element
|
# remember active text element
|
||||||
a.bind('focusin', ->
|
inputElement.bind('focusin', ->
|
||||||
ui.area = $(@)
|
ui.area = $(@)
|
||||||
)
|
)
|
||||||
|
|
||||||
ui.C = false
|
inputElement.bind('keydown', (e) ->
|
||||||
ui.CList = ''
|
|
||||||
a.bind('keydown', (e) ->
|
|
||||||
|
|
||||||
# lisen if crtl is pressed
|
# lisen if crtl is pressed
|
||||||
if ui.C
|
if ui.Capture
|
||||||
key = App.ClipBoard.keycode( e.keyCode )
|
key = App.ClipBoard.keycode( e.keyCode )
|
||||||
|
|
||||||
# remove one char
|
# remove one char
|
||||||
if key is 'backspace'
|
if key is 'backspace'
|
||||||
ui.CList = ui.CList.slice( 0, -1 )
|
ui.CaptureList = ui.CaptureList.slice( 0, -1 )
|
||||||
|
|
||||||
# take over
|
# take over
|
||||||
else if key is 'enter'
|
else if key is 'enter'
|
||||||
# ui.CList = ui.CList.slice(0, -1)
|
objects = ui.objectSearch( ui.CaptureList )
|
||||||
objects = ui.objectSearch( ui.CList )
|
|
||||||
if objects[0]
|
if objects[0]
|
||||||
ui._insert( objects[0].content, ui )
|
ui._insert( objects[0].content, ui )
|
||||||
|
|
||||||
# reset search
|
# reset search
|
||||||
ui.CList = ''
|
ui.CaptureList = ''
|
||||||
ui.renderTable()
|
ui.renderTable()
|
||||||
|
|
||||||
# add char to search selection
|
# add char to search selection
|
||||||
else
|
else
|
||||||
ui.CList = ui.CList + key
|
ui.CaptureList = ui.CaptureList + key
|
||||||
|
|
||||||
console.log 'CTRL+', ui.CList
|
console.log 'CTRL+', ui.CaptureList
|
||||||
ui.el.find('#text-module-search').val( ui.CList )
|
ui.el.find('#text-module-search').val( ui.CaptureList )
|
||||||
ui.renderTable( ui.CList )
|
ui.renderTable( ui.CaptureList )
|
||||||
|
|
||||||
# start current search process
|
# start current search process
|
||||||
if e.ctrlKey
|
if e.ctrlKey
|
||||||
ui.C = true
|
ui.Capture = true
|
||||||
)
|
)
|
||||||
|
|
||||||
# start current search process
|
# start current search process
|
||||||
# do code to test other keys
|
# do code to test other keys
|
||||||
a.bind('keyup', (e) ->
|
inputElement.bind('keyup', (e) ->
|
||||||
if e.keyCode == 17
|
if e.keyCode == 17
|
||||||
console.log 'CTRL UP - pressed ', ui.CList
|
console.log 'CTRL UP - pressed ', ui.CaptureList
|
||||||
ui.CList = ''
|
ui.el.find('#text-module-search').val( '' )
|
||||||
ui.C = false
|
ui.CaptureList = ''
|
||||||
|
ui.Capture = false
|
||||||
ui.renderTable()
|
ui.renderTable()
|
||||||
)
|
)
|
||||||
|
|
||||||
@configure_attributes = [
|
|
||||||
{ name: 'text_module_id', display: '', tag: 'select', multiple: false, null: true, nulloption: true, relation: 'TextModule', class: 'span2', default: @text_module_id },
|
|
||||||
]
|
|
||||||
|
|
||||||
text_module = {}
|
|
||||||
if @text_module_id
|
|
||||||
text_module = App.Collection.find( 'TextModule', @text_module_id )
|
|
||||||
|
|
||||||
# insert data
|
# insert data
|
||||||
@html App.view('text_module')(
|
@html App.view('text_module')(
|
||||||
text_module: text_module,
|
|
||||||
search: @search,
|
search: @search,
|
||||||
)
|
)
|
||||||
|
|
||||||
# rerender if search phrase has changed
|
# rerender if search phrase has changed
|
||||||
@el.find('#text-module-search').unbind('keyup').bind('keyup', =>
|
@el.find('#text-module-search').unbind('keyup').bind('keyup', =>
|
||||||
search = $('#text-module-search').val();
|
search = $('#text-module-search').val()
|
||||||
console.log 'SEARCH', search
|
|
||||||
@renderTable( search )
|
@renderTable( search )
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -114,7 +105,6 @@ class App.TextModuleUI extends App.Controller
|
||||||
filterExtended: [ { name: search }, { content: search }, { keywords: search } ],
|
filterExtended: [ { name: search }, { content: search }, { keywords: search } ],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
renderTable: (search) =>
|
renderTable: (search) =>
|
||||||
|
|
||||||
objects = @objectSearch(search)
|
objects = @objectSearch(search)
|
||||||
|
@ -143,7 +133,6 @@ class App.TextModuleUI extends App.Controller
|
||||||
text_module = App.Collection.find( 'TextModule', params['text_module_id'] )
|
text_module = App.Collection.find( 'TextModule', params['text_module_id'] )
|
||||||
if confirm('Sure?')
|
if confirm('Sure?')
|
||||||
text_module.destroy()
|
text_module.destroy()
|
||||||
@text_module_id = undefined
|
|
||||||
@render()
|
@render()
|
||||||
|
|
||||||
select: (e) =>
|
select: (e) =>
|
||||||
|
@ -151,13 +140,14 @@ class App.TextModuleUI extends App.Controller
|
||||||
id = $(e.target).parents('tr').data('id')
|
id = $(e.target).parents('tr').data('id')
|
||||||
text_module = App.Collection.find( 'TextModule', id )
|
text_module = App.Collection.find( 'TextModule', id )
|
||||||
@el.find('#text-module-preview-content').val( text_module.content )
|
@el.find('#text-module-preview-content').val( text_module.content )
|
||||||
|
@el.find('#text_module_name').val( text_module.name )
|
||||||
|
|
||||||
create: (e) =>
|
create: (e) =>
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
|
||||||
# get params
|
# get params
|
||||||
params = @formParam(e.target)
|
params = @formParam(e.target)
|
||||||
name = params['text_module_name']
|
name = params['name']
|
||||||
# delete params['text_module_name']
|
# delete params['text_module_name']
|
||||||
|
|
||||||
text_module = App.Collection.findByAttribute( 'TextModule', 'name', name )
|
text_module = App.Collection.findByAttribute( 'TextModule', 'name', name )
|
||||||
|
@ -165,10 +155,10 @@ class App.TextModuleUI extends App.Controller
|
||||||
text_module = new App.TextModule
|
text_module = new App.TextModule
|
||||||
|
|
||||||
content = App.ClipBoard.getSelectedLast()
|
content = App.ClipBoard.getSelectedLast()
|
||||||
if content
|
|
||||||
text_module.load(
|
text_module.load(
|
||||||
name: params['text_module_name']
|
name: params['name'],
|
||||||
content: content
|
content: content,
|
||||||
|
active: true,
|
||||||
)
|
)
|
||||||
|
|
||||||
# validate form
|
# validate form
|
||||||
|
@ -181,7 +171,6 @@ class App.TextModuleUI extends App.Controller
|
||||||
ui = @
|
ui = @
|
||||||
text_module.save(
|
text_module.save(
|
||||||
success: ->
|
success: ->
|
||||||
ui.text_module_id = @.id
|
|
||||||
ui.render()
|
ui.render()
|
||||||
ui.log 'save success!'
|
ui.log 'save success!'
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,22 @@ class _Singleton
|
||||||
# bind to fill selected text into
|
# bind to fill selected text into
|
||||||
bind: (el) ->
|
bind: (el) ->
|
||||||
$(el).bind('mouseup', =>
|
$(el).bind('mouseup', =>
|
||||||
|
|
||||||
|
# check selection on mouse up
|
||||||
|
@selection = @_getSelected()
|
||||||
|
if @selection
|
||||||
|
@selectionLast = @selection
|
||||||
|
)
|
||||||
|
$(el).bind('keyup', (e) =>
|
||||||
|
|
||||||
|
# check selection on sonder key
|
||||||
|
if e.keyCode == 91
|
||||||
|
@selection = @_getSelected()
|
||||||
|
if @selection
|
||||||
|
@selectionLast = @selection
|
||||||
|
|
||||||
|
# check selection of arrow keys
|
||||||
|
if e.keyCode == 37 || e.keyCode == 38 || e.keyCode == 39 || e.keyCode == 40
|
||||||
@selection = @_getSelected()
|
@selection = @_getSelected()
|
||||||
if @selection
|
if @selection
|
||||||
@selectionLast = @selection
|
@selectionLast = @selection
|
||||||
|
|
|
@ -8,13 +8,14 @@
|
||||||
<!--<button type="submit" class="btn" data-type="text_module_edit"><%- @T( 'Edit' ) %></button>-->
|
<!--<button type="submit" class="btn" data-type="text_module_edit"><%- @T( 'Edit' ) %></button>-->
|
||||||
<!--
|
<!--
|
||||||
<button type="submit" class="btn" data-type="text_module_delete"><%- @T( 'Delete' ) %></button>
|
<button type="submit" class="btn" data-type="text_module_delete"><%- @T( 'Delete' ) %></button>
|
||||||
<button type="submit" class="btn" data-type="text_module_select"><%- @T( 'Apply' ) %></button>
|
|
||||||
-->
|
-->
|
||||||
<%- @T( 'Preview ') %>
|
<%- @T( 'Preview ') %>
|
||||||
<br>
|
<br>
|
||||||
<textarea id="text-module-preview-content" class="span2"></textarea>
|
<textarea id="text-module-preview-content" class="span2"></textarea>
|
||||||
<hr>
|
<hr>
|
||||||
|
<form>
|
||||||
<label class="" for="text_module_name"><%- @T( 'Save as Text Module' ) %></label>
|
<label class="" for="text_module_name"><%- @T( 'Save as Text Module' ) %></label>
|
||||||
<input type="text" name="text_module_name" id="text_module_name" class="span2" value="<%= @text_module.name %>"/>
|
<input type="text" name="name" id="text_module_name" class="span2" value=""/>
|
||||||
<button type="submit" class="btn" data-type="text_module_save"><%- @T( 'Save' ) %></button>
|
<button type="submit" class="btn" data-type="save"><%- @T( 'Save' ) %></button>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
Loading…
Reference in a new issue