1 define(['require','Collections','NexcelGroupList','NexcelCellList'], 
  2     function ( require , Collection, nexcelGroupList, nexcelCellList) {
  3     	//Old file dss.js
  4 		/**
  5 		 * A Class to handle with all Nexcel UI based functionalities including the group setup and its highlighting on mouse over and out etc..
  6 		 * @name NexcelUI
  7 		 * @class NexcelUI
  8 		 * @example require('NexcelUI')
  9 		 * @exports NexcelUI
 10 		 * @version 1.0
 11 		 * @module NexcelUI
 12 		 * @augments Collections
 13 		 **/
 14 		var NexcelUI = {
 15 					
 16 					/**
 17 					 * Object totalGroups variable keeps track of the number groups available in the WorkBook 
 18 					 * @name totalGroups
 19 					 * @exports totalGroups 
 20 					 * @version 1.0
 21 					 * @module NexcelUI
 22 					 * @memberOf NexcelUI
 23 					 * @field
 24 					 **/
 25 					totalGroups:0,
 26 					/**
 27 					 * highlightedGroupSet keeps track of the groups which are highlighted in teh screen 
 28 					 * @name highlightedGroupSet
 29 					 * @exports highlightedGroupSet 
 30 					 * @version 1.0
 31 					 * @module NexcelUI
 32 					 * @memberOf NexcelUI
 33 					 * @field
 34 					 * @type {Collections.Set}
 35 					 **/
 36 					highlightedGroupSet : require("Collections").Set(),
 37 					/**
 38 					 * groupNames keeps track of the group names of the workBook 
 39 					 * @name groupNames
 40 					 * @exports groupNames 
 41 					 * @version 1.0
 42 					 * @module NexcelUI
 43 					 * @memberOf NexcelUI
 44 					 * @field
 45 					 * @type {Collections.Set}
 46 					 **/
 47 					groupNames:[],
 48 					/**
 49 					 * @name setUpNexcelGroups
 50 					 * @memberOf NexcelUI
 51 					 * @method 
 52 					 * Setup all the groups with UI including applying style to the group and keeping the details.
 53 					 * @param {GroupObj[]} groupList
 54 					 * @return null
 55 					 * @function
 56 					 * 
 57 					 */
 58 					setUpNexcelGroups:function(groupList){
 59 						for(var i=0; i<groupList.length; i++){
 60 							
 61 							var groupObj = groupList[i];
 62 							require('NexcelGroupList').add(groupObj.id, groupObj.name, groupObj);
 63 							var WorkBook = require('WorkBook');
 64 							var DomObjects = require('DomObjects');
 65 							if(require('WorkBook').ACTIVE_SHEET_ID == groupObj.sheetId){
 66 								//require('GridView').applyStyleToGroupTitleAndColName(groupObj);//, groupObj.color);
 67 								var divName = require('GridView').setUpGroupHeader(groupObj);
 68 								require('GridView').setUpGroupHeaderWidth(divName, groupObj);
 69 							}
 70 						}
 71 					},
 72 					
 73 					/**
 74 					 * @name addGroup					 
 75 					 * @memberOf NexcelUI
 76 					 * @method 
 77 					 * method to add a new group to the sheet, Internally calls the service to create a group in server side and the global id will be returned back.
 78 					 * @param {String} name the group Name
 79 					 * @return newGroupId the id generated for the group is returned.
 80 					 * @function
 81 					 */
 82 					addGroup:function(name, sheetId, groupArea, colNameAvailable, colNameList, tillLastRow, groupTitle, formula){
 83 						if(nexcelGroupList.isExist(name)){
 84 							throw 'Group name already exists.. Please use another name !';
 85 							return;
 86 						}
 87 						var colSize = groupArea.CURR_COL - groupArea.START_COL +1;
 88 						var groupObj = {name:name, sheetId:sheetId, formula:formula, colSize:colSize, colNameAvailable:colNameAvailable, groupTitle:groupTitle};
 89 						groupObj.loc = new Object();
 90 						groupObj.loc.rowEnd = groupArea.CURR_ROW;
 91 						groupObj.loc.rowStart = groupArea.START_ROW;
 92 						groupObj.loc.colEnd = groupArea.CURR_COL;
 93 						groupObj.loc.colStart = groupArea.START_COL;
 94 						groupObj.color = require('UIUtil').randomColor();
 95 						groupObj.colNameList = colNameList;
 96 						var GridView = require('GridView');
 97 						// Create the Group in Server database and Retrieve groupId Synch including adding the column name to column name Table.
 98 						var newGroupId = require('NexcelUIDataService').createGroup(name, sheetId, groupObj.loc, formula, colSize, groupObj.color, colNameAvailable, colNameList, groupTitle);
 99 			
100 						GridView.applyStyleToGroupTitleAndColName(groupObj);
101 						
102 						groupObj.rowEnd = groupArea.CURR_ROW;
103 						groupObj.rowStart = groupArea.START_ROW;
104 						groupObj.colEnd = groupArea.CURR_COL;
105 						groupObj.colStart = groupArea.START_COL;
106 						groupObj.id=newGroupId;
107 						
108 						var row = groupArea.START_ROW;
109 						if(groupTitle){
110 							//GridView.saveCell(sheetId, row, groupArea.START_COL, formula, name);
111 							//row++;
112 							groupObj.groupTitle=1;
113 						}
114 						if(colNameAvailable){
115 							//for(var i =0; i< colSize; i++){
116 							//	GridView.saveCell(sheetId, row, groupArea.START_COL+i, formula, columnNameList[i]);
117 							//}
118 							groupObj.colNameAvailable =1;
119 						}
120 						nexcelGroupList.add(groupObj.id, groupObj.name, groupObj);
121 						GridView.setUpGroupHeader(groupObj);
122 						
123 						GridView.highlighGroupByGroupObj(groupObj, groupObj.color);
124 						return newGroupId;
125 					},
126 					
127 					/**
128 					 * @memberOf NexcelUI
129 					 * @method 
130 					 * method to create sort order div on group so that the range data can be sorted down.
131 					 * @param {Object} groupObject the group Object
132 					 * @return null
133 					 * @function
134 					 * @name createSortDivOnColHeader
135 					 */
136 					//TODO the UI part is pending.
137 					createSortDivOnColHeader:function(groupObj){
138 						var i=0;
139 						var end = groupObj.colSize;
140 						if(groupObj.groupTitle == '1'){
141 							i= end;
142 							end = 2*end;
143 						}
144 						if(groupObj.colNameAvailable =='1'){
145 							for(var col=0;i<end; i++, col++){
146 								var cell = groupObj.obj[i];
147 								$(cell).css("font-weight", "bold");
148 								$(cell).css("background", "#B5C3C7");
149 								$(cell).attr('align', 'center');	
150 								//TODO Add the Sorting Functionality here.
151 								var div = $('<div class="ui-state-default jSBarHelper" style="padding-left: 477.55556535720825px; display: block;"></div>');//<span class="ui-icon ui-icon-triangle-dn"></span>
152 								var span ;
153 								if(groupObj.sorted && groupObj.sorted == SORTING.ASC && groupObj.sortedCol == col){
154 									span = this.GROUP.UI.getSortAscSpan();
155 									$(div).data('sorting', SORTING.ASC);
156 								}
157 								else if(groupObj.sorted && groupObj.sorted == SORTING.DESC && groupObj.sortedCol == col){
158 									span = this.GROUP.UI.getSortDscSpan();
159 									$(div).data('sorting', SORTING.DESC);
160 								}
161 								else{ 
162 									span = this.GROUP.UI.getNoSortingSpan();
163 									$(div).data('sorting', SORTING.NO);
164 								}
165 								$(span).appendTo($(div));
166 								$(div).data('groupName', groupObj.name);
167 								$(div).data('columnName', $($(cell)[0]).html());
168 								$(div).appendTo($(cell));
169 								$(div).click(function(){
170 									var sorting = $(this).data('sorting');
171 									var span = $(this).children()[0];
172 									$(span).remove();
173 									console.log($(this).data('groupName')+" Group Sorting :"+sorting);
174 									if(sorting == SORTING.ASC){
175 										this.GROUP.DATA.SORTDSC($(this).data('groupName'), $(this).data('columnName'));
176 									}
177 									else{
178 										this.GROUP.DATA.SORTASC($(this).data('groupName'), $(this).data('columnName'));
179 									}
180 								});
181 							}
182 						}
183 					},
184 
185 					/**
186 					 * @memberOf NexcelUI
187 					 * @method 
188 					 * method to rename the group sort order div on group so that the range data can be sorted down.
189 					 * @param {String} oldName the old group Name
190 					 * @param {String} newName the new group Name
191 					 * @return null
192 					 * @function
193 					 * @name renameGroup
194 					 */
195 					//TODO Need to check how the Existing Function Usage of the Same Name will be Handled.
196 					renameGroup:function(oldName, newGroupName, colNameAvailable, colNameList){
197 						var groupObj = nexcelGroupList.getGroupObjByName(oldName);
198 						var groupId = nexcelGroupList.getId(oldName);
199 						nexcelGroupList.reName(oldName, newGroupName);
200 						this.highlightGroupById(groupId);
201 						
202 						var group = require('NexcelDataObject').Group();
203 						group.setId(groupId);
204 						group.setName(newGroupName);
205 						group.setColNameAvailable(colNameAvailable);
206 						group.setColNameList(colNameList);
207 			
208 						require('NexcelUIDataService').renameGroup(group);
209 					},
210 					
211 					/**
212 					 * @memberOf NexcelUI
213 					 * @method 
214 					 * method to rename the group sort order div on group so that the range data can be sorted down.
215 					 * @param {Object} groupObject the group Object
216 					 * @return null
217 					 * @function
218 					 * @name deleteGroup
219 					 */
220 					//TODO Need to check how the Existing Function Usage of the Same Name will be Handled.
221 					deleteGroup:function(groupObj){
222 						var dependencyTable = require('DependencyTableController').getDependencyTable();
223 						var targetEqual = require('TreeGenerationHelper').setBinRelDetails(require('CONSTANT').BinOperation.OP_EQUAL, new TREEObjects.EXPRESSION(ObjectType.EXP_VAR, 'Target'), new TREEObjects.CONSTANT(ObjectType.CONSTANT_NAM, groupObj.name));
224 						var sourceTypeEqual = require('TreeGenerationHelper').setBinRelDetails(require('CONSTANT').BinOperation.OP_EQUAL, new TREEObjects.EXPRESSION(ObjectType.EXP_VAR, 'SourceType'), new TREEObjects.CONSTANT(ObjectType.CONSTANT_NAM, '3002'));
225 						var filteredTable = require('EvaluationHelper').applyConstrRelOnRange(dependencyTable, [targetEqual,sourceTypeEqual]);
226 						if(filteredTable.length>1){
227 							var tableNames = [];
228 							for(var i=1; i<filteredTable.length; i++)
229 								tableNames.push(filteredTable[i][3]);
230 							modal({
231 								type  : 'alert',
232 								title : 'Alert',
233 								text  : groupObj.name+" is used in the formulas of the groups - "+tableNames.join(',')+"<br/> Please remove the refernce and delete the group."
234 							});
235 							return false;	
236 						}else{
237 							this.removeAllHighlightByGroupId(groupObj.id);
238 							nexcelGroupList.remove(groupObj.name);
239 							/*for(i=0;i<groupObj.obj.length;i++){
240 								$(groupObj.obj[i]).attr('title', '');
241 								var groupIdList = $(groupObj.obj[i]).data('group');
242 								groupIdList.splice(groupIdList.indexOf(groupObj.id),1);
243 							}*/
244 							
245 							$('#Head'+groupObj.id).remove();
246 							$('#groupNameDiv'+groupObj.id).remove();
247 							require('NexcelUIDataService').deleteGroup(groupObj.id);
248 							return true;
249 						}
250 					},
251 
252 					/**
253 					 * @memberOf NexcelUI
254 					 * @method 
255 					 * method to rename the group sort order div on group so that the range data can be sorted down.
256 					 * @param {Object} groupObject the group Object
257 					 * @return null
258 					 * @function
259 					 * @name applyGroupResult
260 					 * @deprecated
261 					 */
262 					applyGroupResult:function(cell, data, formula, groupName){
263 						console.log('apply Group result......');
264 						var jS = $.sheet.instance[0];
265 						var loc = jS.getTdLocation(cell.td);
266 						if(this.isPartOfAnyGroupWithGroupFormula(loc, data)){
267 							modal({
268 								type  : 'alert',
269 								title : 'Alert',
270 								text  : "Group Formula Applied.. You Cannot Apply Another."
271 							});
272 							return;	
273 						}
274 						//TODO Remove this check, no need to totalGroups
275 						if(!groupName) 
276 							groupName = 'group'+this.totalGroups;
277 						var groupMembers=[], size=0, colSize;
278 						for(i=0;i<data.length;i++){
279 							rowVal=data[i];
280 							colSize = rowVal.length;
281 							for(j=0;j<rowVal.length;j++){
282 								cell = jS.spreadsheets[jS.i][loc.row+i][loc.col+j];
283 								cell.formula = "";
284 								cell.td.html(data[i][j]);
285 								cell.html[0] = data[i][j];
286 								cell.value = data[i][j];	
287 								cell.result = data[i][j];
288 								groupMembers[size++] = cell.td[0];
289 							}
290 						}
291 						var withColHeader = true;
292 						var tillLastRow = false;
293 						var groupTitle = false;
294 						var loc = this.getGroupLocation(groupMembers);
295 						this.addGroup(groupName, jS.i, loc, groupMembers, colSize, withColHeader, tillLastRow, groupTitle , formula);
296 					},
297 					
298 					/**
299 					 * @memberOf NexcelUI
300 					 * @method 
301 					 * If the User Updates teh Formula of Group through Editor, then the new Values will be updated in Group using this method. The data provided WILL HAVE headers.
302 					 * @param {integer} groupId The group id in which the formula is edited.
303 					 * @param {Object[]} value The result after the formula applied
304 					 * @param {String} newFormula The new formula user created..
305 					 * @return null
306 					 * @function
307 					 * @name updateGroupResult
308 					 */
309 					updateGroupResult:function(groupId, values, newFormula){
310 						console.log('updateGroupResult.....');
311 						//this.clearGroupResult(groupId);
312 						var WorkBook = require('WorkBook');
313 						var groupObj = nexcelGroupList.getGroupObjById(groupId);
314 						groupObj.formula = newFormula;
315 						var endRow = groupObj.rowEnd;
316 						if(groupObj.rowEnd==-1)
317 							endRow = WorkBook.getSheetObj(groupObj.sheetId).rows;
318 
319 						var colnameAvailable = nexcelGroupList.isColNameAvailable(groupId);
320 						var headerAvailable = nexcelGroupList.isGroupTitleAvailable(groupId);
321 						var updatedCellList = Collection.ArrayList();
322 						var startRow=parseInt(groupObj.rowStart)-1;
323 						/*if(headerAvailable){
324 							startRow++;
325 						}
326 						var i=0;
327 						if(!colnameAvailable){
328 							values.shift();
329 						}else{
330 							// Update Column name in the result;
331 							i++;
332 						}*/
333 						//Removing Header.
334 						values.shift();
335 						var trList = $('#dataTable tr');
336 						var cellFormula;
337 						var sheetId = groupObj.sheetId;
338 						var sheetObj = WorkBook.getSheetObj(sheetId);
339 						var maxRow = sheetObj.rows;
340 						var activeSheetId = require('WorkBook').ACTIVE_SHEET_ID;
341 						for(var i=0;i<values.length;i++){
342 							rowVal=values[i];
343 							var j=0;
344 							for(col=parseInt(groupObj.colStart);col<=parseInt(groupObj.colEnd);col++){
345 								var nCell = nexcelCellList.isExist(groupObj.sheetId, (startRow+i+1), col);
346 								if(activeSheetId == groupObj.sheetId){
347 									try{
348 										$($(trList[startRow+i]).find('td')[col-1]).html(values[i][j]);// Just Updating teh value in GRID_VIEW. Need to Update the TD_LIST as well
349 									}catch(e){}
350 								}
351 								if(nCell)
352 									nCell.setValue(values[i][j]);
353 								else
354 									nCell = nexcelCellList.addCellWithDetails(groupObj.sheetId, (startRow+i+1), col, cellFormula, values[i][j]);
355 								updatedCellList.add(nCell);
356 								j++;
357 							}
358 							if((startRow+i+1)>maxRow) maxRow = (startRow+i+1);
359 						}
360 						// Clearing Remaining Cells of the Group.
361 						for(; startRow+i <=parseInt(endRow); i++){
362 							for(j=parseInt(groupObj.colStart); j<=parseInt(groupObj.colEnd);j++){
363 								var nCell = nexcelCellList.isExist(groupObj.sheetId, (startRow+i+1),j);
364 								if(!nCell) continue;
365 								nCell.setValue('');
366 								updatedCellList.add(nCell);
367 								if(activeSheetId == groupObj.sheetId){
368 									try{
369 										$($(trList[startRow+i]).find('td')[nCell.getColumn()-1]).html('');// Just Updating teh value in GRID_VIEW. Need to Update the TD_LIST as well
370 									}catch(e){}
371 								}
372 							}
373 						}
374 						if(newFormula){// If formula modified then only the newFormula passed, then only need to be applied dependency.
375 							require(['NexcelUIDataService'],function(nexcelUidataService){
376 								nexcelUidataService.updateGroupFormula(groupId, newFormula);
377 							});
378 						/*	require(['DependencyGraphController'],function(dependencyGraphController){
379 								dependencyGraphController.evaluateGroupDependents(groupObj.name);
380 							});*/
381 						}
382 						if(maxRow > sheetObj.rows){
383 							sheetObj.rows = maxRow+5;
384 							require('WorkBookDataService').updateSheetSize(sheetId, parseInt(maxRow)+5, parseInt(sheetObj.cols));
385 						}
386 						this.CELL.DATA.updateListOfCells(updatedCellList);
387 						//this.createSortDivOnColHeader(groupObj);
388 					},
389 					/**
390 					 *@param dependents	- A Hash map contains the all the dependents updated in the execution 3001_ cell and 3002_ Groups. 
391 					 */
392 					updateCalculatedDependents:function(dependentsArray){
393 						var nexcelCellList = require("NexcelCellList");
394 						var keys = Object.keys(dependentsArray);
395 						for(var i =0; i<keys.length; i++){
396 							var key = keys[i];
397 							if(key.startsWith('3001_')){
398 								var cellName = key.substr(5);
399 								var cell = cellName.split('!');
400 								var sheetObj = require('WorkBook').getSheetObjByName(cell[0]);
401 								var cell = require('GridView').parseLocation(cell[1]);
402 								var cellObj = nexcelCellList.isExist(sheetObj.id, cell.row, cell.col);
403 								require('GridView').saveCell(sheetObj.id, cell.row, cell.col, cellObj.getFormula(), dependentsArray[key]);
404 								//update cell
405 							}else if(key.startsWith('3002_')){
406 								var groupName = key.substr(5);
407 								var groupObj = nexcelGroupList.getGroupObjByName(groupName);
408 								require('NexcelUI').updateGroupResult(groupObj.id, dependentsArray[key], groupObj.formula);
409 							}
410 						}
411 					},
412 					/**
413 					 * @memberOf NexcelUI
414 					 * @method 
415 					 * Returns the group data as An Array with group header & Column Header.The Caller have to Remove wrt Requirements. 
416 					 * @param {String} groupName The new formula user created..
417 					 * @return {Object[]}
418 					 * @function
419 					 * @name getGroupDataArray
420 					 */
421 					getGroupDataArray : function(groupName){
422 						var groupObj = nexcelGroupList.getGroupObjByName(groupName);
423 						var endRow = groupObj.rowEnd;
424 						if(groupObj.rowEnd==-1)
425 							endRow = require('WorkBook').getSheetObj(groupObj.sheetId).rows;
426 						return nexcelCellList.getRangeCellDataArray(groupObj.sheetId, groupObj.rowStart,groupObj.colStart, endRow, groupObj.colEnd );
427 					},
428 					/**
429 					 * @memberOf NexcelUI
430 					 * @method 
431 					 * Returns the group data as An Array with group header & Column Header.The Caller have to Remove wrt Requirements. 
432 					 * @param {String} groupName The new formula user created..
433 					 * @return {Object[]}
434 					 * @function
435 					 * @name getGroupDataArray
436 					 */
437 					getGroupHeaderDataArray : function(groupName){
438 						var groupObj = nexcelGroupList.getGroupObjByName(groupName);
439 						var colName=[];
440 						if(groupObj.colNameAvailable){
441 							for(var i=0; i<groupObj.colNameList.length; i++){
442 								colName.push(groupObj.colNameList[i].name);
443 							}
444 							//TODO remove the for loop, as group have header, then the above wont be empty.
445 							for (var j = 0; groupObj.colNameList.length ==0 &&j < parseInt(groupObj.colSize); j++)
446 								colName.push('Col' + (j + 1));
447 						}
448 						return colName;//nexcelCellList.getRangeCellDataArray(groupObj.sheetId, groupObj.rowStart,groupObj.colStart, endRow, groupObj.colEnd );
449 					},
450 
451 					/**
452 					 * @memberOf NexcelUI
453 					 * @method 
454 					 * Clear Group result Values in the Current HTML View.
455 					 * @param {integer} groupId the group Id
456 					 * @return null
457 					 * @function
458 					 * @name applyGroupResult
459 					 */
460 					clearGroupResult:function(groupId){
461 						var groupObj = nexcelGroupList.getGroupObjById(groupId);
462 						var WorkBook = require('WorkBook');
463 						var sheetNo = WorkBook.ACTIVE_SHEET_ID;
464 						if(sheetNo != groupObj.sheet)
465 							return;// Not able clear as not part of UI Now
466 						var endRow = groupObj.rowEnd;
467 						if(groupObj.rowEnd==-1)
468 							endRow = WorkBook.SHEET_DETAILS[sheetNo].rows;
469 						var trList = $('#dataTable tr');
470 						for(var i=parseInt(groupObj.rowStart);i<=parseInt(endRow); i++){
471 							var tr = trList[i-1];
472 							var tdList = $(tr).find('td');
473 							for(var j=parseInt(groupObj.colStart);j<=parseInt(groupObj.colEnd); j++){
474 								var td= tdList[j-1];
475 								$(td).html('');
476 							}
477 						}
478 					},
479 					
480 					/**
481 					 * @memberOf NexcelUI
482 					 * @method 
483 					 * Once the User Double clicks in the formula and modifies, then the Group Formula need to be reEvaluated, and applied on the cells.
484 					 * @param {integer} groupId the group Id
485 					 * @return null
486 					 * @function
487 					 * @name applyGroupResult
488 					 * @throws It popup alerts on the error happened in parsing.
489 					 */
490 					updateGroupFormula:function(groupId, formula){
491 						if (formula) {
492 							
493 							if (formula.charAt(0) == '=') {
494 								formula = formula.substring(1);
495 							}
496 							require(['ParsingController'],function(parsingController){
497 								try {
498 									var NexcelUI = require('NexcelUI');
499 									var groupObj = require('NexcelGroupList').getGroupObjById(groupId);
500 									parseResult = parsingController.parseAndEvaluateFormula(formula, groupObj.name);
501 									if(!parseResult) return;
502 									if(parseResult.type == require('CONSTANT').ResultType.GROUP){
503 										NexcelUI.updateGroupResult(groupId, parseResult.groupValue, parseResult.formula);
504 									}else if(parseResult.type == ResultType.SINGLE){
505 										// There will not be any Single Result here.	
506 										var resultArray =[];
507 										resultArray[0]=[];
508 										resultArray[0][0] = parseResult.groupValue;
509 										NexcelUI.updateGroupResult(groupId, resultArray, formula);
510 									}else{
511 										//If the result is a Single Result, Converting result to 2D Array 1x1.
512 										var resultArray =[];
513 										resultArray[0]=[];
514 										resultArray[0][0] = parseResult;
515 										NexcelUI.updateGroupResult(groupId, resultArray, formula);
516 									}
517 								} catch (e) {
518 									//console.log(e.toString());
519 									modal({
520 										type  : 'alert',
521 										title : e.name+'!',
522 										text  : e.message
523 									});
524 								}
525 							});
526 						} 
527 					},
528 					
529 					/**
530 					 *	To make the Group Name Header Visible. 
531 					 *  @position  The position of the Group Header
532 					 *  @groupId the Group Id  
533 					 */
534 					showGroupHeader:function(position, groupId){
535 						this.highlightedGroupSet.add(groupId);
536 						$('#Head'+groupId).each(function(){
537 								var name = nexcelGroupList.getName(groupId);
538 								$(this).html(name);
539 								$(this).css('left', $(position).offset().left-3+'px');
540 								$(this).css('top', $(position).offset().top-22+'px');
541 								$(this).show();
542 							});
543 					},
544 					/**
545 					 *	Once the Scroll Bar is Scrolled, then the Header also should be scrolled with the Cell Locations. 
546 					 */
547 					relocateHighlightedGroupHeader:function(){
548 						var groups = this.highlightedGroupSet.getElements();
549 						for(var i=0; i< groups.length; i++){
550 							var groupId = groups[i];
551 							var groupObj = nexcelGroupList.getGroupObjById(groupId);
552 							this.showGroupHeader(groupObj.obj[0], groupId);
553 						}
554 					},
555 
556 					/**
557 					 *  Create a New Div inside the header Container DIV, this Div is Used for Showing the Header. and Used in Showheader Method. 
558 					 */
559 					createGroupHeader:function(groupId, sheet, groupName){
560 						var jS = $.sheet.instance[0];
561 						var headerDiv = "<div class='groupNameHeader' id='Head"+groupId+"'> "+groupName+" </div>";
562 						$($('div.jSEnclosure')[sheet]).append(headerDiv);
563 						$(('#Head'+groupId)).hide();
564 					},
565 
566 					/**
567 					 *Highlight the List of Groups with the provided Column Name.
568 					 * groupList will of the form ({range:range, variable:word, varPos:pos});
569 					 * Refer : EditorController.findGroupContainsVariable 
570 					 */
571 					highlightGroupAndColumn:function(variable, groupList){
572 						this.removeAllHighlightedGroups();
573 						for(var i=0; i<groupList.length; i++){
574 							var groupObj = nexcelGroupList.getGroupObjByName(groupList[i].range);
575 							if(!groupObj) continue;
576 							groupList[i].groupObj = groupObj;
577 							groupColDetails = groupList[i]; 
578 							this.highlightGroupById(groupObj.id);
579 							this.highlightColumnInGroup(groupColDetails);
580 						}
581 					},
582 					/**
583 					 *	 ({range:range, variable:word, varPos:pos, groupObj:groupObj}); 
584 					 */
585 					highlightColumnInGroup:function(groupColDetails){
586 						if(groupColDetails.varPos == -1)
587 							return;
588 						var groupObj = groupColDetails.groupObj;
589 						for(var i=0; i< groupObj.obj.length/groupObj.colSize; i++){
590 							if(i==0 && (nexcelGroupList.isColNameAvailable(groupObj.id) || nexcelGroupList.isGroupTitleAvailable(groupObj.id)))
591 								continue;
592 							if(i==1 && nexcelGroupList.isColNameAvailable(groupObj.id) && nexcelGroupList.isGroupTitleAvailable(groupObj.id))
593 								continue;
594 							var pos = i*groupObj.colSize + groupColDetails.varPos;
595 							$(groupObj.obj[pos]).css('background-color', '#FCFC53');
596 						}
597 					},
598 					/**
599 					 * @author asker
600 					 * Highlight Group By Passing the Id, it internally Calls HighlightGroup with group Details. 
601 					 */
602 					highlightGroupById:function(groupId){
603 						if(!groupId) return;
604 						var groupObj = nexcelGroupList.getGroupObjById(groupId);
605 						var cols = groupObj.colSize;
606 						var obj  = groupObj.obj;
607 						require('GridView').highlighGroupByGroupObj(groupObj, groupObj.color);
608 						nexcelGroupList.highlightGroup(groupId);
609 					},
610 
611 					/**
612 					 *	Removes All teh Highlighted Groups. 
613 					 */
614 					removeAllHighlightedGroups:function(){
615 						require('NexcelGroupList').getAllHighlighedGroup().map(function(groupId) { 
616 							require('NexcelUI').removeAllHighlightByGroupId(groupId);
617 						});
618 					},
619 					
620 					removeAllHighlightByGroupId:function(groupId){
621 						var groupObj = nexcelGroupList.getGroupObjById(groupId);
622 						if(groupObj)
623 							require('GridView').removeHighlightByGroupObj(groupObj);
624 					},
625 
626 					/**
627 					 * Method returns true/false depends on the argument TD is a part of the Selection Area in the Screen. 
628 					 */
629 					isObjectInSelection:function(td, selectionObj){
630 						if(!selectionObj || selectionObj.length == 0)
631 							return;
632 						var jS = $.sheet.instance[0];
633 						var tdLoc = jS.getTdLocation($(td));
634 						var groupLoc = this.getGroupLocation(selectionObj);
635 						if(tdLoc.row<=groupLoc.rowEnd && tdLoc.row>=groupLoc.rowStart && tdLoc.col>=groupLoc.colStart && tdLoc.col<=groupLoc.colEnd)
636 							return true;
637 						else
638 							return false;
639 					},
640 					/**
641 					 * If a Td is Associated with Multiple Groups, still It can be a part of one group have a Group formula.
642 					 * Here this method returns the Group {id:formula} which have the group formula.
643 					 */
644 					getGroupWithFormula:function(td){
645 						var groups=$(td).data('group');
646 						var group = null;
647 						if (groups) {
648 							$(groups).each(function(index, val){
649 								var groupObj = nexcelGroupList.getGroupObjById(val);
650 								if(groupObj.formula){
651 									group = {id:val,groupObj:groupObj};
652 									return;
653 								}
654 							});
655 						}
656 						return group;
657 					},
658 					/**
659 					 * Calculates the Row and Column of x1,y1 and x2,y2 of the Group. 
660 					 * @param {Object} groupObjects
661 					 */
662 					getGroupLocation:function(groupObjects){
663 						var jS = $.sheet.instance[0];
664 						var rowStart = 100000,rowEnd = 0,colStart = 100000,colEnd = 0;
665 						var size = groupObjects.length;
666 						for( var i=0; i<size;i++){
667 							var loc = jS.getTdLocation($(groupObjects[i]));
668 							if(loc.row>rowEnd) rowEnd = loc.row;
669 							if(loc.col>colEnd) colEnd = loc.col;
670 							if(loc.row<rowStart) rowStart = loc.row;
671 							if(loc.col<colStart) colStart = loc.col;
672 						}
673 						return {rowStart:rowStart,rowEnd:rowEnd,colStart:colStart,colEnd:colEnd };
674 					},
675 					/**
676 					 * Returns teh Range of the group like A1:B9, it helps to replace the Formulas.
677 					 * @author asker 
678 					 */
679 					getGroupRange : function(name){
680 						var groupObj = nexcelGroupList.getGroupObjByName(name);
681 						var loc = groupObj.loc;
682 						var col = '';
683 						if(loc.colStart > 26){
684 							col = col + String.fromCharCode(64+parseInt(loc.colStart/26));
685 						}
686 						col = col + String.fromCharCode(64+loc.colStart%26);
687 						var start = col+''+loc.rowStart;
688 						col = '';
689 						if(loc.colEnd > 26){
690 							col = col + String.fromCharCode(64+parseInt(loc.colEnd/26));
691 						}
692 						col = col + String.fromCharCode(64+loc.colEnd%26);
693 						var end = col+''+loc.rowEnd;
694 						return 'SHEET'+(groupObj.sheet+1)+'!'+start+':'+end;
695 					},
696 					/**
697 					 *	Checks for any Object[]- Array is Part of Any Group. 
698 					 */
699 					isPartOfAnyGroup : function(obj, sheet){
700 						for(i=0;i<obj.length;i++){
701 							if(this.isPartOfGroups(obj[i], sheet, nexcelGroupList.getNameList().getElements()))
702 								return true;
703 						}
704 						return false;
705 					},
706 					/**
707 					 *	Checks for any Object[]- Array is Part of Any Group Header or Column names. 
708 					 */
709 					isPartOfAnyGroupHeader : function(obj, sheet){
710 						for(i=0;i<obj.length;i++){
711 							if(this.isPartOfGroupsHeader(obj[i], sheet, nexcelGroupList.getNameList().getElements()))
712 								return true;
713 						}
714 						return false;
715 					},
716 					
717 					/**
718 					 *	groupObj - [][] Two dimentional Array Value Objects. 
719 					 *
720 					 *	Checks for any Object is Part of Any Group with Group Formula. 
721 					 */
722 					isPartOfAnyGroupWithGroupFormula : function(groupObj){
723 						var groupWithFormulaList = require('NexcelGroupList').getGroupObjListOnSheet(groupObj.sheetId);
724 						for(i=0;i<groupWithFormulaList.size();i++){
725 							grpObj = groupWithFormulaList.get(i);
726 							if (grpObj.id!= groupObj.id && grpObj.formula){
727 								x11 = groupObj.colStart,
728 					            y11 = groupObj.rowStart,
729 					            x12 = groupObj.colEnd,
730 					            y12 = groupObj.rowEnd,
731 					            x21 = grpObj.colStart,
732 					            y21 = grpObj.rowStart,
733 					            x22 = grpObj.colEnd,
734 					            y22 = grpObj.rowEnd,
735 					            
736 					            leftX = Math.max(x11, x21),
737 							    // Right x
738 							    rightX = Math.min(x12, x22),
739 							    // Bottom y
740 							    botY = Math.max(y11, y21),
741 							    // TopY
742 							    topY = Math.min(y12, y22);
743 			        	  		if (rightX >= leftX && topY >= botY)
744 									return grpObj;
745 							}
746 						}
747 						return false;
748 					},
749 					/**
750 					 * @args groups
751 					 * It checks whether the group have any Group Formula. if so returns true else false.
752 					 */
753 					isGroupHasGroupFormula:function(groupIds){
754 						if(groupIds){
755 							for(var gNo = 0; gNo<groupIds.length; gNo++)
756 							if(nexcelGroupList.getGroupObjById(groupIds[gNo]).formula){
757 								return true;
758 							}
759 						}
760 						return false;
761 					},
762 					/**
763 					 * This method returns whether the provided Location is a Part of any group provided in groupNames
764 					 * groupNames [] It is an Array of group name.
765 					 * loc --> loc.row, loc.col 
766 					 *	@author asker 
767 					 */
768 					isPartOfGroups : function(tdObj, sheet, groupNames){
769 						var jS = $.sheet.instance[0];
770 						var loc = jS.getTdLocation(tdObj);
771 						for(var i=0;i<groupNames.length;i++){
772 							// checking for whether the cell is in the same sheet or another sheet with same location and in the Same Sheet.
773 							var grpObj = nexcelGroupList.getGroupObjByName(groupNames[i]);
774 							//Ensuring in the Same Sheet
775 							if(sheet == grpObj.sheet){
776 								//Ensuring inside teh Group Area.
777 								if(loc.row<=grpObj.rowEnd && loc.row>=grpObj.rowStart && loc.col>=grpObj.colStart && loc.col<=grpObj.colEnd){
778 									return true;
779 								}
780 							}
781 						}
782 						return false;
783 					},
784 					/**
785 					 * This method returns whether the provided Location is a Part of any group header provided in groupNames
786 					 * groupNames [] It is an Array of group name.
787 					 * loc --> loc.row, loc.col 
788 					 * @author asker 
789 					 */
790 					isPartOfGroupsHeader : function(tdObj, sheet, groupNames){
791 						var row = $(tdObj).parent().index()+1;//data('row');
792 						var col = $(tdObj).index()+1;//data('col');
793 						for(var i=0;i<groupNames.length;i++){
794 							// checking for whether the cell is in the same sheet or another sheet with same location and in the Same Sheet.
795 							var grpObj = nexcelGroupList.getGroupObjByName(groupNames[i]);
796 							//Ensuring in the Same Sheet
797 							if(sheet == grpObj.sheetId && (parseInt(grpObj.colNameAvailable) || parseInt(grpObj.groupTitle))){
798 								if(parseInt(grpObj.colNameAvailable) && parseInt(grpObj.groupTitle)){
799 									if(row>=parseInt(grpObj.rowStart) && row<=(parseInt(grpObj.rowStart)+1) && col>=parseInt(grpObj.colStart) && col<=parseInt(grpObj.colEnd))
800 										return true;
801 								}
802 								else if(row == parseInt(grpObj.rowStart) && col>=parseInt(grpObj.colStart) && col<=parseInt(grpObj.colEnd))
803 									return true;
804 							}
805 						}
806 						return false;
807 					},
808 					/**
809 					 * 
810 					 */
811 					BODY:{
812 						/**
813 						 *	Once the Nexcel Body onload completed, this method will be called. 
814 						 */
815 						onLoad:function(){
816 							require('loading').hide();	
817 							require('GridView').setViewRowHeight();
818 						}
819 					},
820 					/**
821 					 * 	Parser related functions to Dss comes on this package.
822 					 * @author Asker 
823 					 */
824 					parser :{
825 						
826 						/**
827 						 * 	Replaces the Formula with the Ranges of the Spreedsheet.
828 						 * 	@param {Object} formula
829 						 */
830 						applyGroupRange:function(formula){
831 							var groupNames =  nexcelGroupList.getNamesSortByNameLength();
832 							for(var i=0; i<groupNames.length;i++){
833 								var name = groupNames[i];
834 								while(formula.indexOf(name) != -1){
835 									var range = this.getGroupRange(name);
836 									formula = formula.replace(groupNames[i], range);
837 								}
838 							}
839 							return formula;
840 						}
841 					},
842 					
843 					
844 					/**
845 					 *	Header Associated All method Comes Here. 
846 					 */
847 					HEADER:{
848 						setUpHeaderEnclosure:function(){
849 							$($('div.jSEnclosure')).each(function(pos, obj){
850 									$(obj).append($('<div class="headerContainer"></div>'));
851 							});
852 						}
853 					},
854 					
855 					CPANEL:{	
856 						init:function(){
857 							var div= $('<div/>');
858 							$(div).append("<input value='Open Dubugger' type='button' onclick='debuggerDialog.openDialog()'/>");
859 							$(div).append("<input value='Draw Dracula Graph' type='button' onclick='draculaDebuggerController.show()'/>");
860 							$('.jSHeader').prepend(div);
861 						}
862 					},
863 					
864 					/**
865 					 *	A Group of Functions which will sort the Given Group either in ASC or DSC Order. 
866 					 */
867 					GROUP:{
868 						UI:{
869 							getSortAscSpan:function(span){
870 								var span = $('<span ></span>');
871 								$(span).css({
872 									"width:": 18,
873 									"height": 16,
874 									"background-image": "url('css/images/arrow-dn.gif')",
875 									"background-color":"#B5C3C7"
876 								  });
877 								  return span;
878 							},
879 							getSortDscSpan:function(span){
880 								var span = $('<span ></span>');
881 								$(span).css({
882 									"width:": 18,
883 									"height": 16,
884 									"background-image": "url('css/images/arrow-up.gif')",
885 									"background-color":"#B5C3C7"
886 								  });
887 							 return span;
888 							},
889 							getNoSortingSpan:function(span){
890 								var span = $('<span ></span>');
891 								$(span).css({
892 									"width:": 18,
893 									"height": 16,
894 									"background-image": "url('css/images/arrow-ud.gif')",
895 									"background-color":"#B5C3C7"
896 								  });
897 								   return span;
898 							}
899 						},
900 						DATA:{
901 							/**
902 							 *	dSS.GROUP.DATA.SORTASC 
903 							 */
904 							SORTASC:function(groupName, colName){
905 								var data = dSS.GROUP.DATA.getGroupData(groupName);
906 								var groupId = nexcelGroupList.getId(groupName);
907 								var headerList = Collection.ArrayList();
908 								var header = data[0];
909 								headerList.addAll(header);
910 								var index = headerList.indexOf(colName);
911 								data.shift();
912 								data.sort(function(a,b){return a[index]>b[index]?1:-1;});
913 								var groupObj = nexcelGroupList.getGroupObjById(groupId); 
914 								groupObj.sorted = SORTING.ASC;
915 								groupObj.sortedCol = index;
916 								dataService.updateGroupSorting(groupObj);
917 								data.unshift(header);
918 								dSS.updateGroupResult(groupId, data);
919 							},
920 							SORTDSC:function(groupName, colName){
921 								var data = dSS.GROUP.DATA.getGroupData(groupName);
922 								var groupId = nexcelGroupList.getId(groupName);
923 								var headerList = Collection.ArrayList();
924 								var header = data[0];
925 								headerList.addAll(header);
926 								var index = headerList.indexOf(colName);
927 								data.shift();
928 								data.sort(function(a,b){return a[index]<b[index]?1:-1;});
929 								var groupObj = nexcelGroupList.getGroupObjById(groupId); 
930 								groupObj.sorted = SORTING.DESC;
931 								groupObj.sortedCol = index;
932 								dataService.updateGroupSorting(groupObj);
933 								data.unshift(header);
934 								dSS.updateGroupResult(groupId, data);
935 							},
936 							/**
937 							 * dSS.GROUP.DATA.getGroupData
938 							 * Returns the Data with Column Header, It removes only the Header - Group name if Available. 
939 							 * @param {Object} rangeName
940 							 */
941 							getGroupData : function(rangeName){
942 								var nexcelGroupList = require('NexcelGroupList');
943 								var groupId = nexcelGroupList.getId(rangeName);
944 								if(groupId == -1) throw {name:'Invalide Range', message:rangeName+" range not found"};// The group is not yet Available
945 								var data = require('NexcelUI').getGroupDataArray(rangeName);
946 								data = require('EvaluationHelper').removeEmptyRows(data);
947 								var groupTitleAvailable = nexcelGroupList.isGroupTitleAvailable(groupId);
948 								//if(groupTitleAvailable)
949 								//	data.shift();
950 								return data;
951 							},
952 							/**
953 							 *	If no column name header present it will be added. and filtered according to the provided header. 
954 							 */
955 							getGroupDataWithColumnHeader:function(rangeName, header){
956 								var nexcelGroupList = require('NexcelGroupList');
957 								var data = require('NexcelUI').GROUP.DATA.getGroupData(rangeName);
958 								var groupId = nexcelGroupList.getId(rangeName);
959 								var colNameAvailable = nexcelGroupList.isColNameAvailable(groupId);
960 								//if(!colNameAvailable){
961 								data.unshift(header);
962 								//}else{
963 								//	data[0]=header;// Renaming to the provided header.
964 								//}
965 								return require('EvaluationHelper').filterResult(data, header);
966 							},
967 							/**
968 							 * Returns the Data without Column Header, It removes only the Header - Group name if Available. 
969 							 * @param {Object} rangeName
970 							 */
971 							getGroupDataWithoutHeader : function(rangeName){
972 								var groupId = nexcelGroupList.getId(rangeName);
973 								var data = require('NexcelUI').GROUP.DATA.getGroupData(rangeName);
974 								var colNameAvailable = nexcelGroupList.isColNameAvailable(groupId);
975 								//if(data && colNameAvailable)
976 								//	data.shift();
977 								return data;
978 							},
979 							/**
980 							 *	returns an Array of Cell Objects 
981 							 */
982 							getGroupCellObjects : function(groupObj){
983 								var data = nexcelCellList.getRangeCellArray(groupObj.sheetId, groupObj.rowStart, groupObj.colStart, groupObj.rowEnd, groupObj.colEnd);
984 								var groupTitleAvailable = nexcelGroupList.isGroupTitleAvailable(groupObj.groupId);
985 								//if(groupTitleAvailable)
986 								//	data.shift();
987 								return data;
988 							},
989 							/**
990 							 * Returns the Data without Column Header, It removes only the Header - Group name if Available. 
991 							 * @param {Object} groupObj
992 							 */
993 							getGroupCellWithoutHeader : function(groupObj){
994 								var data = require('NexcelUI').GROUP.DATA.getGroupCellObjects(groupObj);
995 								var colNameAvailable = nexcelGroupList.isColNameAvailable(groupObj.groupId);
996 								//if(data && colNameAvailable)
997 								//	data.shift();
998 								return data;
999 							},
1000 							
1001 							evaluateGroup:function(groupId){
1002 								var NexcelUI = require('NexcelUI');
1003 								var groupObj = nexcelGroupList.getGroupObjById(groupId);
1004 								programs = [];
1005 								parser.parse(groupObj.formula);
1006 								parsingController.postParseAction(programs);
1007 								var parseResult = evaluationController.evaluateNexcelPrograms(programs);
1008 								parseResult.formula = groupObj.formula;
1009 								
1010 								if(parseResult.type == ResultType.GROUP){
1011 									NexcelUI.updateGroupResult(groupId, parseResult.groupValue, parseResult.formula);
1012 								}else if(parseResult.type == ResultType.SINGLE){
1013 									// There will not be any Single Result here.	
1014 									var resultArray =[];
1015 									resultArray[0]=[];
1016 									resultArray[0][0] = parseResult.groupValue;
1017 									NexcelUI.updateGroupResult(groupId, resultArray, groupObj.formula);
1018 								}else{
1019 									//If the result is a Single Result, Converting result to 2D Array 1x1.
1020 									var resultArray =[];
1021 									resultArray[0]=[];
1022 									resultArray[0][0] = parseResult;
1023 									NexcelUI.updateGroupResult(groupId, resultArray, groupObj.formula);
1024 								}
1025 							}
1026 						},
1027 						FORMULA:{
1028 							format:function(programs){
1029 								return programs.join('. \n')+'.';
1030 							}
1031 						},
1032 					},
1033 					/**
1034 					 *	All teh Cell Associated data transaction Happens here. 
1035 					 */
1036 					CELL:{
1037 						DATA:{
1038 							cellList:[],
1039 							saveCell:function(sheetNo, row, col, formula, value){
1040 								var NexcelUI = require('NexcelUI');
1041 								var sheetId= require('WorkBook').sheetIdList[sheetNo];
1042 								var cell = nexcelCellList.isExist(sheetId, row, col);
1043 								if(cell){
1044 									//Refer WorkBook.getSheetObj(sheetId)
1045 									//TODO Refactor the code.
1046 									var sheetNo = NexcelUI.SHEET.getSheetNo(cell.getSheet()); 
1047 									NexcelUI.CELL.DATA.updateSheetCell(sheetNo, cell.getRow(), cell.getColumn(),  formula, value); // Updating in the Sheet
1048 									NexcelUI.CELL.DATA.updateNexcelCell(cell.getId(), formula, value);	// Updating CellList and database
1049 									
1050 								}else{
1051 									cell = nexcelCellList.addCellWithDetails(sheetId, row, col, formula, value);
1052 									var cellId = dataService.createCell(cell.json());
1053 									cell.setId(cellId);
1054 								}
1055 								NexcelUI.CELL.DEPENDENCY.evaluateDependents(cell.getId());
1056 							},
1057 							updateNexcelCell:function(cellId, formula, value){
1058 								var cell = nexcelCellList.getCell(cellId);
1059 								cell.setValue(value);
1060 								cell.setFormula(formula);
1061 								dataService.updateCell(cell.json());
1062 							},
1063 							
1064 							getSheetCellValue:function(sheetId, row, col){
1065 								var cell = nexcelCellList.isExist(sheetId, row, col);
1066 								if(cell)
1067 									return cell.getValue();
1068 							},
1069 							
1070 							/**
1071 							 *	Saves a List of Cells. No call Back. 
1072 							 */
1073 							updateListOfCells:function(updatedCellList){
1074 								if(updatedCellList.size()>0)
1075 									require('WorkBookDataService').updateListOfCells(updatedCellList.json());
1076 							},
1077 							/**
1078 							 *	Simply ReEvaluates teh Value of teh Cell 
1079 							 */
1080 							evaluateCell:function(cellId){
1081 								var cell = nexcelCellList.getCell(cellId);
1082 								var parseResult = parsingController.parseAndEvaluateFormula(cell.getFormula());
1083 								if(!parseResult) return;
1084 								
1085 								if(parseResult.type == ResultType.GROUP){
1086 									//TODO Never the result will be group result.
1087 									dSS.applyGroupResult(cell, parseResult.groupValue, parseResult.formula, parseResult.groupName);
1088 									console.log('----------------------------------Jquery Sheet Group Result produced -----------------------------------------------');								
1089 								}else if(parseResult.type == ResultType.SINGLE){
1090 									dSS.CELL.DATA.updateNexcelCell(cellId, cell.getFormula(), parseResult.groupValue);	// Updating CellList and database
1091 									var sheetNo = dSS.SHEET.getSheetNo(cell.getSheet()); 
1092 									dSS.CELL.DATA.updateSheetCell(sheetNo, cell.getRow(), cell.getColumn(), cell.getFormula(), cell.getValue()); // Updating in the Sheet
1093 								}
1094 							}
1095 						},
1096 						FORMULA:{
1097 							
1098 						},
1099 						DEPENDENCY:{
1100 							generateDependency:function(sheetId, row, col, formula){
1101 								parsingController.parseFormula(formula);
1102 								dependencyController.applyDependency(DEP_SOURCE_TYPE.CELL, sheetId, row, col, programs);
1103 							},
1104 							setUpAllCellDependency:function(){
1105 								var cellArray =nexcelCellList.getElements();
1106 								for(var i=0; i< cellArray.length; i++){
1107 									var cell = cellArray[i];
1108 									if(cell.getFormula())
1109 										dSS.CELL.DEPENDENCY.generateDependency(DEP_SOURCE_TYPE.CELL, cell.getSheetId(), cell.getRow(), cell.getColumn(), cell.getFormula());
1110 								}						
1111 							},
1112 
1113 							/**
1114 							 *	All the Groups and Cells Depends on this cell Need to be ReEvaluated. 
1115 							 */
1116 							evaluateDependents:function(cellId){
1117 								var cell = nexcelCellList.getCell(cellId);
1118 								var sheetNo = dSS.SHEET.getSheetNo(cell.getSheet()); 
1119 								var jS=$.sheet.instance[0];
1120 								var td = jS.spreadsheets[sheetNo][cell.getRow()][cell.getColumn()].td;
1121 								var groups = $(td).data('group');
1122 
1123 								var cellDepOnCellList = nexcelCellList.getCellDependentsOnCell(cellId);
1124 								var groupDepOnCellList = nexcelGroupList.getGroupDependentsOnCell(cellId);
1125 								//TODO Evaluate the Groups..
1126 
1127 								for(var i=0; groups && i<groups.length; i++){
1128 									//TODO Remove Commented Dependency calculation
1129 								//	dSS.GROUP.DEPENDENCY.evaluateDependents(groups[i]);
1130 								}
1131 							}
1132 						},
1133 					
1134 						/**
1135 						 * This method returns whether the provided Location is a Part of any group provided in groupNames
1136 						 * groupNames [] It is an Array of group name.
1137 						 * loc --> loc.row, loc.col 
1138 						 *	@author asker 
1139 						 */
1140 						getListOfGroupObjCellBelongTo : function(sheetId, row, column){
1141 							var groupList = Collection.ArrayList();
1142 							var groupNames = nexcelGroupList.getNameList();
1143 							for(var i=0;i<groupNames.size();i++){
1144 								// checking for whether the cell is in the same sheet or another sheet with same location and in the Same Sheet.
1145 								var groupObj = nexcelGroupList.getGroupObjByName(groupNames.get(i));
1146 								//Ensuring in the Same Sheet
1147 								var endRow = groupObj.rowEnd;
1148 								if(sheetId == groupObj.sheetId){
1149 									if(groupObj.rowEnd==-1)
1150 										var endRow = require('WorkBook').getSheetObj(groupObj.sheetId).rows;
1151 									//Ensuring inside teh Group Area.
1152 									if(row<=endRow && row>=groupObj.rowStart && column>=groupObj.colStart && column<=groupObj.colEnd){
1153 										groupList.add(groupObj);
1154 									}
1155 								}
1156 							}
1157 							return groupList;
1158 						},
1159 						/**
1160 						 * Converts the Object array to Cells By Adding to the dSS Cell DB. 
1161 						 * @param {Object} obj 
1162 						 */
1163 						getCellListFromObjects:function(sheetNo, groupObjects){
1164 							var cellList=new Object();
1165 							cellList.newCellList=Collection.ArrayList();
1166 							cellList.updatedCellList=Collection.ArrayList();
1167 							cellList.allCellList=Collection.ArrayList();
1168 							var jS=$.sheet.instance[0];
1169 							var sheetId = require('WorkBook').sheetIdList[sheetNo];
1170 							for(var i=0; i< groupObjects.length; i++){
1171 								var obj = groupObjects[i];
1172 								var loc = jS.getTdLocation(obj);
1173 								var cell =nexcelCellList.isExist(sheetId, loc.row, loc.col);
1174 								if(cell){
1175 									cellList.updatedCellList.add(cell);
1176 									cellList.allCellList.add(cell);
1177 								}
1178 								else{
1179 									cell = jS.spreadsheets[sheetNo][loc.row][loc.col];
1180 									nexcelCell = nexcelCellList.addCellWithDetails(sheetId, loc.row, loc.col, cell.formula, cell.value);
1181 									cellList.newCellList.add(nexcelCell);
1182 									cellList.allCellList.add(nexcelCell);		
1183 								}
1184 							}
1185 							return cellList;
1186 						}
1187 					},
1188 					
1189 					DEPENDENCY:{
1190 						
1191 						pendingQueue : require('Collections').Queue() // Queue consists of Object {sheetId, row, col}
1192 					}
1193 		};
1194 		return NexcelUI;
1195 	}
1196 );