I need to make a module that allow the user to enter width and height , and then it should calculate the price based on the height and width .
thanks in advance
let's say that you want to do it on the product ID N° 1 from the product page :
first add two inputs fields in your product.tpl ( or in your module.tpl called in product.tpl)
<input name="height"><br>
<input name="width">
now you need to get it in your module.php to change the price dynamicly :
$id_product = 1;
$newPrice = 0;
$height = Tools::getValue('height');
$width = Tools::getValue('width');
//Price rules (change with your rules)
if($height > 10 && $width > 10) $newPrice = 10;
$specific_price = new SpecificPrice();
$specific_price->price = $newPrice;
$specific_price->id_cart = (int) $this->context->cart->id;
$specific_price->id_shop = 0;
$specific_price->id_shop_group = 0;
$specific_price->id_currency = 0;
$specific_price->id_country = 0;
$specific_price->id_group = 0;
$specific_price->id_customer = (int) $this->context->customer->id;
$specific_price->id_product = (int)$id_product;
$specific_price->id_product_attribute = 0;
$specific_price->from_quantity = 1;
$specific_price->reduction = 0;
$specific_price->reduction_type = 'amount';
$specific_price->from = '0000-00-00 00:00:00';
$specific_price->to = '0000-00-00 00:00:00';
$specific_price->add();
and if you want add it to cart
$cart->id_lang = (int)($this->context->cookie->id_lang);
$cart->id_currency = (int)($this->context->cookie->id_currency);
$cart->updateQty($qte, $id_product);
and after order is done you put the normal price, so override the orderConfirmation controller in override/controllers/front/OrderConfirmationController.php:
class OrderConfirmationController extends OrderConfirmationControllerCore
{
public $ssl = true;
public $php_self = 'order-confirmation';
public $id_cart;
public $id_module;
public $id_order;
public $reference;
public $secure_key;
public function getPriceBack($id_product){
$normalPrice = Product::getPriceStatic($id_product);
$specific_price = new SpecificPrice();
$specific_price->price = $normalPrice;
$specific_price->id_cart = (int) $this->context->cart->id;
$specific_price->id_shop = 0;
$specific_price->id_shop_group = 0;
$specific_price->id_currency = 0;
$specific_price->id_country = 0;
$specific_price->id_group = 0;
$specific_price->id_customer = (int) $this->context->customer->id;
$specific_price->id_product = (int)$id_product;
$specific_price->id_product_attribute = 0;
$specific_price->from_quantity = 1;
$specific_price->reduction = 0;
$specific_price->reduction_type = 'amount';
$specific_price->from = '0000-00-00 00:00:00';
$specific_price->to = '0000-00-00 00:00:00';
$specific_price->add();
}
public function init()
{
parent::init();
$this->id_cart = (int)(Tools::getValue('id_cart', 0));
$is_guest = false;
/* get normal price back */
$id_product = 1;
self::getPriceBack($id_product);
/* check if the cart has been made by a Guest customer, for redirect link */
if (Cart::isGuestCartByCartId($this->id_cart)) {
$is_guest = true;
$redirectLink = 'index.php?controller=guest-tracking';
} else {
$redirectLink = 'index.php?controller=history';
}
$this->id_module = (int)(Tools::getValue('id_module', 0));
$this->id_order = Order::getOrderByCartId((int)($this->id_cart));
$this->secure_key = Tools::getValue('key', false);
$order = new Order((int)($this->id_order));
if ($is_guest) {
$customer = new Customer((int)$order->id_customer);
$redirectLink .= '&id_order='.$order->reference.'&email='.urlencode($customer->email);
}
if (!$this->id_order || !$this->id_module || !$this->secure_key || empty($this->secure_key)) {
Tools::redirect($redirectLink.(Tools::isSubmit('slowvalidation') ? '&slowvalidation' : ''));
}
$this->reference = $order->reference;
if (!Validate::isLoadedObject($order) || $order->id_customer != $this->context->customer->id || $this->secure_key != $order->secure_key) {
Tools::redirect($redirectLink);
}
$module = Module::getInstanceById((int)($this->id_module));
if ($order->module != $module->name) {
Tools::redirect($redirectLink);
}
}
}
after the order is done you have to empty the cart with id_product and delete rule in dbb :
$this->context->cart->deleteProduct(1);
Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'specific_price WHERE id_customer='.(int)$this->context->customer->id);
it s just an example and can not use without variables tests and maybe put constante for your product id concerned, hope it helps
Related
Here is the part I am havng problems... I am able to use this code in my search button to search for Banda = 0 or Musica = 1.. but not both.. any idea?
function myFunction() {
var input, filter, table, tr, td, i, txtValue;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("myTable");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[0];
if (td) {
txtValue = td.textContent || td.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
I'm trying to get the "id" of the TD Node that a field is in. I created a function, but I am not getting the data out of the loop ... I'm guessing that the variables are out of scope and I can't figure out how to make it work.
function getTD(vStartNm)
{
vNm = document.getElementsByName(vStartNm),
vId = vNm[0].getAttribute('id'),
vNode = document.getElementById(vId),
vTag = vNode.nodeName;
vTDId = '';
for (i = 0; i >10; i++)
{
vPar = vNode.parentNode;
vTag = vPar.nodeName;
vTDId = vPar.id;
vNode = vPar;
if (vTag == 'TD'){return vTDId; break;}
}
}
vTD_id = getTD('udfchar45');
vTD = document.getElementById(vTD_id);
my syntax on the do loop may be wrong. once i changed it to a while loop, it seems to work just fine.
function getTD(vStartNm)
{
vNm = document.getElementsByName(vStartNm),
vId = vNm[0].getAttribute('id'),
vNode = document.getElementById(vId),
vTag = vNode.nodeName;
vTDId = '';
i=0;
while (i < 10)
{
i++;
vPar = vNode.parentNode;
vTag = vPar.nodeName;
vTDId = vPar.id;
vNode = vPar;
if (vTag == 'TD'){return vTDId; break;}
}
}
vTD_id = getTD('udfchar45');
vTD = document.getElementById(vTD_id);
I am using DHTMLX Scheduler in my MVC Application. In my scheduler when we drag and the drop the timings a popup will be displayed which is working by default scheduler.js file. My problem is while dragging the time i need to display the custom popup window. Is it possible to do with the scheduler?
Can any one please help me.
Code for scheduler is
public ActionResult CalendarView(int? id, int? CustomerUserid)
{
//id = (int)Session["BUId"];
if (CustomerUserid == (int)Session["UserID"] || (CustomerUserid == (int)Session["UserID"] && id == (int)Session["BusinessId"]))
{
var scheduler = new DHXScheduler(this);
string val = System.Configuration.ConfigurationManager.AppSettings["UserTypeId"];
int code = Convert.ToInt32(val);
//var cuid = (int)Session["UserID"];
// List<tblUser> user = new List<tblUser>();
// var user1 = (from s in user
// where s.UserTypeId == 3 && s.UserID == cuid
// select new Appt
// {
// AddCustomer = s.DependentCustomer.ToString()
// }).ToList();
var cal = (from s
in db.tblUsers
where s.UserTypeId == code && s.UserID == id
select new Appt
{
BusinessName = s.tblBusinessCategory.BusinessName
// StartTime = s.WorkingHour.StartTime,
}).FirstOrDefault();
var sa = (from a
in db.WorkHours
where a.BusinessUserId == id
select new Appt
{
StartTime = a.StartTime,
EndTime = a.EndTime
}).FirstOrDefault();
Session["StartTime"] = sa.StartTime.Hour;
Session["EndTime"] = sa.EndTime.Hour;
Session["BUName"] = cal.BusinessName.ToString();
// var scheduler = new DHXScheduler(this);//{ InitialDate = new DateTime(2015, 1, 30) };
scheduler.Skin = DHXScheduler.Skins.Flat;
scheduler.Data.Loader.PreventCache();
scheduler.EnableDynamicLoading(SchedulerDataLoader.DynamicalLoadingMode.Week);
scheduler.Extensions.Add(SchedulerExtensions.Extension.Recurring);
//scheduler.Extensions.Add(SchedulerExtensions.Extension.ActiveLinks);
//scheduler.Extensions.Add(SchedulerExtensions.Extension.Collision);
scheduler.Extensions.Add(SchedulerExtensions.Extension.Limit);
scheduler.Config.limit_start = new DateTime(2015, 8, 25);
scheduler.Config.limit_end = new DateTime(2015, 9, 25);
scheduler.LoadData = true;
scheduler.EnableDataprocessor = true;
scheduler.Config.show_loading = true;
// scheduler.Config.buttons_left = ["dhx_save_btn","dhx_cancel_btn","locate_button"];
//var button = new LightboxButtonList();
//scheduler.Lightbox.Add();
int days = System.DateTime.Now.Day - 1;
int months = System.DateTime.Now.Month;
int years = System.DateTime.Now.Year;
int ihour = System.DateTime.Now.Hour;
int iminute = System.DateTime.Now.Minute;
int isecond = System.DateTime.Now.Second;
scheduler.TimeSpans.Add(new DHXBlockTime()
{
StartDate = new DateTime(2014, 2, 10),
EndDate = new DateTime(years, months, days + 1, ihour, iminute, isecond),
});
Session["BUId"] = id;
var parameter = new SqlParameter[1];
parameter[0] = new SqlParameter { ParameterName = "UserId", Value = id };
List<Appt> cm = new List<Appt>();
using (SYTEntities context = new SYTEntities())
{
cm = context.Database.SqlQuery<Appt>("exec spHoliday #UserId", parameter).ToList();
}
int iyear = 2015;
int imonth = 8;
int iday = 09;
//int ihour = 10;
int imin = 05;
int isec = 00;
foreach (var cp in cm)
{
iyear = cp.HolidayDate.Year;
imonth = cp.HolidayDate.Month;
iday = cp.HolidayDate.Day;
scheduler.TimeSpans.Add(new DHXMarkTime()
{
StartDate = new DateTime(iyear, imonth, iday), //new DateTime(2015, 8, 06), //hl.HolidayDate ?? default(DateTime),
EndDate = new DateTime(iyear, imonth, iday + 1),
// Day = DayOfWeek.Friday,
CssClass = "red_section",
HTML = "hos",
SpanType = DHXTimeSpan.Type.BlockEvents
});
}
var parameters = new SqlParameter[1];
parameters[0] = new SqlParameter { ParameterName = "BusinessUserId", Value = id };
List<Appt> wt = new List<Appt>();
using (SYTEntities context = new SYTEntities())
{
wt = context.Database.SqlQuery<Appt>("exec spGetWaitingList #BusinessUserId", parameters).ToList();
}
int ihr;
int imts;
int idayd;
int iyr;
int imnth;
int ihrs;
foreach (var cs in wt)
{
iyr = cs.EndTime.Year;// System.DateTime.Now.Year;
imnth = cs.EndTime.Month;// System.DateTime.Now.Month;
idayd = cs.EndTime.Day;// System.DateTime.Now.Day;
ihr = cs.EndTime.Hour; //.Hours; //.Hour;
imts = cs.EndTime.Minute; //.Minutes; //.Minute;
isec = cs.EndTime.Second; //.Seconds;
ihrs = cs.EndTime.Hour - cs.StartTime.Hour;
scheduler.TimeSpans.Add(new DHXMarkTime()
{
StartDate = new DateTime(iyr, imnth, idayd, ihr, imts, isec), //new DateTime(2015, 8, 06), //hl.HolidayDate ?? default(DateTime),
EndDate = new DateTime(iyr, imnth, idayd, ihr, imts, isec),
// Day = DayOfWeek.Friday,
CssClass = "green_section",
HTML = "",
SpanType = DHXTimeSpan.Type.BlockEvents
});
}
//for (int i = 0; i < 4; i++)
//{
// scheduler.TimeSpans.Add(new DHXMarkTime()
// {
// StartDate = new DateTime(iyear, imonth,iday,ihour, imin, isec), //new DateTime(2015, 8, 06), //hl.HolidayDate ?? default(DateTime),
// EndDate = new DateTime(iyear, imonth, iday,ihour, imin, isec),
// CssClass = "red_section",
// SpanType = DHXTimeSpan.Type.BlockEvents
// });
//}
scheduler.BeforeInit.Add("schedulerClient.init()");
//var check = new LightboxCheckbox("highlighting", "Important") { MapTo = "color", CheckedValue = "#FE7510" };
//scheduler.Lightbox.Add(check);
return View(scheduler);
}
return View();
}
Image
Do you mean you need to show some kind of popup showing additional info during task move/resize?
If so, you can use template for task content - if the current task is being dragged or resized, a template should return an absolute positioned popup with a custom content
E.g.
JS:
scheduler.attachEvent("onSchedulerReady", function () {
var headerTemplate = scheduler.templates.event_header;
scheduler.templates.event_header = function (start, end, event) {
var content = headerTemplate(start, end, event);
if (scheduler.getState().drag_id == event.id) {
var dragPopup = "<div class='drag-popup'>" + headerTemplate(start, end, event) + "</div>";
content += dragPopup;
}
return content;
};
});
CSS:
.drag-popup{
position: absolute;
right:0;
top: 0;
margin-right: 120px;
padding: 10px;
width: 100px;
background-color: inherit;
color: inherit;
z-index: 5;
}
Result:
Although, with this approach you'll need to manage tooltip position more thoughtfully than i did in this sample. Since popup is nested in event's DOM element, it will be limited by a scheduler container. E.g. when event is in left-most column - you'll need to locate popup at right, otherwise it will be cutted.
Here are the related API methods
http://docs.dhtmlx.com/scheduler/api__scheduler_getstate.html
http://docs.dhtmlx.com/scheduler/api__scheduler_event_header_template.html
i have a working program where i can add an array to a Zedgraph and show this in a form.
Now i only want to change the display of the x-axis from points (0..400) to frequency (9e3..6e9 Hz).
Here are my currently working functions:
public void AddGraph(double[] Values, string LegendName)
{
int i = 0;
PointPairList list = new PointPairList();
for (i = 0; i < Values.Length; i++)
{
list.Add(i, Values[i]);
}
if (i > MaxXAxis)
MaxXAxis = i;
SList.Add(list);
SListColor.Add(Color.Black);
}
SListName.Add(LegendName);
}
public void ShowDiagram(string Title, string XAxisName, string YAxisName,
int Timeout_ms)
{
ZedGraph.ZedGraphControl zgc = new ZedGraphControl();
GraphPane myPane = zgc.GraphPane;
LineItem myCurve = null;
// Set the titles and axis labels
myPane.Title.Text = Title;
myPane.XAxis.Title.Text = XAxisName;
myPane.YAxis.Title.Text = YAxisName;
for (int i = 0; i < SList.Count(); i++)
{
myCurve = myPane.AddCurve(SListName[i], SList[i], SListColor[i],
SymbolType.None);
myCurve.Line.Width = 2;
}
// Add gridlines to the plot, and make them gray
myPane.XAxis.MinorGrid.IsVisible = true;
myPane.YAxis.MinorGrid.IsVisible = true;
myPane.XAxis.MinorGrid.Color = Color.LightGray;
myPane.YAxis.MinorGrid.Color = Color.LightGray;
myPane.XAxis.MinorGrid.DashOff = 0;
myPane.YAxis.MinorGrid.DashOff = 0;
myPane.XAxis.MajorGrid.IsVisible = true;
myPane.YAxis.MajorGrid.IsVisible = true;
myPane.XAxis.MajorGrid.Color = Color.Gray;
myPane.YAxis.MajorGrid.Color = Color.Gray;
myPane.XAxis.MajorGrid.DashOff = 0;
myPane.YAxis.MajorGrid.DashOff = 0;
// Move Legend to bottom
myPane.Legend.Position = LegendPos.Bottom;
zgc.AxisChange();
myPane.XAxis.Scale.Max = MaxXAxis;
zgc.Location = new Point(0, 0);
zgc.Size = new Size(panel_diagramm.ClientRectangle.Width, panel_diagramm.ClientRectangle.Height);
panel_diagramm.Controls.Add(zgc);
}
How can i change the above two functions that they display the frequency in the x-axis?
I already tried to change the AddGraph-function to pass the needed parameters and to calculate the list to have the correct values. But what then...?
public void AddGraph_Frequency(int **Points**, double **StartFrequency**,
double **StopFrequency**, double[] Values, string GraphColor, string LegendName)
{
...
double frequency = StartFrequency; //der erste Punkt
double Intervall = (StopFrequency - StartFrequency) / Points;
for (i = 0; i < Points; i++)
{
list.Add(frequency, Values[i]);
frequency = frequency + Intervall;
}
....
}
Thanks for any help
best regards
Solved.
Missing was:
myPane.XAxis.Scale.Max = Stopfrequency;
myPane.XAxis.Scale.Min = Startfrequency;
So I have this stinky method, the two conditional blocks do almost the exact same thing, but with radically different parameters (at least in my eyes). I want to clean it Uncle Bob style, but can't for the life of me figure out a tidy way of doing it. So I come to you, my fabulous nerd friends, to see how you might distill this down to something that doesn't make one want to gouge out their eyes. The code is AS3, but that doesn't really make a difference in my opinion.
/**
* Splits this group into two groups based on the intersection of the group
* with another group. The group is split in a direction to fill empty
* cells left by the splitting group.
*
* #param onGroup
* #param directionToMoveSplitCells
* #return
*
*/
public function split(onGroup:CellGroup, directionToMoveSplitCells:String):CellGroup
{
if (!hasIntersection(onGroup))
return this;
var numCellsToSplit:int = 0;
var splitCells:Array;
var newGroup:CellGroup;
var numberOfCellsToSplit:int;
var splitStartIndex:int;
var resultingGroupStartIndex:int;
if (directionToMoveSplitCells == "RIGHT")
{
numberOfCellsToSplit = endIndex - onGroup.startIndex + 1;
splitStartIndex = length - numberOfCellsToSplit;
splitCells = trimCells(splitStartIndex, numberOfCellsToSplit);
resultingGroupStartIndex = onGroup.endIndex + 1;
if (splitCells.length > 0)
{
newGroup = row.createGroup(splitCells, resultingGroupStartIndex)
newGroup.nextGroup = nextGroup;
if (newGroup.nextGroup)
newGroup.nextGroup.previousGroup = newGroup;
newGroup.previousGroup = this;
nextGroup = newGroup;
}
}
else
{
numberOfCellsToSplit = onGroup.endIndex - startIndex + 1;
splitStartIndex = 0;
splitCells = trimCells(splitStartIndex, numberOfCellsToSplit);
resultingGroupStartIndex = onGroup.startIndex - splitCells.length;
if (splitCells.length > 0)
{
newGroup = row.createGroup(splitCells, resultingGroupStartIndex)
newGroup.previousGroup = previousGroup;
if (newGroup.previousGroup)
newGroup.previousGroup.nextGroup = newGroup
previousGroup = newGroup;
newGroup.nextGroup = this;
var newX:int = (onGroup.endIndex + 1) * cellSize.width;
x = newX;
}
}
removeArrayOfCellsFromGroup(splitCells);
row.joinGroups();
row.updateGroupIndices();
repositionCellsInGroup();
return newGroup;
}
public function split(onGroup:CellGroup, directionToMoveSplitCells:String):CellGroup
{
if (!hasIntersection(onGroup))
return this;
var newGroup:CellGroup;
if (directionToMoveSplitCells == "RIGHT")
{
newGroup = splitGroupAndMoveSplitCellsRight(onGroup);
if (!newGroup)
return;
insertAsNextGroupInLinkedList(newGroup);
}
else
{
newGroup = splitGroupAndMoveSplitCellsLeft(onGroup);
if (!newGroup)
return;
insertAsPreviousGroupInLinkedList(newGroup);
x = (onGroup.endIndex + 1) * cellSize.width;
}
removeArrayOfCellsFromGroup(splitCells);
row.joinGroups();
row.updateGroupIndices();
repositionCellsInGroup();
return newGroup;
}
private function splitGroupAndMoveSplitCellsRight(onGroup:CellGroup):CellGroup
{
var numCellsToSplit:int = endIndex - onGroup.startIndex + 1;
var splitStartIndex:int = length - numberOfCellsToSplit;
var splitCells:Array = trimCells(splitStartIndex, numberOfCellsToSplit);
if (!splitCells.length)
return null;
var resultingGroupStartIndex:int = onGroup.endIndex + 1;
return row.createGroup(splitCells, resultingGroupStartIndex);
}
private function splitGroupAndMoveSplitCellsLeft(onGroup:CellGroup):CellGroup
{
var numCellsToSplit:int = onGroup.endIndex - startIndex + 1;
var splitStartIndex:int = 0;
var splitCells:Array = trimCells(splitStartIndex, numberOfCellsToSplit);
if (!splitCells.length)
return null;
var resultingGroupStartIndex:int = onGroup.startIndex - splitCells.length;
return row.createGroup(splitCells, resultingGroupStartIndex);
}
private function insertAsNextGroupInLinkedList(group:CellGroup):void
{
var currentNextGroup:CellGroup = nextGroup;
if (currentNextGroup)
{
group.nextGroup = currentNextGroup;
currentNextGroup.previousGroup = group;
}
group.previousGroup = this;
nextGroup = group;
}
private function insertAsPreviousGroupInLinkedList(group:CellGroup):void
{
var currentPreviousGroup:CellGroup = previousGroup;
if (currentPreviousGroup)
{
group.previousGroup = currentPreviousGroup;
currentPreviousGroup.nextGroup = group;
}
group.nextGroup = this;
previousGroup = group;
}
/**
* Splits this group into two groups based on the intersection of the group
* with another group. The group is split in a direction to fill empty
* cells left by the splitting group.
*
* #param onGroup
* #param directionToMoveSplitCells
* #return
*
*/
public function split(onGroup:CellGroup, directionToMoveSplitCells:String):CellGroup
{
if(!hasIntersection(onGroup)) return this;
var numCellsToSplit:int = 0;
var splitCells:Array;
var newGroup:CellGroup;
var numberOfCellsToSplit:int;
var splitStartIndex:int;
var resultingGroupStartIndex:int;
numberOfCellsToSplit = (directionToMoveSplitCells == "RIGHT" ? (endIndex - onGroup.startIndex) : (onGroup.endIndex - startIndex)) + 1;
splitStartIndex = directionToMoveSplitCells == "RIGHT" ? (length - numberOfCellsToSplit) : 0;
splitCells = trimCells(splitStartIndex, numberOfCellsToSplit);
resultingGroupStartIndex = directionToMoveSplitCells == "RIGHT" ? (onGroup.startIndex - splitCells.length) : (onGroup.endIndex + 1);
if (splitCells.length > 0)
{
newGroup = row.createGroup(splitCells, resultingGroupStartIndex)
newGroup.nextGroup = nextGroup; //not sure how to not set this from jump
newGroup.previousGroup = previousGroup; //not sure how to not set this from jump
if (newGroup.previousGroup){
newGroup.previousGroup.nextGroup = newGroup;
previousGroup = newGroup;
var newX:int = (onGroup.endIndex + 1) * cellSize.width;
x = newX;
}
if (newGroup.nextGroup) newGroup.nextGroup.previousGroup = newGroup;
else{
newGroup.nextGroup = this;
newGroup.previousGroup = this;
nextGroup = newGroup;
}
}
removeArrayOfCellsFromGroup(splitCells);
row.joinGroups();
row.updateGroupIndices();
repositionCellsInGroup();
return newGroup;
}
This is all that occurs to me. The linked list is really a seperate detail... so maybe it can be refactored out....
public function split(onGroup:CellGroup, directionToMoveSplitCells:String):CellGroup
{
if (!hasIntersection(onGroup))
return this;
valr splitCells:Array;
var newGroup:CellGroup ;
var numberOfCellsToSplit:int;
var splitStartIndex:int;
var resultingGroupStartIndex:int;
if (directionToMoveSplitCells == "RIGHT")
{
numberOfCellsToSplit = this.endIndex - onGroup.startIndex + 1;
splitStartIndex = this.length - numberOfCellsToSplit;
splitCells = trimCells(splitStartIndex, numberOfCellsToSplit);
resultingGroupStartIndex = onGroup.endIndex + 1;
if (splitCells.length > 0)
{
newGroup = row.createGroup(splitCells, resultingGroupStartIndex);
nextGroup=insertGroup(newGroup,this,nextGroup);
}
}
else
{
numberOfCellsToSplit = onGroup.endIndex - startIndex + 1;
splitStartIndex = 0;
splitCells = trimCells(splitStartIndex, numberOfCellsToSplit);
resultingGroupStartIndex = onGroup.startIndex - splitCells.length;
if (splitCells.length > 0)
{
newGroup = row.createGroup(splitCells, resultingGroupStartIndex);
previousGroup=insertGroup(newGroup,previousGroup,this);
var newX:int = (onGroup.endIndex + 1) * cellSize.width;
x = newX;
}
}
removeArrayOfCellsFromGroup(splitCells);
row.joinGroups();
row.updateGroupIndices();
repositionCellsInGroup();
return newGroup;
}
private function insertGroup(toInsert:CellGroup,prior:CellGroup,next:CellGroup):CellGroup
{
toInsert.nextGroup = next;
toInsert.previousGroup = prior;
if (toInsert.nextGroup )
toInsert.nextGroup.previousGroup = toInsert;
if (toInsert.previousGroup )
toInsert.previousGroup.nextGroup = toInsert;
return toInsert;
}
My unindenting of splitCells assigment is to indicate that it is the inoly non-conditional line in the block.
I looked at doing what Anon proposed but I can't see any way to make the code actually better that way.
var groupThatWillReceiveCells = this;
var groupThatWontReceiveCells = onGroup;
if (directionToMoveSplitCells == "RIGHT")
{
groupThatWillReceiveCells = onGroup;
groupThatWontReceiveCells = this;
}
Rename stuff as needed.