Init commit for object manager.

This commit is contained in:
Martin Edenhofer 2014-11-02 20:44:15 +01:00
parent 73b2353842
commit 99f64668e7
7 changed files with 319 additions and 2 deletions

View file

@ -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' )

View file

@ -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

View file

@ -0,0 +1,2 @@
edit

View file

@ -0,0 +1,37 @@
<div class="page-header-title">
<div class="horizontal">
<h1><%- @T( @head ) %> <small><%- @T( 'Object Manager' ) %></small></h1>
<div class="page-header-meta">
<a class="btn js-restore"><%- @T( 'Restore Attributes to default' ) %></a>
<a class="btn btn--danger js-sync"><%- @T( 'Sync Changes' ) %> <span class="glyphicon glyphicon-lock"></span></a>
<a class="btn btn--success js-new"><%- @T( 'New Attribute' ) %></a>
</div>
</div>
</div>
<table class="table table-striped table-hover">
<thead>
<tr>
<th class=""><%- @T('State') %></th>
<th class=""><%- @T('Display') %></th>
<th class=""><%- @T('Name') %></th>
<th class=""><%- @T('Type') %></th>
<th class=""><%- @T('Actions') %></th>
</tr>
</thead>
<tbody>
<% for item in @items: %>
<tr class="<% if item.active is false: %>not-active<% end %> js-edit u-clickable" data-id="<%- item.id %>">
<td><span class="glyphicon <% if item.pending_migration: %>glyphicon-flash<% end %> <% if item.active: %>glyphicon-ok<% else: %>glyphicon-remove<% end %>"></span></td>
<td><%= item.display %></td>
<td><%= item.name %></td>
<td><%= item.data_type %></td>
<td>
<a href="#" class="glyphicon glyphicon-chevron-up js-up"></a><a href="#" class="glyphicon glyphicon-chevron-down js-down"></a>
<% if item.editable: %>
<a href="#" data-id="<%- item.id %>" data-type="delete" class="glyphicon glyphicon-trash" title="<%- @T('Delete') %>"></a>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>

View file

@ -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

View file

@ -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)

View file

@ -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