diff --git a/app/controller/window/source/SourceView.js b/app/controller/window/source/SourceView.js index a5a7b1606..4b386b6b1 100644 --- a/app/controller/window/source/SourceView.js +++ b/app/controller/window/source/SourceView.js @@ -62,7 +62,7 @@ Ext.define('EdiromOnline.controller.window.source.SourceView', { var data = response.responseText; var movements = Ext.create('Ext.data.Store', { - fields: ['id', 'name'], + fields: ['id', 'name', 'parts'], data: Ext.JSON.decode(data) }); diff --git a/app/view/window/source/SourceView.js b/app/view/window/source/SourceView.js index 9a1f064e1..c930733c4 100644 --- a/app/view/window/source/SourceView.js +++ b/app/view/window/source/SourceView.js @@ -213,13 +213,90 @@ Ext.define('EdiromOnline.view.window.source.SourceView', { me.movements = movements; me.measureBasedView.setMovements(movements); + /* copy from OPERA + * TODO: cleanup and make partwise global option; probably implement possibility to order parts */ + var partwise = true; + var movementItems = []; - movements.each(function(movement) { - movementItems.push({ - text: movement.get('name'), - handler: Ext.bind(me.gotoMovement, me, movement.get('id'), true) - }); + var partList = []; + var partNames =[]; + + movements.data.each(function(movement){ + + if (movement.data.parts === null){ + movementItems.push({ + text: movement.get('name'), + handler: Ext.bind(me.gotoMovement, me, movement.get('id'), true) + }); + } + else + { + if (partwise) + { + movement.data.parts.forEach(function(part){ + var exists = partNames.indexOf(part.name); + var obj = { + text: part.name, + menu: [] + }; + if (exists === -1) { + partNames.push(part.name); + partList.push(obj); + exists = partNames.length - 1; + } /*else {*/ + var menu_mov = { + text: movement.get('name'), + handler: Ext.bind(me.gotoMovement, me, part.id, true) + } + + partList[exists].menu.push(menu_mov); + /*}*/ + }); + } + else + { + var parts = []; + + movement.data.parts.forEach(function(part){ + parts.push(part); + }); + + if (movement.data.parts === null) + { + movementItems.push({ + text: movement.get('name'), + handler: Ext.bind(me.gotoMovement, me, movement.get('id'), true) + }); + partList.forEach(function(item){ + movementItems.push(item); + }); + } + else + { + + var partItems = []; + parts.forEach(function(part){ + partItems.push({ + text: part.name, + handler: Ext.bind(me.gotoMovement, me, part.id, true) + }); + }); + movementItems.push({ + text: movement.get('name'), + menu: [ partItems ] + }); + } + } + } + }); + + if(partwise) { + partList.forEach(function(item){ + movementItems.push(item); + }); + } + /* end OPERA stuff */ me.gotoMenu.menu.add({ id: me.id + '_gotoMovement',