aparajita/Cup

trying to use code only doesn't work

SAMGARTNER opened this issue · 0 comments

Hello, I have been trying to use CUP with code only, no Interface Builder stuff, unfortunately it is not working. I have a already tested a regular implementation of JQuery File Upload with no issues in my server, but with cup it doesn't even attempt to call the server function.

Can someone please help me with this? The array controller works fine and it attempts to send the file by showing "cupDidStartQueue:" at the console log but it doesn't really call the server function.
This is the code:

//
// AppController.j
// FlickrPhoto
//
// Created by Ross Boucher.
// Copyright 2008 - 2010, 280 North, Inc. All rights reserved.

@import <Foundation/Foundation.j>
@import <AppKit/AppKit.j>
@import <Foundation/CPString.j>
@import <Cup/Cup.j>



@implementation AppController :  CPObject
        {
      	CPArrayController queueController;
		CPTableView picturesTableView;
		CPDictionary pictureData;
		CPTableColumn theColumn;
		CPTableColumn sizeColumn;
		CPButton addPictureButton;
		CPButton sendPictureButton;
		CPScrollView picturesTableViewScrollView;
		Cup myCup;
		CPArrayController picturesArrayController;
		BOOL                logging ;
        
        }   
        
        


- (void)applicationDidFinishLaunching:(CPNotification)aNotification
        {
	        
	    var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],
        contentView = [theWindow contentView];


        myCup = [[Cup alloc] init];
        picturesArrayController =  [[CPArrayController alloc] init];
		myCup.queueController = picturesArrayController;
		self.logging = true;
		[myCup setDelegate:self];
		queueController = [[CPArrayController alloc] initWithContent:nil]; 
		var second = [[CPView alloc] initWithFrame:CGRectMake(200, 0, 300, 310)];
    	[second setBackgroundColor:[CPColor whiteColor]];

		var secondBox = [[CPBox alloc] initWithFrame:CGRectMake(10, 10, CGRectGetWidth([second bounds])-20, CGRectGetHeight([second bounds])-20)];
	
	
		addPictureButton = [[CPButton alloc] initWithFrame:CGRectMake(0, 0, 120, 30)];
		[addPictureButton setTitle:@"agregar imagen"];
		[addPictureButton setTarget:myCup];   
		[addPictureButton setAction:@selector(addFiles:)];
	
	
    	picturesTableViewScrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(0, 50, CGRectGetWidth([secondBox bounds]), CGRectGetHeight([secondBox bounds])-50)];
      	[picturesTableViewScrollView setBorderType:CPBezelBorder];
    	picturesTableView = [[CPTableView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth([picturesTableViewScrollView bounds]), CGRectGetHeight([picturesTableViewScrollView bounds])-50)];
     	[picturesTableView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
     
    	addPictureButton = [[CPButton alloc] initWithFrame:CGRectMake((((CGRectGetWidth([secondBox bounds])/2)*0.2)/2), ((((CGRectGetHeight([secondBox bounds]) - CGRectGetHeight([picturesTableViewScrollView bounds])))*0.2)/2), ((CGRectGetWidth([secondBox bounds])/2)*0.8),  ((CGRectGetHeight([secondBox bounds]) - CGRectGetHeight([picturesTableViewScrollView bounds]))*0.8))];
		[addPictureButton setTarget:myCup];   
		[addPictureButton setAction:@selector(addFiles:)];
		sendPictureButton = [[CPButton alloc] initWithFrame:CGRectMake((CGRectGetWidth([secondBox bounds])/2)+(((CGRectGetWidth([secondBox bounds])/2)*0.2)/2), ((((CGRectGetHeight([secondBox bounds]) - CGRectGetHeight([picturesTableViewScrollView bounds])))*0.2)/2), ((CGRectGetWidth([secondBox bounds])/2)*0.8),  ((CGRectGetHeight([secondBox bounds]) - CGRectGetHeight([picturesTableViewScrollView bounds]))*0.8) )];
		[sendPictureButton setTitle:@"send"];
		[addPictureButton setTitle:@"add imagpictureen"];
		[sendPictureButton setTarget:self];   
		[sendPictureButton setAction:@selector(bla:)];
     
    	myCup.dropTarget = picturesTableView;
    	[picturesTableView setUsesAlternatingRowBackgroundColors:YES];
    	[picturesTableView setAllowsMultipleSelection:YES];
    	sizeColumn = [[CPTableColumn alloc] initWithIdentifier:@"sizeColumn"];
		theColumn = [[CPTableColumn alloc] initWithIdentifier:@"theColumn"];
		[theColumn setWidth:250];
		[sizeColumn setWidth:50];
		[[theColumn headerView] setStringValue:@"Name"];
		[[sizeColumn headerView] setStringValue:@"Size"];
		[picturesTableView addTableColumn:sizeColumn];
		[picturesTableView addTableColumn:theColumn];
		[picturesTableView setGridColor:[CPColor redColor]];
		[picturesTableView setRowHeight:23.0];
        [theColumn bind:CPValueBinding toObject:picturesArrayController withKeyPath:@"arrangedObjects.name" options:nil];
		[sizeColumn bind:CPValueBinding toObject:picturesArrayController withKeyPath:@"arrangedObjects.size" options:nil];
		
		
		[picturesTableViewScrollView setHasVerticalScroller:YES];
      	[picturesTableViewScrollView setHasHorizontalScroller:YES];
      	[picturesTableViewScrollView setAutoresizesSubviews:YES];
      	[picturesTableViewScrollView setAutoresizingMask:CPViewWidthSizable|CPViewHeightSizable];
      	[picturesTableViewScrollView setDocumentView:picturesTableView];
		
        [secondBox addSubview:picturesTableViewScrollView];
		[second addSubview:secondBox];
        [secondBox addSubview:addPictureButton];
    	[secondBox addSubview:sendPictureButton];
    	
    	[contentView addSubview:second];
	
		[theWindow orderFront:self];
	
		// Uncomment the following line to turn on the standard menu bar.
		[CPMenu setMenuBarVisible:YES];
        }
        
        
-(void)bla:(id)sender
	{	
	/*var bodyElement = [CPPlatform mainBodyElement];
    var input = document.createElement("input");
    input.className = "cpdontremove";
    input.setAttribute("type", "text");
    input.setAttribute("id", "myinput");
    input.style.visibility = "hidden";
    bodyElement.appendChild(input);
    var allInputs = $( ":input" );
	console.log(allInputs);*/
	var formData = new FormData();
	
	/*formData.append('ean', '75755885949494');
	formData.append('reference_code', '0');
	formData.append('description', 'value');
	formData.append('reference_name', 'value');
	formData.append('line_name', 'value');
	formData.append('origin', 'value');
	formData.append('maker', 'value');
	formData.append('color_code', '0');
	formData.append('color_name', 'value');
	formData.append('color_hex', 'value');
	formData.append('size', 'value');
	formData.append('kind', 'value');
	formData.append('type', 'value');
	formData.append('type_code', '0');
	formData.append('stock_ammount', '0');
	formData.append('production_stock', '0');
	formData.append('price', '0');
	formData.append('retail_price', '0');
	formData.append('wholesale_price', '0');
	formData.append('megasale_price', '0');
	formData.append('size_order', '1');
	formData.append('discount', '0');
	formData.append('retail_discount', '0');
	formData.append('wholesale_discount', '0');
	formData.append('megasale_discount', '0');*/
	//var options = [myCup options];
	//options.formData = formData;
	[myCup setValue:@"/picture/upload" forKey:@"URL"];
	//[myCup setOptions:options];
	[sender bind:@"enabled" toObject:myCup withKeyPath:@"uploading" options:nil];
	var data = [myCup start:sender];
	}
        
- (int)numberOfRowsInTableView:(CPTableView)aTableView 
{
    return [picturesArrayController.arrangedObjects count];
}

- (id)tableView:(CPTableView)aTableView objectValueForTableColumn:(CPTableColumn)aTableColumn row:(int)rowIndex 
{
    return [picturesArrayController.arrangedObjects objectAtIndex:rowIndex];
}

- (CPView) tableView:(CPTableView) aTableView viewForTableColumn:(CPTableColumn)aTableColumn row:(CPInteger)aRowIndex 
{
	
	var dataView = [aTableColumn dataViewForRow:aRowIndex];
	if ([[aTableColumn identifier] isEqualToString:@"sizeColumn"]) {
        var sizeFormatter = [[CPByteCountFormatter alloc] init];
	[dataView setFormatter:sizeFormatter];
    }
	return dataView;
}

- (BOOL)cup:(Cup)aCup willAddFile:(CupFile)aFile
{
    if (logging)
        console.log("%s %s", _cmd, [aFile description]);

    return YES;
}

- (void)cup:(Cup)aCup didAddFile:(CupFile)aFile
{
    if (logging)
        console.log("%s %s", _cmd, [aFile description]);
}

- (BOOL)cup:(Cup)aCup willSubmitFile:(CupFile)aFile
{
    if (logging)
        console.log("%s %s", _cmd, [aFile description]);

    return YES;
}

- (BOOL)cup:(Cup)aCup willSendFile:(CupFile)aFile
{
    if (logging)
        console.log("%s %s", _cmd, [aFile description]);

    return YES;
}

- (void)cup:(Cup)aCup uploadDidSucceedForFile:(CupFile)aFile
{
    if (logging)
        console.log("%s %s", _cmd, [aFile description]);
}

- (void)cup:(Cup)aCup uploadDidFailForFile:(CupFile)aFile
{
    if (logging)
        console.log("%s %s", _cmd, [aFile description]);
}

- (void)cup:(Cup)aCup uploadDidCompleteForFile:(CupFile)aFile
{
    if (logging)
        console.log("%s %s", _cmd, [aFile description]);
}

- (void)cup:(Cup)aCup uploadWasStoppedForFile:(CupFile)aFile
{
    if (logging)
        console.log("%s %s", _cmd, [aFile description]);

    [[CPAlert alertWithMessageText:[CPString stringWithFormat:@"Transfer of “%@” has been stopped.", [aFile name]]
                     defaultButton:@"OK"
                   alternateButton:nil
                       otherButton:nil
         informativeTextWithFormat:@""] runModal];
}

- (void)cup:(Cup)aCup uploadForFile:(CupFile)aFile didProgress:(JSObject)progress
{
    if (logging)
        console.log("%s %s: %s", _cmd, [aFile description], CPDescriptionOfObject(progress));
}

- (void)cup:(Cup)aCup uploadsDidProgress:(JSObject)progress
{
    if (logging)
        console.log("%s %s", _cmd, CPDescriptionOfObject(progress));
}

- (void)cupDidStart:(Cup)aCup
{
    if (logging)
        console.log("%s", _cmd);
}

- (void)cupDidStop:(Cup)aCup
{
    if (logging)
        console.log("%s", _cmd);
}

- (void)cupDidStartQueue:(Cup)aCup
{
    if (logging)
        console.log("%s", _cmd);
}

- (void)cupDidClearQueue:(Cup)aCup
{
    if (logging)
        console.log("%s", _cmd);
}

- (void)cupDidStopQueue:(Cup)aCup
{
    if (logging)
        console.log("%s", _cmd);
}

- (void)cup:(Cup)aCup fileInputDidSelectFiles:(CPArray)files
{
    if (logging)
        console.log("%s %s", _cmd, [files description]);
}

- (void)cup:(Cup)aCup didPasteFiles:(CPArray)files
{
    if (logging)
        console.log("%s %s", _cmd, [files description]);
}

- (void)cup:(Cup)aCup didDropFiles:(CPArray)files
{
    if (logging)
        console.log("%s %s", _cmd, [files description]);
}

- (void)cup:(Cup)aCup wasDraggedOverWithEvent:(jQueryEvent)anEvent
{
    if (logging)
        console.log("%s %o", _cmd, anEvent);
}

- (BOOL)cup:(Cup)aCup willSendChunkForFile:(CupFile)aFile
{
    if (logging)
        console.log("%s %s", _cmd, [aFile description]);

    return YES;
}
- (void)cup:(Cup)aCup chunkDidSucceedForFile:(CupFile)aFile
{
    if (logging)
        console.log("%s %s", _cmd, [aFile description]);
}

- (void)cup:(Cup)aCup chunkDidFailForFile:(CupFile)aFile
{
    if (logging)
        console.log("%s %s", _cmd, [aFile description]);
}

- (void)cup:(Cup)aCup chunkDidCompleteForFile:(CupFile)aFile
{
    if (logging)
        console.log("%s %s", _cmd, [aFile description]);
}
    
@end

UPDATE

Never mind I just found the mistake. I was trying to translate the screencast into code so I was setting the queue controller myself

picturesArrayController = [[CPArrayController alloc] initWithContent:nil]; myCup.queueController = picturesArrayController;

instead I had to get the reference directly from the Cup Object like this.

picturesArrayController = [myCup queueController];