Skip to content
Snippets Groups Projects
Commit 3fa094ea authored by Pascal Neub's avatar Pascal Neub
Browse files

[Projekt: xRM-Sales][TicketNr.: 1062845][Angebot/Beleg: Verschieben von Angebotsposten/Belegposten]

parent a86b56b3
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,8 @@ import("system.db");
import("system.neon");
/**
* a static Utility class for the items like OfferItem and OrderItem.
* A Utility class for the items like OfferItem and OrderItem.
* Loads all items and stores them as trees
*
* @class
*/
......@@ -26,10 +27,12 @@ function MoveableItemUtils(pTargetTable, pItemIdField, pItemSortField, pItemPosF
{
var uid = data[i][0];
var pos = data[i][2];
var trimmedPos = pos.replace(/(^|\.)\d*$/, "")
var trimmedPos = pos.replace(/(^|\.)\d*$/, "");
if(!this.posMap.has(pos))
{
this.posMap.set(pos, {childs: []});
}
var curr = this.posMap.get(pos);
curr.uid = uid;
......@@ -37,13 +40,18 @@ function MoveableItemUtils(pTargetTable, pItemIdField, pItemSortField, pItemPosF
curr.parent = trimmedPos;
if(!this.posMap.has(trimmedPos))
{
this.posMap.set(trimmedPos, {childs: []});
}
this.posMap.get(trimmedPos).childs.push(pos);
this.uidToPos.set(uid, pos);
}
}
/**
* Checks weather the item can move up
*/
MoveableItemUtils.prototype.canMoveUp = function(pItemId)
{
var pos = this.uidToPos.get(pItemId);
......@@ -52,6 +60,9 @@ MoveableItemUtils.prototype.canMoveUp = function(pItemId)
return parentChilds.indexOf(pos) >= 1;
}
/**
* Checks weather the item can move down
*/
MoveableItemUtils.prototype.canMoveDown = function(pItemId)
{
var pos = this.uidToPos.get(pItemId);
......@@ -60,10 +71,15 @@ MoveableItemUtils.prototype.canMoveDown = function(pItemId)
return parentChilds.indexOf(pos) < parentChilds.length - 1;
}
/**
* Moves the item up
*/
MoveableItemUtils.prototype.moveUp = function(pItemId)
{
if(!this.canMoveUp(pItemId))
{
throw new Error("Item can't be moved up");
}
var pos = this.uidToPos.get(pItemId);
var item = this.posMap.get(pos);
......@@ -82,10 +98,15 @@ MoveableItemUtils.prototype.moveUp = function(pItemId)
neon.refreshAll();
}
/**
* Moves the item down
*/
MoveableItemUtils.prototype.moveDown = function(pItemId)
{
if(!this.canMoveDown(pItemId))
{
throw new Error("Item can't be moved down");
}
var pos = this.uidToPos.get(pItemId);
var item = this.posMap.get(pos);
......@@ -104,6 +125,9 @@ MoveableItemUtils.prototype.moveDown = function(pItemId)
neon.refreshAll();
}
/**
* Swaps item positions
*/
MoveableItemUtils.prototype.moveItem = function(pTargetStmts, pId, pPos)
{
var pos = this.uidToPos.get(pId);
......@@ -122,6 +146,9 @@ MoveableItemUtils.prototype.moveItem = function(pTargetStmts, pId, pPos)
}
}
/**
* Updates the sorting
*/
MoveableItemUtils.prototype.updateSorting = function()
{
var stmts = [];
......@@ -144,6 +171,9 @@ MoveableItemUtils.prototype.updateSorting = function()
db.updates(stmts);
}
/**
* Returns the item data via sql
*/
MoveableItemUtils.prototype.getData = function()
{
return newSelect([this.itemIdField, this.itemSortField, this.itemPosField])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment