diff --git a/app/assets/javascripts/app/controllers/object_manager.js.coffee b/app/assets/javascripts/app/controllers/object_manager.js.coffee new file mode 100644 index 000000000..a394fa231 --- /dev/null +++ b/app/assets/javascripts/app/controllers/object_manager.js.coffee @@ -0,0 +1,173 @@ +class Index extends App.ControllerTabs + constructor: -> + super + + # get data + @ajax( + id: 'object_manager_attributes_list', + type: 'GET', + url: @apiPath + '/object_manager_attributes_list', + processData: true, + success: (data, status, xhr) => + @build(data.objects) + ) + + build: (objects) => + @tabs = [] + for object in objects + item = + name: object, + target: "c-#{object}", + controller: Items, + params: + object: object + @tabs.push item + + @render() + +class Items extends App.ControllerContent + events: + 'click [data-type="delete"]': 'destroy' + 'click .js-up': 'move' + 'click .js-down': 'move' + 'click .js-new': 'new' + 'click .js-edit': 'edit' + + constructor: -> + super + # check authentication + return if !@authenticate() + + @subscribeId = App.ObjectManagerAttribute.subscribe(@render) + App.ObjectManagerAttribute.fetch() + + # ajax call + + release: => + if @subscribeId + App.ObjectManagerAttribute.unsubscribe(@subscribeId) + + render: => + items = App.ObjectManagerAttribute.search( + filter: + object: @object + sortBy: 'position' + ) + + @html App.view('object_manager/index')( + head: @object + items: items + ) + + + ### + new App.ControllerTable( + el: @el.find('.table-overview') + model: App.ObjectManagerAttribute + objects: objects + bindRow: + events: + 'click': @edit + ) + ### + + move: (e) => + e.preventDefault() + e.stopPropagation() + id = $( e.target ).closest('tr').data('id') + direction = 'up' + if $( e.target ).hasClass('js-down') + direction = 'down' + console.log('M', id, direction) + + items = App.ObjectManagerAttribute.search( + filter: + object: @object + sortBy: 'position' + ) + count = 0 + for item in items + if item.id is id + if direction is 'up' + itemToMove = items[ count - 1 ] + else + itemToMove = items[ count + 1 ] + if itemToMove + movePosition = itemToMove.position + if movePosition is item.position + if direction is 'up' + movePosition -= 1 + else + movePosition += 1 + itemToMove.position = item.position + itemToMove.save() + console.log(itemToMove, itemToMove.position, count) + item.position = movePosition + item.save() + console.log(item, movePosition, count) + count += 1 + + new: (e) => + e.preventDefault() + new App.ControllerGenericNew( + pageData: + title: 'Attribute' + home: 'object_manager' + object: 'ObjectManagerAttribute' + objects: 'ObjectManagerAttributes' + navupdate: '#object_manager' + genericObject: 'ObjectManagerAttribute' + ) + + edit: (e) => + e.preventDefault() + id = $( e.target ).closest('tr').data('id') + new Edit( + pageData: { + object: 'ObjectManagerAttribute' + }, + genericObject: 'ObjectManagerAttribute' + callback: @render + id: id + ) + + destroy: (e) -> + e.preventDefault() + sessionId = $( e.target ).data('session-id') + @ajax( + id: 'sessions/' + sessionId + type: 'DELETE' + url: @apiPath + '/sessions/' + sessionId + success: (data) => + @load() + ) + +class Edit extends App.ControllerModal + constructor: (params) -> + super + + @head = App.i18n.translateContent( 'Edit' ) + @cancel = true + @button = true + + ### + controller = new App.ControllerForm( + model: App.ObjectManagerAttribute + params: @item + screen: @screen || 'edit' + autofocus: true + ) + + @content = controller.form + ### + + content = App.view('object_manager/edit')( + head: @object + items: [] + ) + + @show(content) + + + +App.Config.set( 'SystemObject', { prio: 1700, parent: '#system', name: 'Objects', target: '#system/object_manager', controller: Index, role: ['Admin'] }, 'NavBarAdmin' ) diff --git a/app/assets/javascripts/app/models/object_manager_attribute.js.coffee b/app/assets/javascripts/app/models/object_manager_attribute.js.coffee new file mode 100644 index 000000000..0611d8c67 --- /dev/null +++ b/app/assets/javascripts/app/models/object_manager_attribute.js.coffee @@ -0,0 +1,20 @@ +class App.ObjectManagerAttribute extends App.Model + @configure 'ObjectManagerAttribute', 'name', 'object', 'display', 'active', 'editable', 'data_type', 'data_option', 'screens', 'position', 'updated_at' + @extend Spine.Model.Ajax + @url: @apiPath + '/object_manager_attributes' + @configure_attributes = [ + { name: 'name', display: 'Name', tag: 'input', type: 'text', limit: 100, 'null': false }, + { name: 'display', display: 'Anzeige', tag: 'input', type: 'text', limit: 100, 'null': false }, + { name: 'object', display: 'Object', tag: 'input', readonly: 1 }, + { name: 'position', display: 'Position', tag: 'input', readonly: 1 }, + { name: 'active', display: 'Active', tag: 'boolean', 'default': true, 'null': false }, + { name: 'data_type', display: 'Format', tag: 'input', type: 'text', limit: 100, 'null': false }, + { name: 'updated_at', display: 'Updated', type: 'time', readonly: 1 }, + ] + @configure_overview = [ + #'name', + 'display', + 'position', + 'data_type', + ] + @configure_delete = true \ No newline at end of file diff --git a/app/assets/javascripts/app/views/object_manager/edit.jst.eco b/app/assets/javascripts/app/views/object_manager/edit.jst.eco new file mode 100644 index 000000000..2e7f24ab3 --- /dev/null +++ b/app/assets/javascripts/app/views/object_manager/edit.jst.eco @@ -0,0 +1,2 @@ +edit + diff --git a/app/assets/javascripts/app/views/object_manager/index.jst.eco b/app/assets/javascripts/app/views/object_manager/index.jst.eco new file mode 100644 index 000000000..fef25a8cd --- /dev/null +++ b/app/assets/javascripts/app/views/object_manager/index.jst.eco @@ -0,0 +1,37 @@ +
+
+

<%- @T( @head ) %> <%- @T( 'Object Manager' ) %>

+ +
+
+ + + + + + + + + + + + <% for item in @items: %> + + + + + + + + <% end %> + +
<%- @T('State') %><%- @T('Display') %><%- @T('Name') %><%- @T('Type') %><%- @T('Actions') %>
<%= item.display %><%= item.name %><%= item.data_type %> + + <% if item.editable: %> + + <% end %> +
\ No newline at end of file diff --git a/app/controllers/object_manager_attributes_controller.rb b/app/controllers/object_manager_attributes_controller.rb new file mode 100644 index 000000000..d3d3fd12f --- /dev/null +++ b/app/controllers/object_manager_attributes_controller.rb @@ -0,0 +1,46 @@ +# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ + +class ObjectManagerAttributesController < ApplicationController + before_filter :authentication_check + + + # GET /object_manager_attributes_list + def list + return if deny_if_not_role('Admin') + render :json => { + :objects => ObjectManager.listObjects, + } + #model_index_render(ObjectManager::Attribute, params) + end + + # GET /object_manager_attributes + def index + return if deny_if_not_role('Admin') + render :json => ObjectManager::Attribute.list_full + #model_index_render(ObjectManager::Attribute, params) + end + + # GET /object_manager_attributes/1 + def show + return if deny_if_not_role('Admin') + model_show_render(ObjectManager::Attribute, params) + end + + # POST /object_manager_attributes + def create + return if deny_if_not_role('Admin') + model_create_render(ObjectManager::Attribute, params) + end + + # PUT /object_manager_attributes/1 + def update + return if deny_if_not_role('Admin') + model_update_render(ObjectManager::Attribute, params) + end + + # DELETE /object_manager_attributes/1 + def destroy + return if deny_if_not_role('Admin') + model_destory_render(ObjectManager::Attribute, params) + end +end diff --git a/app/models/object_manager.rb b/app/models/object_manager.rb index 27f918f84..e3ca57347 100644 --- a/app/models/object_manager.rb +++ b/app/models/object_manager.rb @@ -11,7 +11,7 @@ add a new activity entry for an object =end def self.listObjects - ['Ticket', 'TicketArticle', 'Group', 'Organization', 'User'] + ['Ticket', 'User', 'Organization' ] #, 'Group' ] end end @@ -23,6 +23,33 @@ class ObjectManager::Attribute < ApplicationModel store :screens store :data_option +=begin + +list of all attributes + + result = ObjectManager::Attribute.list_full + + result = [ + { + :name => 'some name', + :display => '...', + }. + ], + +=end + + def self.list_full + result = ObjectManager::Attribute.all + attributes = [] + assets = {} + result.each {|item| + attribute = item.attributes + attribute[:object] = ObjectLookup.by_id( item.object_lookup_id ) + attribute.delete('object_lookup_id') + attributes.push attribute + } + attributes + end =begin @@ -89,7 +116,7 @@ add a new activity entry for an object =begin -get list of object attributes +get user based list of object attributes attribute_list = ObjectManager::Attribute.by_object('Ticket', user) diff --git a/config/routes/object_manager_attribute.rb b/config/routes/object_manager_attribute.rb new file mode 100644 index 000000000..f5c37f0ca --- /dev/null +++ b/config/routes/object_manager_attribute.rb @@ -0,0 +1,12 @@ +Zammad::Application.routes.draw do + api_path = Rails.configuration.api_path + + # object_manager + match api_path + '/object_manager_attributes_list', :to => 'object_manager_attributes#list', :via => :get + match api_path + '/object_manager_attributes', :to => 'object_manager_attributes#index', :via => :get + match api_path + '/object_manager_attributes/:id', :to => 'object_manager_attributes#show', :via => :get + match api_path + '/object_manager_attributes', :to => 'object_manager_attributes#create', :via => :post + match api_path + '/object_manager_attributes/:id', :to => 'object_manager_attributes#update', :via => :put + match api_path + '/object_manager_attributes/:id', :to => 'object_manager_attributes#destroy', :via => :delete + +end \ No newline at end of file