Browse Source

Merge branch 'develop' into interface

Conflicts:
	app/assets/javascripts/app/controllers/ticket_zoom.js.coffee
	app/assets/javascripts/app/controllers/widget/tag.js.coffee
Martin Edenhofer 10 years ago
parent
commit
9be9d56d74

+ 11 - 15
app/assets/javascripts/app/controllers/ticket_zoom.js.coffee

@@ -113,6 +113,12 @@ class App.TicketZoom extends App.Controller
     # remember article ids
     @ticket_article_ids = data.ticket_article_ids
 
+    # remember link
+    @links = data.links
+
+    # remember tags
+    @tags = data.tags
+
     # get edit form attributes
     @form_meta = data.form_meta
 
@@ -155,12 +161,14 @@ class App.TicketZoom extends App.Controller
             el:           el.find('.tags')
             object_type:  'Ticket'
             object:       @ticket
+            tags:         @tags
           )
           el.append('<div class="links"></div>')
           new App.WidgetLink(
             el:           el.find('.links')
             object_type:  'Ticket'
             object:       @ticket
+            links:        @links
           )
           el.append('<div class="action"></div>')
           showHistory = =>
@@ -865,26 +873,14 @@ class Edit extends App.Controller
         @autosaveStart()
         return
 
+    ticket.article = article
     ticket.save(
       done: (r) =>
 
         # reset form after save
-        if article
-          article.save(
-            done: (r) =>
-              @ui.fetch( ticket.id, true )
-
-              # reset form after save
-              App.TaskManager.update( @task_key, { 'state': {} })
-            fail: (r) =>
-              @log 'error', 'update article', r
-          )
-        else
-
-          # reset form after save
-          App.TaskManager.update( @task_key, { 'state': {} })
+        App.TaskManager.update( @task_key, { 'state': {} })
 
-          @ui.fetch( ticket.id, true )
+        @ui.fetch( ticket.id, true )
     )
 
   reset: (e) =>

+ 6 - 1
app/assets/javascripts/app/controllers/widget/link.js.coffee

@@ -5,7 +5,12 @@ class App.WidgetLink extends App.Controller
 
   constructor: ->
     super
-    @fetch()
+
+    # if links are given, do not init fetch
+    if @links
+      @render()
+    else
+      @fetch()
 
   fetch: =>
     # fetch item on demand

+ 7 - 1
app/assets/javascripts/app/controllers/widget/tag.js.coffee

@@ -12,10 +12,16 @@ class App.WidgetTag extends App.Controller
 
   constructor: ->
     super
+
     @cacheKey = "tags::#{@object_type}::#{@object.id}"
+
+    if @tags
+      @render(@tags)
+      return
+
     @tagList = App.Store.get( @cacheKey ) || []
-    @render()
     if !_.isEmpty(@tagList)
+      @render()
       @delay(
         =>
           @fetch()

+ 8 - 3
app/assets/javascripts/app/models/_application_model.js.coffee

@@ -171,6 +171,7 @@ class App.Model extends Spine.Model
               attribute[item] = value
             attributesNew[ attribute.name ] = attribute
 
+    # if no screen is given or no attribute has this screen - use default attributes
     if !screen || _.isEmpty( attributesNew )
       for attribute in attributes
         attributesNew[ attribute.name ] = attribute
@@ -335,9 +336,13 @@ class App.Model extends Spine.Model
 
     # fetch init collection
     if param.initFetch is true
-      @one 'refresh', (collection) =>
-        callback(collection)
-      @fetch( {}, { clear: true } )
+      if !@initFetchActive
+        @one 'refresh', (collection) =>
+          @initFetchActive = true
+          callback(collection)
+        @fetch( {}, { clear: true } )
+      else
+        callback( @all() )
 
     # return key
     key

+ 71 - 37
app/controllers/tickets_controller.rb

@@ -22,7 +22,7 @@ class TicketsController < ApplicationController
 
   # POST /api/v1/tickets
   def create
-    @ticket = Ticket.new( Ticket.param_validation( params[:ticket] ) )
+    ticket = Ticket.new( Ticket.param_validation( params[:ticket] ) )
 
     # check if article is given
     if !params[:article]
@@ -31,8 +31,8 @@ class TicketsController < ApplicationController
     end
 
     # create ticket
-    if !@ticket.save
-      render :json => @ticket.errors, :status => :unprocessable_entity
+    if !ticket.save
+      render :json => ticket.errors, :status => :unprocessable_entity
       return
     end
 
@@ -42,7 +42,7 @@ class TicketsController < ApplicationController
       tags.each {|tag|
         Tag.tag_add(
           :object        => 'Ticket',
-          :o_id          => @ticket.id,
+          :o_id          => ticket.id,
           :item          => tag,
           :created_by_id => current_user.id,
         )
@@ -51,57 +51,39 @@ class TicketsController < ApplicationController
 
     # create article if given
     if params[:article]
-      form_id  = params[:article][:form_id]
-      params[:article].delete(:form_id)
-      @article = Ticket::Article.new( Ticket::Article.param_validation( params[:article] ) )
-      @article.ticket_id     = @ticket.id
-
-      # find attachments in upload cache
-      if form_id
-        @article.attachments = Store.list(
-          :object => 'UploadCache',
-          :o_id   => form_id,
-        )
-      end
-      if !@article.save
-        render :json => @article.errors, :status => :unprocessable_entity
-        return
-      end
-
-      # remove attachments from upload cache
-      if form_id
-        Store.remove(
-          :object => 'UploadCache',
-          :o_id   => form_id,
-        )
-      end
+      article_create( ticket, params[:article] )
     end
 
-    render :json => @ticket, :status => :created
+    render :json => ticket, :status => :created
   end
 
   # PUT /api/v1/tickets/1
   def update
-    @ticket = Ticket.find(params[:id])
+    ticket = Ticket.find(params[:id])
 
     # permissin check
-    return if !ticket_permission(@ticket)
+    return if !ticket_permission(ticket)
+
+    if ticket.update_attributes( Ticket.param_validation( params[:ticket] ) )
 
-    if @ticket.update_attributes( Ticket.param_validation( params[:ticket] ) )
-      render :json => @ticket, :status => :ok
+      if params[:article]
+        article_create( ticket, params[:article] )
+      end
+
+      render :json => ticket, :status => :ok
     else
-      render :json => @ticket.errors, :status => :unprocessable_entity
+      render :json => ticket.errors, :status => :unprocessable_entity
     end
   end
 
   # DELETE /api/v1/tickets/1
   def destroy
-    @ticket = Ticket.find( params[:id] )
+    ticket = Ticket.find( params[:id] )
 
     # permissin check
-    return if !ticket_permission(@ticket)
+    return if !ticket_permission(ticket)
 
-    @ticket.destroy
+    ticket.destroy
 
     head :ok
   end
@@ -286,12 +268,34 @@ class TicketsController < ApplicationController
       assets = article.assets(assets)
     }
 
+    # get links
+    links = Link.list(
+      :link_object       => 'Ticket',
+      :link_object_value => ticket.id,
+    )
+    link_list = []
+    links.each { |item|
+      link_list.push item
+      if item['link_object'] == 'Ticket'
+        ticket = Ticket.lookup( :id => item['link_object_value'] )
+        assets = ticket.assets(assets)
+      end
+    }
+
+    # get tags
+    tags = Tag.tag_list(
+      :object => 'Ticket',
+      :o_id   => ticket.id,
+    )
+
     # return result
     render :json => {
       :ticket_id          => ticket.id,
       :ticket_article_ids => article_ids,
       :signature          => signature,
       :assets             => assets,
+      :links              => link_list,
+      :tags               => tags,
       :form_meta          => attributes_to_change,
       :edit_form          => attributes_to_change,
     }
@@ -361,4 +365,34 @@ class TicketsController < ApplicationController
     }
   end
 
+  private
+
+  def article_create(ticket, params)
+puts params.inspect
+    # create article if given
+    form_id  = params[:form_id]
+    params.delete(:form_id)
+    article = Ticket::Article.new( Ticket::Article.param_validation( params ) )
+    article.ticket_id = ticket.id
+
+    # find attachments in upload cache
+    if form_id
+      article.attachments = Store.list(
+        :object => 'UploadCache',
+        :o_id   => form_id,
+      )
+    end
+    if !article.save
+      render :json => article.errors, :status => :unprocessable_entity
+      return
+    end
+
+    # remove attachments from upload cache
+    if form_id
+      Store.remove(
+        :object => 'UploadCache',
+        :o_id   => form_id,
+      )
+    end
+  end
 end