Friday, June 25, 2010

Wired thing after adding subview to UIAlertView

There are many discussions about adding UITextField or other UIView to UIAlertView, here are some links:

  1. New info on adding text fields to alerts
  2. Custom UIAlertView (Color chooser)
  3. Add TextField or other control to UIActionSheet or UIAlertView
At first, I used the undocumented API ‘addTextFieldWithValue’, then I found that your APP may be rejected if undocumented API used. so I changed to the second way, as mentioned in Custom UIAlertView (Color chooser), it works, except one thing, look the following pictures:

This is the first time UIAlertView shows, after I click any button, it dismisses. then when it shows again, looks like this:


I don’t know why, seems cocoa touch re-layout the views again or just forget two buttons positions, as the buttons positions are almost the same as when no subviews in UIAlertView. to avoid this, I have to release the UIAlertView each time after it dismiss.

The following is the code, almost the same as Custom UIAlertView (Color chooser) :
@interface FolderAlertView : UIAlertView
{
        UITextView *errorMsg;
        UITextField *folderName;
}

@property (nonatomic, readonly) UITextView *errorMsg;
@property (nonatomic, readonly) UITextField *folderName;

- (void)clear;
- (NSString *)inputText;
- (void)warn;

@end

@implementation
FolderAlertView

@synthesize errorMsg;
@synthesize folderName;

- (id)initWithFrame:(CGRect)frame {
        if (self = [super initWithFrame:frame]) {
              
                errorMsg = [[UITextView alloc] initWithFrame:CGRectZero];
                errorMsg.backgroundColor = [UIColor clearColor];
                errorMsg.textColor = [UIColor whiteColor];
                errorMsg.text = @“illegal name“;
                errorMsg.editable = NO;
                errorMsg.font = [UIFont systemFontOfSize:14];
              
                folderName = [[UITextField alloc] initWithFrame:CGRectZero];
                folderName.backgroundColor = [UIColor whiteColor];
                folderName.clearsOnBeginEditing = YES;
                folderName.font = [UIFont systemFontOfSize:17];
                folderName.placeholder = @"Folder Name";
                folderName.adjustsFontSizeToFitWidth = YES;
                folderName.autocorrectionType = UITextAutocorrectionTypeNo;
              
                [super insertSubview:folderName atIndex:0];
                [super insertSubview:errorMsg atIndex:1];
        }
        return self;
}

- (void)setFrame:(CGRect)rect {
        [super setFrame:CGRectMake(0, 0, rect.size.width, 200)];
        self.center = CGPointMake(320/2, 460/2);
}

- (void)layoutSubviews {
        CGFloat buttonTop;
        for (UIView *view in self.subviews) {
                if ([[[view class] description] isEqualToString:@"UIThreePartButton"]) {
                        view.frame = CGRectMake(view.frame.origin.x, self.bounds.size.height - view.frame.size.height - 15,
                                                                        view.frame.size.width, view.frame.size.height);
                        buttonTop = view.frame.origin.y;
                }
        }
      
        buttonTop -= 7;
        buttonTop -= 60;
        errorMsg.frame = CGRectMake(12, buttonTop, self.bounds.size.width - 24, 60);
      
        buttonTop -= 7;
        buttonTop -= 21;
        folderName.frame = CGRectMake(12, buttonTop, self.bounds.size.width - 24, 21);
}

- (void)clear {
        folderName.text = @"";
        errorMsg.textColor = [UIColor whiteColor];
}

- (NSString *)inputText {
        return folderName.text;
}

- (void)warn {
        errorMsg.textColor = [UIColor redColor];
}

- (void)dealloc {
        [errorMsg release];
        [folderName release];
        [super dealloc];
}

@end

Create folder using SharePoint web service

You can find how to create a folder using SharePoint web service at here http://msdn.microsoft.com/en-us/library/lists.lists.updatelistitems%28v=office.12%29.aspx .
The following XML is how to create a folder under a list directly.
<Batch OnError="Continue" PreCalc="TRUE" ListVersion="0" ViewName="{EF2F5A21-0FD0-4654-84ED-112B4F5A48F8}">
<Method ID="1" Cmd="New">
<Field Name="ID">New</Field>
<Field Name="FSObjType">1</Field>
<Field Name="BaseName">FolderA</Field>
</Method>
</Batch>

But my question is how to create a folder in another folder, you cannot set BaseName to the path, like list/folderA/folderB, as BaseName should be the folder name, cannot contain any special characters. after checking the document above, I found that if you want to update/delete a document, the field FileRef must be provided, like this:
<Batch OnError=“Continue” PreCalc=“TRUE” ListVersion=“0” ViewName=“{EF2F5A21-0FD0-4654-84ED-112B4F5A48F8}”>
<Method ID=“1” Cmd=“Delete”>
<Field Name=“ID”>3</Field>
<Field Name=“FileRef”>http://machinename/sites/siteA/listA/folderA</Field>
</Method>
</Batch>

so FileRef is a much important value for SharePoint to identify a document. then I tried to set FileRef field to the folder path when creating a folder, like this:
<Batch OnError="Continue" PreCalc="TRUE" ListVersion="0" ViewName="{EF2F5A21-0FD0-4654-84ED-112B4F5A48F8}">
<Method ID="1" Cmd="New">
<Field Name="ID">New</Field>
<Field Name="FSObjType">1</Field>
<Field Name="BaseName">FolderB</Field>
<Field Name="FileRef">/listA/FolderA/FolderB</Field>
</Method>
</Batch>
There it is. you can see that folder B is created under folder A.

When will google merge google toolbar bookmarks and chrome bookmars?

any plan? or I have to do it manually

in reference to:

"utmx_section("Header") A fast new browser: Now available for Mac"
- Google Chrome - Get a fast new browser. For PC, Mac, and Linux (view on Google Sidewiki)

I do not use Chrome for MAC

I don't know why, after I open Chrome, the OS is freeze for a few seconds frequently.

BTW, why no version information here?

in reference to:

"utmx_section("Header") A fast new browser: Now available for Mac"
- Google Chrome - Get a fast new browser. For PC, Mac, and Linux (view on Google Sidewiki)

Tuesday, June 22, 2010

Delete SharePoint file via web service

As you know, we can talk to SharePoint via web service, Microsoft has provided some default web services for us, also you can deploy your own web services. In this post I will the state the way to delete a file.

The web service method to delete an item is here, send a xml to SharePoint:
<Batch OnError=“Continue” PreCalc=“TRUE” ListVersion=“0” ViewName=“{EF2F5A21-0FD0-4654-84ED-112B4F5A48F8}”>
<Method ID=“1” Cmd=“Delete”>
<Field Name=“ID”>3</Field>
<Field Name=“FileRef”>
http://Server/[sites/][Site/]Shared Documents/File
</Field>
</Method>
</Batch>

Note that to delete a file, other than deleting other type of item, the field “FileRef” must be provided, the url cannot include any encoded characters(exclude / : * .etc that cannot used as folder/file name in SharePoint), for example the above url include a whitespace, if you encode it to ‘%20’, then SharePoint will report an error or do nothing.

Another wired thing is, In my environment, I can browse SharePoint using both machine IP(http://192.168.0.100/) and machine name(http://sharepointserver/), I can use the machine IP to fetch the file content, but when deleting a file, machine name must be used, or SharePoint will report that unable to find the file.

Wednesday, June 9, 2010

Cascade Order

I’m reading a book “Pro.CSS.and.HTML.Design.Patterns”, as I found so many wired things when using CSS, and I think this book may be helpful for me. and I post some of patterns in the book while learning.

CSS Selector Priority
As a CSS rule(like border:1px solid blue) may be assigned to an element multiple times, we must understand which one will effect the element style, so the following are rules, the priority is from high to low:
  1. !important this has the highest priority, when a rule comes with this, it’s the boss.
  2. style on element here style is the HTML element attribute, like <p style=“margin:2px”/>
  3. ID, again ID is the id of a HTML element. like <div id=“css”/>, then you can use #css to define CSS rules for this div.
  4. CSS class, like .cssClass{...}, also including the pseudo, like .cssClass:after{...}, they have the same priority
  5. HTML element like p, div, br .etc
  6. * this is the universal selector, you can write CSS like this *{padding:1px}, then it applies to every HTML element
Most of time, we use class and ID selectors, but I think class selector is enough, which is at forth priority. especially when I started to use JQuery and JQuery UI, it’s a bad idea to use ID as a CSS selector. as in the HTML page, there may be many elements have the same ID but different element and/or usage, and when you collaborate with others, a good idea is to use multiple class selectors to find an element or apply rules.

Sometimes, you may use a combination of several selectors, for example, #css .cssClass .button{...}, or #css2 .cssClass p {...}. at this time, the one has higher priority when it has more selectors of a higher priority. so in the above example, the first one win, as both of them have ID selector, but the first one has two class selectors, and the second has only one class selector.

Location Priority
What if both selectors have the same number and level of selectors? they’er further prioritized by location. here are the rules, from high priority to low:
  1. <style> in HTML <header>
  2. @import within <style>
  3. <link>
  4. @import within a CSS file attached by <link>
  5. CSS file attached by an end user? how? don’t understand :(
  6. default CSS supplied by a browser
when multiple stylesheets are attached or imported at the same level, stylesheet attached later override stylesheets attached previously.