Browse Source

Init version of tags.

Martin Edenhofer 12 years ago
parent
commit
4aae8cb3e2

+ 30 - 0
app/assets/javascripts/app/controllers/_application_controller_form.js.coffee

@@ -285,6 +285,36 @@ class App.ControllerForm extends App.Controller
     else if attribute.tag is 'textarea'
       item = $( App.view('generic/textarea')( attribute: attribute ) )
 
+    # tag
+    else if attribute.tag is 'tag'
+      item = $( App.view('generic/input')( attribute: attribute ) )
+      a = =>
+        siteUpdate = (reorder) =>
+          container = document.getElementById( attribute.id + "_tagsinput" )
+          if reorder
+            $('#' + attribute.id + "_tagsinput" ).height( 20 )
+          height = container.scrollHeight
+          $('#' + attribute.id + "_tagsinput" ).height( height - 16 )
+
+        onAddTag = =>
+          siteUpdate()
+
+        onRemoveTag = =>
+          siteUpdate(true)
+
+        w = $('#' + attribute.id).width()
+        h = $('#' + attribute.id).height()
+        $('#' + attribute.id).tagsInput(
+          width: w + 'px'
+#          height: (h + 30 )+ 'px'
+          onAddTag:    onAddTag
+          onRemoveTag: onRemoveTag
+        )
+        siteUpdate(true)
+
+      @delay( a, 600 )
+
+
     # autocompletion
     else if attribute.tag is 'autocompletion'
       item = $( App.view('generic/autocompletion')( attribute: attribute ) )

+ 1 - 0
app/assets/javascripts/app/controllers/agent_ticket_create.js.coffee

@@ -103,6 +103,7 @@ class Index extends App.Controller
       { name: 'customer_id',        display: 'Customer', tag: 'autocompletion', type: 'text', limit: 200, null: false, relation: 'User', class: 'span7', autocapitalize: false, help: 'Select the customer of the Ticket or create one.', link: '<a href="" class="customer_new">&raquo;</a>', callback: @localUserInfo },
       { name: 'group_id',           display: 'Group',    tag: 'select',   multiple: false, null: false, filter: @edit_form, nulloption: true, relation: 'Group', default: defaults['group_id'], class: 'span7',  },
       { name: 'owner_id',           display: 'Owner',    tag: 'select',   multiple: false, null: true,  filter: @edit_form, nulloption: true, relation: 'User',  default: defaults['owner_id'], class: 'span7',  },
+      { name: 'tags',               display: 'Tags',     tag: 'tag',      type: 'text', null: true, default: defaults['tags'], class: 'span7', },
       { name: 'subject',            display: 'Subject',  tag: 'input',    type: 'text', limit: 200, null: false, default: defaults['subject'], class: 'span7', },
       { name: 'body',               display: 'Text',     tag: 'textarea', rows: 6,                  null: false, default: defaults['body'],    class: 'span7', },
       { name: 'ticket_state_id',    display: 'State',    tag: 'select',   multiple: false, null: false, filter: @edit_form, relation: 'TicketState',    default: defaults['ticket_state_id'],    translate: true, class: 'medium' },

+ 8 - 0
app/assets/javascripts/app/controllers/agent_ticket_zoom.js.coffee

@@ -188,6 +188,14 @@ class Index extends App.Controller
         zoom:    @
       )
 
+    # start tag controller
+    if !@isRole('Customer')
+      new App.TagWidget(
+        el:           @el.find('#tag_info')
+        object_type:  'Ticket'
+        object:        @ticket
+      )
+
     # start link info controller
     if !@isRole('Customer')
       new App.LinkInfo(

+ 69 - 0
app/assets/javascripts/app/controllers/tag_widget.js.coffee

@@ -0,0 +1,69 @@
+$ = jQuery.sub()
+
+class App.TagWidget extends App.Controller
+  constructor: ->
+    super
+    @load()
+
+  load: =>
+    App.Com.ajax(
+      id:    'tags_' + @object.id + '_' + @object_type
+      type:  'GET'
+      url:   '/api/tags'
+      data:
+        object: @object_type
+        o_id:   @object.id
+      processData: true
+      success: (data, status, xhr) =>
+        @render(data.tags)
+    )
+
+  render: (tags) =>
+
+    # insert data
+    @html App.view('tag_widget')(
+      tags: tags || [],
+    )
+    @el.find('#tags').tagsInput(
+      width:       '150px'
+      defaultText: App.i18n.translateContent('add a Tag')
+      onAddTag:    @onAddTag
+      onRemoveTag: @onRemoveTag
+#      height: '65px'
+    )
+    @delay @siteUpdate, 100
+
+#    @el.find('#tags').elastic()
+
+  onAddTag: (item) =>
+    App.Com.ajax(
+      type:  'GET',
+      url:   '/api/tags/add',
+      data:
+        object: @object_type,
+        o_id:   @object.id,
+        item:   item
+      processData: true,
+      success: (data, status, xhr) =>
+        @siteUpdate()
+    )
+
+  onRemoveTag: (item) =>
+    App.Com.ajax(
+      type:  'GET'
+      url:   '/api/tags/remove'
+      data:
+        object: @object_type
+        o_id:   @object.id
+        item:   item
+      processData: true
+      success: (data, status, xhr) =>
+        @siteUpdate(true)
+    )
+
+  siteUpdate: (reorder) =>
+    container = document.getElementById("tags_tagsinput")
+    if reorder
+      $('#tags_tagsinput').height( 20 )
+    height = container.scrollHeight
+    $('#tags_tagsinput').height( height - 10 )

+ 1 - 1
app/assets/javascripts/app/controllers/template_widget.js.coffee

@@ -35,7 +35,7 @@ class App.TemplateUI extends App.Controller
       template = App.Collection.find( 'Template', @template_id )
 
     # insert data
-    @html App.view('template')(
+    @html App.view('template_widget')(
       template: template,
     )
     new App.ControllerForm(

+ 1 - 1
app/assets/javascripts/app/controllers/text_module_widget.js.coffee

@@ -132,7 +132,7 @@ class App.TextModuleUI extends App.Controller
     )
 
     # insert data
-    @html App.view('text_module')(
+    @html App.view('text_module_widget')(
       search: @search,
     )
 

+ 1 - 1
app/assets/javascripts/app/models/ticket.js.coffee

@@ -1,5 +1,5 @@
 class App.Ticket extends App.Model
-  @configure 'Ticket', 'number', 'title', 'group_id', 'owner_id', 'customer_id', 'ticket_state_id', 'ticket_priority_id', 'article'
+  @configure 'Ticket', 'number', 'title', 'group_id', 'owner_id', 'customer_id', 'ticket_state_id', 'ticket_priority_id', 'article', 'tags'
   @extend Spine.Model.Ajax
   @url: '/api/tickets'
   @configure_attributes = [

+ 1 - 0
app/assets/javascripts/app/views/agent_ticket_zoom.jst.eco

@@ -93,6 +93,7 @@
   <div class="span3">
     <div id="customer_info"></div>
     <div id="action_info"></div>
+    <div id="tag_info"></div>
     <div id="link_info"></div>
     <div id="text_module"></div>
   </div>

+ 4 - 0
app/assets/javascripts/app/views/tag_widget.jst.eco

@@ -0,0 +1,4 @@
+<div class="well">
+  <h3><%- @T( 'Tags' ) %></h3>
+  <input type="text" name="tags" id="tags" class="span2" value="<% for tag in @tags: %><%= tag %>,<% end %>"/>
+</div>

+ 0 - 0
app/assets/javascripts/app/views/template.jst.eco → app/assets/javascripts/app/views/template_widget.jst.eco


Some files were not shown because too many files changed in this diff