use jquery-tmpl

This commit is contained in:
jysperm
2015-01-31 15:28:10 +08:00
parent 8b73b3a18d
commit a8de66c2b7
5 changed files with 57 additions and 50 deletions

View File

@@ -6,6 +6,7 @@
"underscore": "~1.7.0", "underscore": "~1.7.0",
"jquery": "~2.1.2", "jquery": "~2.1.2",
"backbone": "~1.1.2", "backbone": "~1.1.2",
"moment": "~2.9.0" "moment": "~2.9.0",
"jquery-tmpl": "*"
} }
} }

View File

@@ -64,6 +64,12 @@ $ ->
alert jqXHR.statusText alert jqXHR.statusText
.success callback .success callback
tmpl: (selector) ->
cache = $(selector).template()
return (view_data) ->
return $.tmpl cache, view_data
RP.initLocale() RP.initLocale()
$('nav a').each -> $('nav a').each ->

View File

@@ -16,8 +16,8 @@ $ ->
idAttribute: '_id' idAttribute: '_id'
initialize: -> initialize: ->
@replies = new ReplyCollection @replies = new ReplyCollection()
url: @url() + '/replies' @replies.url = @url() + '/replies'
@once 'change', => @once 'change', =>
@replies.reset @get 'replies' @replies.reset @get 'replies'
@@ -45,7 +45,7 @@ $ ->
className: 'list-group-item clearfix' className: 'list-group-item clearfix'
initialize: -> initialize: ->
@template = _.template $('#reply-template').html() @template = RP.tmpl '#reply-template'
@model.on 'change', @render.bind @ @model.on 'change', @render.bind @
render: -> render: ->
@@ -70,10 +70,10 @@ $ ->
@model.fetch() @model.fetch()
@templateContent = _.template $('#content-template').html() @templateContent = RP.tmpl '#content-template'
@templateActions = _.template $('#actions-template').html() @templateActions = RP.tmpl '#actions-template'
@templateAccountInfo = _.template $('#account-info-template').html() @templateAccountInfo = RP.tmpl '#account-info-template'
@templateMembers = _.template $('#members-template').html() @templateMembers = RP.tmpl '#members-template'
render: -> render: ->
view_data = @model.toJSON() view_data = @model.toJSON()
@@ -108,7 +108,7 @@ $ ->
tagName: 'tr' tagName: 'tr'
initialize: -> initialize: ->
@template = _.template $('#list-item-template').html() @template = RP.tmpl '#list-item-template'
render: -> render: ->
view_data = @model.toJSON() view_data = @model.toJSON()

View File

@@ -23,8 +23,8 @@ prepend sidebar
append footer append footer
script(src='/script/ticket.js') script(src='/script/ticket.js')
script(id='list-item-template', type='text/template') script(id='list-item-template', type='text/x-jquery-tmpl')
td td
a(href='/ticket/view/{{_id}}') {{title}} a(href='/ticket/view/${_id}') ${title}
td td
span(class='text-{{color}}') {{RP.t('ticket_status.' + status)}} span(class='text-${color}') ${RP.t('ticket_status.' + status)}

View File

@@ -26,64 +26,64 @@ prepend sidebar
append footer append footer
script(src='/bower_components/moment/moment.js') script(src='/bower_components/moment/moment.js')
script(src='/script/ticket.js') script(src='/script/ticket.js')
script(id='content-template', type='text/template') script(id='content-template', type='text/x-jquery-tmpl')
header header
| {{title}}   | ${title}  
span.small(class='text-{{color}}') {{RP.t('ticket_status.' + status)}} span.small(class='text-${color}') ${RP.t('ticket_status.' + status)}
p {:content_html}} p {{html content_html}}
script(id='reply-template', type='text/template') script(id='reply-template', type='text/x-jquery-tmpl')
a.pull-left a.pull-left
img.img-avatar(src='{{account.preferences.avatar_url}}') img.img-avatar(src='${account.preferences.avatar_url}')
.list-content .list-content
{% if (content_html) { %} {{if content_html}}
p {:content_html}} p {{html content_html}}
{% } else { %} {{else}}
p {{content}} p ${content}
{% }; %} {{/if}}
p p
span.label.label-info {{account.username}} span.label.label-info ${account.username}
{% if (created_at) { %} {{if created_at}}
span.label.label-default(title='{{created_at}}') {{moment(created_at).fromNow()}} span.label.label-default(title='${created_at}') ${moment(created_at).fromNow()}
{% } else { %} {{else}}
span.label.label-default ... span.label.label-default ...
{% }; %} {{/if}}
script(id='actions-template', type='text/template') script(id='actions-template', type='text/x-jquery-tmpl')
{% if (status != 'closed') { %} {{if status != 'closed'}}
header= t('ticket.create_reply') header= t('ticket.create_reply')
{% }; %} {{/if}}
form.form-horizontal form.form-horizontal
{% if (status != 'closed') { %} {{if status != 'closed'}}
.form-group.padding .form-group.padding
textarea.form-control(name='content', rows='5') textarea.form-control(name='content', rows='5')
{% }; %} {{/if}}
.form-group.padding .form-group.padding
{% if (status == 'closed') { %} {{if status == 'closed'}}
button(disabled).btn.btn-lg.btn-primary= t('ticket_status.closed') button(disabled).btn.btn-lg.btn-primary= t('ticket_status.closed')
{% } else { %} {{else}}
button.btn.btn-lg.btn-primary.action-reply(type='button')= t('ticket.create_reply') button.btn.btn-lg.btn-primary.action-reply(type='button')= t('ticket.create_reply')
button(type='button', data-status='closed').btn.btn-lg.btn-danger.action-status= t('ticket.close_ticket') button(type='button', data-status='closed').btn.btn-lg.btn-danger.action-status= t('ticket.close_ticket')
{% }; %} {{/if}}
if account.isAdmin() if account.isAdmin()
{% if (status == 'open' || status == 'pending') { %} {{if status == 'open' || status == 'pending'}}
button(type='button', data-status='finish').btn.btn-lg.btn-success.action-status= t('ticket.finish_ticket') button(type='button', data-status='finish').btn.btn-lg.btn-success.action-status= t('ticket.finish_ticket')
{% }; %} {{/if}}
{% if (status == 'closed') { %} {{if status == 'closed'}}
button(type='button', data-status='open').btn.btn-lg.btn-success.action-status= t('ticket.reopen_ticket') button(type='button', data-status='open').btn.btn-lg.btn-success.action-status= t('ticket.reopen_ticket')
{% }; %} {{/if}}
script(id='account-info-template', type='text/template') script(id='account-info-template', type='text/x-jquery-tmpl')
{% if (account) { %} {{if account}}
a.pull-left a.pull-left
img.img-avatar(src='{{account.preferences.avatar_url}}') img.img-avatar(src='${account.preferences.avatar_url}')
p p
span.label.label-info {{account.username}} span.label.label-info ${account.username}
br br
span.label.label-default(title='{{created_at}}') {{moment(created_at).fromNow()}} span.label.label-default(title='${created_at}') ${moment(created_at).fromNow()}
{% }; %} {{/if}}
script(id='members-template', type='text/template') script(id='members-template', type='text/x-jquery-tmpl')
header= t('ticket.members') header= t('ticket.members')
{% members.forEach(function(member) { %} {{each members}}
a.pull-left a.pull-left
img.img-avatar(src='{{member.preferences.avatar_url}}', alt='{{member.username}}') img.img-avatar(src='${$value.preferences.avatar_url}', alt='${$value.username}')
{% }); %} {{/each}}