topical media & game development

talk show tell print

actionscript-application-flickr-SearchPanel.mx

actionscript-application-flickr-SearchPanel.mx [swf] flex


  <?xml version="1.0" encoding="utf-8"?>
  <!--
          SearchPanel
  -->
  
  <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*"
                  xmlns:ui="*"
                  xmlns:uiSearch="*" 
                  >
                  
          <mx:Metadata>
                  [Event(name="search",type="com.adobe.flickr.events.SearchEvent")]
          </mx:Metadata>                        
                  
          <mx:states>
                  <mx:State name="optionsState">
                          <mx:AddChild position="lastChild">
                                  <mx:Label text="User:" left="10" top="84"/>
                          </mx:AddChild>
                          <mx:SetProperty target="{userName}" name="visible" value="true" />
                          <mx:SetProperty target="{historyGrid}" name="visible" value="false" />
                          <mx:SetProperty target="{optionButton}" name="direction" value="up" />
                          <mx:AddChild position="lastChild">
                                  <mx:Label x="10" y="136" text="Date Taken:"/>
                          </mx:AddChild>
                          <mx:AddChild position="lastChild">
                                  <mx:DateField id="minDateTaken" x="80" y="159"
                                          toolTip="Fill in to set the date of the earliest photos."/>
                          </mx:AddChild>
                          <mx:AddChild position="lastChild">
                                  <mx:DateField id="maxDateTaken" x="80" y="189"
                                          toolTip="Fill in to set the date of the latest photos."/>
                          </mx:AddChild>
                          <mx:AddChild position="lastChild">
                                  <mx:Label x="21" y="161" text="between"/>
                          </mx:AddChild>
                          <mx:AddChild position="lastChild">
                                  <mx:Label x="46" y="191" text="and"/>
                          </mx:AddChild>
                  </mx:State>
          </mx:states>
                  
          <mx:Script>
          <![CDATA[
                  import mx.events.ValidationResultEvent;
                  import com.adobe.flickr.SearchCriteria;
                  import com.adobe.flickr.events.*;
                  import mx.utils.ArrayUtil;
                  import mx.controls.Alert;
                  import mx.core.DragSource;
                  import mx.collections.ArrayCollection;
                  import mx.events.DragEvent;
                  import mx.events.ListEvent;
                  import mx.managers.DragManager;
                  
                  [Bindable]
                  public var criteria:SearchCriteria = new SearchCriteria();
                  
                  // handleGridClick is called when a row from the History grid
                  // as been selected. It clears the tags and replaces it with
                  // the contents of that row.
                  
                  private function handleGridClick( event:ListEvent ) : void
                  {
                          criteria.copyInto(SearchCriteria(event.target.selectedItem));
                  }
                  
                  private function goSearch( save:Boolean=false ) : void
                  {
                          var vr:ValidationResultEvent = validateSearch.validate();
                          if( vr.type == ValidationResultEvent.INVALID ) {
                                  return;
                          }
                          
                          var event:SearchEvent = new SearchEvent();
                          event.criteria = criteria;
                          dispatchEvent( event );
                          
                          if( save ) {
                                  historyGrid.addSearchTerm( criteria );
                          }
                  }
                  
                  public function appendSearch( event:SearchEvent ) : void
                  {
                          if( event.criteria.tags != null ) {
                                  if( tags.text.length > 0 ) tags.text += " ";
                                  tags.text += event.criteria.tags;
                          }
                          if( event.criteria.userName != null ) {
                                  userName.text = event.criteria.userName;
                                  currentState = "optionsState";
                          }
                          if( event.criteria.nsid != null ) {
                                  criteria.nsid = event.criteria.nsid;
                          }
                  }
                  
                  private function showMoreOrLess() : void
                  {
                          if( currentState == "optionsState" ) {
                                  currentState = "";
                          } else {
                                  currentState = "optionsState";
                          }
                  }
                  
                  public function clear() : void
                  {
                          tags.text = "";
                          tagMode.selected = true;
                          userName.text = "";
                          if( minDateTaken != null ) minDateTaken.selectedDate = null;
                          if( maxDateTaken != null ) maxDateTaken.selectedDate = null;
                          
                          criteria.clear();
                  }
                  
                  public function deleteItems( event:TrashcanEvent ) : void
                  {
                          historyGrid.deleteItems(event);
                          clear();
                  }
                  
                  public function deleteSelectedItem() : void
                  {
                          historyGrid.deleteSelectedItem();
                          clear();
                  }
          ]]>
          </mx:Script>
          
          <!-- these bindings automatically transfer the contents of fields
               into the criteria variable.
            -->
          <mx:Binding source="tags.text" destination="criteria.tags" />
          <mx:Binding source="tagMode.selected" destination="criteria.tagMode" />
          <mx:Binding source="userName.text" destination="criteria.userName" />
          <mx:Binding source="minDateTaken.selectedDate" destination="criteria.minDateTaken" />
          <mx:Binding source="maxDateTaken.selectedDate" destination="criteria.maxDateTaken" />
          
          <!-- Validation -->
          
          <mx:Model id="searchModel">
                  <fields>
                          <tags>{tags.text}</tags>
                          <user>{userName.text}</user>
                  </fields>
          </mx:Model>
          
          <ui:actionscript_application_flickr_ui_search_SearchValidator id="validateSearch"
                  userName="{userName.text}" tags="{tags.text}"
                  listener="{tags}" />
          
          <!-- User Interface -->
          
          <mx:Label x="10" y="10" text="Tags:"/>
          
          <mx:TextInput id="tags" left="10" top="27" right="42"
                                  text="{criteria.tags}"
                                  toolTip="Search for tags associated with photos. Separate tags with commas."
                                  enter="goSearch(true)"/>
                                  
          <ui:actionscript_application_flickr_ui_GoButton id="goButton"
                                  right="9" top="29" 
                                  toolTip="Searchs for photos that matches the tags and/or user information"
                                  click="goSearch(true)"/>
                                  
          <mx:CheckBox left="10" top="57" label="All of the tags" 
                                  selected="{criteria.tagMode}" 
                                  toolTip="Check to search for photos that contain all of the tags; uncheck to search for photos with any of the tags."
                                  id="tagMode"/>
                                  
          <ui:actionscript_application_flickr_ui_search_OptionsButton id="optionButton" right="9" top="57"
                                  direction="down"
                                  toolTip="Shows or hides additional search options"
                                  click="showMoreOrLess()" />
                                  
          <mx:TextInput id="userName" left="10" top="103" right="45"
                          text="{criteria.userName}"
                          toolTip="Searchs for photos taken by this Flickr user."
                          visible="false"
                          enter="goSearch(true)"/>
                          
          <ui:actionscript_application_flickr_ui_search_HistoryGrid id="historyGrid" left="10" right="10" top="83" bottom="10"
                                   itemClick="handleGridClick(event)"
                                   dragEnabled="true">
          </ui:actionscript_application_flickr_ui_search_HistoryGrid>
  
  </mx:Canvas>
  


(C) Æliens 27/08/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.