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