
/**
 * file Shortcut.js with user shortcut
 * @author Janusz Rygał
 * @date 12.08.2008 
 */
Ext.namespace("Wpi.oms");

/**
 * @class Shortcut
 * shortcut class
 */
Shortcut = function( id_ , image_url_, text_ , x_, y_, url_, windowId_, type_){
		/**
		 * intialize method
		 */
 		init: new function(){
		 		if(!x_)
		 			x_ = 10;
		 		if(!y_)
		 			y_ = 10;
		 		if(image_url_ == false)
 					image_url_ = 'Icon_Universal.png';	
 		}	
 		
 		/**id*/
 		this.id = id_;
 		/**main panel*/
 		this.panel;
 		
 		/**url to open*/
 		this.url = url_;
 		
 		/**id of the window*/
 		this.windowId = windowId_;
 		
 		/**image url*/
 		this.imageUrl = image_url_;
 		
 		/**icon text*/
 		this.winText = text_.trim();
 		
 		/**x coordinate*/
 		this.x    = x_;
 		
 		/**y coordinate*/
 		this.y    = y_;
 		
 		/**type of the icon*/
 		this.type = type_;

        this.shrId = 'ShortCut_-_'+this.windowId+'_-_'+this.winText+'_-_'+this.url+'_-_'+this.id;

 		/**
 		 * method to show context menu
 		 */
 		this.contextMenu = function(event, item){
 				tmpArray = this.id.split('_-_');
 			  	this.windowId = tmpArray[1]; 
 			  	this.url  	 = tmpArray[tmpArray.length - 2];	
 			  	this.winText = tmpArray[tmpArray.length - 3];
 				this.shid    = tmpArray[tmpArray.length - 1];
 				context.menu.clickedShortcut = this;
 		 		event.stopEvent();   
 		 		context.menu.showConMenu(event, this.type);           
 		 }
		
		/**
		 * method to create shortcut
		 */
 		this.createShortcut = function(){
 				 
 				iconWidth = 48;
 				yShadowOffset = 1;
 				if(this.winText.length*7 > iconWidth){
 					iconWidth = this.winText.length*9;
 					diff      = iconWidth - 48;
 					if(diff >= 2){
 						yShadowOffset = parseInt(diff/2);
 					}
 				}	
 				
 				align = 'center';
 				if(iconWidth > 48)
 					align = 'left';

                var mainTextY = this.y + 20;

 				this.panel = new Ext.Panel({
 							width: iconWidth,
 							height: 65,
 							x: this.x,
 							y: this.y,
 							draggable: true,
 							renderTo: 'x-shortcuts',
 							floating: true,
 							windowId: this.windowId,
 							url: this.url,
 							style: 'z-index: 5000;',
 							id:  'ShortCut_-_'+this.windowId+'_-_'+this.winText+'_-_'+this.url+'_-_'+this.id,
 							text: this.winText,
 							items:[
 									new Ext.Panel({
 											width: iconWidth,
 											floating: true,
 											shadow: false,
 											x: 1,
                                            id: this.shrId + '_-_sub',
 											y: 1,
 											height: 48,
 											bodyStyle: "background-color: transparent;  cursor: pointer;",
 											border: false,
 											html: "<div title='"+context.translator.translate('sector_desc_'+this.windowId)+"' align='left'><img style='cursor: pointer;' id='"+this.shrId+"_-_img' src='/../../imc/images/omsImages/main/bigIcons/"+this.imageUrl+"' ></img></div>"
 										})	
 								  ],
 							html: "<div align='" + align + "' style='position: absolute; top: "+51+"px; left: "+1+"px; color: black; cursor: pointer;'>"+this.winText+"</div>   <div align='" + align + "' style='position: absolute; top: "+50+"px; left: "+0+"px; color: white; cursor: pointer;'>"+this.winText+"</div> ",
 							bodyStyle: "background-color: transparent; cursor: pointer; z-index: 5000;",
 							shadow: false,
 							border: false,
 							draggable: {
							        insertProxy: false,
							        onDrag : function(e){
							            var pel = this.proxy.getEl();
							            this.x = pel.getLeft(true);
							            this.y = pel.getTop(true);
							            var s = this.panel.getEl().shadow;
							            if (s) {
							                s.realign(this.x, this.y, pel.getWidth(), pel.getHeight());
							            }
							        },
							        endDrag : function(e){
							           this.panel.setPosition(this.x, this.y);
							           arr  = this.panel.id.split('_-_');
                                       
							           icId = arr[arr.length - 1];
							           context.menu.updateIconPosition(icId, this.x, this.y);
							        }
							    }
 						});	
 			   
 			   
 			  


             this.panel.show();
             this.panel.render();

             elem = Ext.get('ShortCut_-_'+this.windowId+'_-_'+this.winText+'_-_'+this.url+'_-_'+this.id);
 			 elem.type = this.type;

 			 elem.on("contextmenu", this.contextMenu,elem, true);
 			 if(this.type == 'STANDARD'){
		 			  elem.on('dblclick', function(bl, el){
		 			  				tmpArray = this.id.split('_-_');
		 			  				this.windowId = tmpArray[1];
		 			  				this.shid    = tmpArray[tmpArray.length - 1];
		 			  				this.url  	 = tmpArray[tmpArray.length - 2];
		 			  				this.winText = tmpArray[tmpArray.length - 3];
		 			  				this.type    = 'standard';
		 			  		 		context.menu.programs.openProgramWindow(this);
		 			  		 });
		 	 }
		 	 else{
		 	 		elem.on('dblclick', function(bl, el){
		 	 				tmpArray = this.id.split('_-_');
		 			  		this.windowId = tmpArray[1];
		 			  		this.shid    = tmpArray[tmpArray.length - 1];
		 			  		this.url  	 = tmpArray[tmpArray.length - 2];
		 			  		this.winText = tmpArray[tmpArray.length - 3];
		 			  		this.type    = 'ajax';
		 	 				var arr = this.url.split('/');
		 	 				context.applyModule(this, false);
		 	 				//alert(arr[0]+'-----'+arr[1]);
		 	 		});
		 	 }

             /*var sub = Ext.get(this.shrId + '_-_sub');
             sub.on('click', function(){
                 alert('jas');
             });
             
             if(this.type == 'STANDARD'){
		 			  sub.on('dblclick', function(bl, el){
		 			  				tmpArray = this.id.split('_-_');
		 			  				this.windowId = tmpArray[1];
		 			  				this.shid    = tmpArray[tmpArray.length - 2];
		 			  				this.url  	 = tmpArray[tmpArray.length - 3];
		 			  				this.winText = tmpArray[tmpArray.length - 4];
		 			  				this.type    = 'standard';
		 			  		 		context.menu.programs.openProgramWindow(this);
		 			  		 });
		 	 }
		 	 else{
		 	 		sub.on('dblclick', function(bl, el){
		 	 				tmpArray = this.id.split('_-_');
		 			  		this.windowId = tmpArray[1];
		 			  		this.shid    = tmpArray[tmpArray.length - 2];
		 			  		this.url  	 = tmpArray[tmpArray.length - 3];
		 			  		this.winText = tmpArray[tmpArray.length - 4];
		 			  		this.type    = 'ajax';
		 	 				var arr = this.url.split('/');
		 	 				context.applyModule(this, false);
		 	 				//alert(arr[0]+'-----'+arr[1]);
		 	 		});
		 	 }*/
 		}
 		
 		
 }

