Repository: flex-asjs Updated Branches: refs/heads/develop 771010510 -> e019d1c11
Add FileBrowserWithFilter plus some doc fixes Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/e019d1c1 Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/e019d1c1 Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/e019d1c1 Branch: refs/heads/develop Commit: e019d1c11179cefd7868fc952a1332c322802a91 Parents: 7710105 Author: DESKTOP-RH4S838\Yishay <yishayj...@hotmail.com> Authored: Tue Jul 11 14:46:23 2017 +0300 Committer: DESKTOP-RH4S838\Yishay <yishayj...@hotmail.com> Committed: Tue Jul 11 14:46:23 2017 +0300 ---------------------------------------------------------------------- .../main/flex/org/apache/flex/file/FileProxy.as | 9 +++ .../org/apache/flex/file/beads/FileBrowser.as | 26 ++++---- .../flex/file/beads/FileBrowserWithFilter.as | 63 ++++++++++++++++++++ .../org/apache/flex/file/beads/FileModel.as | 2 +- .../src/main/resources/basic-manifest.xml | 1 + 5 files changed, 87 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/e019d1c1/frameworks/projects/Network/src/main/flex/org/apache/flex/file/FileProxy.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Network/src/main/flex/org/apache/flex/file/FileProxy.as b/frameworks/projects/Network/src/main/flex/org/apache/flex/file/FileProxy.as index 38c2fe8..f71ce67 100644 --- a/frameworks/projects/Network/src/main/flex/org/apache/flex/file/FileProxy.as +++ b/frameworks/projects/Network/src/main/flex/org/apache/flex/file/FileProxy.as @@ -63,16 +63,25 @@ package org.apache.flex.file } } + /** + * @copy org.apache.flex.core.IAlertModel#lastModified + */ public function get lastModified():uint { return (model as FileModel).lastModified; } + /** + * @copy org.apache.flex.file.IFileModel#name + */ public function get name():String { return (model as FileModel).name; } + /** + * @copy org.apache.flex.file.IFileModel#type + */ public function get type():String { return (model as FileModel).type; http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/e019d1c1/frameworks/projects/Network/src/main/flex/org/apache/flex/file/beads/FileBrowser.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Network/src/main/flex/org/apache/flex/file/beads/FileBrowser.as b/frameworks/projects/Network/src/main/flex/org/apache/flex/file/beads/FileBrowser.as index 5d48c00..523f619 100644 --- a/frameworks/projects/Network/src/main/flex/org/apache/flex/file/beads/FileBrowser.as +++ b/frameworks/projects/Network/src/main/flex/org/apache/flex/file/beads/FileBrowser.as @@ -50,11 +50,11 @@ package org.apache.flex.file.beads private var _strand:IStrand; COMPILE::SWF { - private var _delegate:flash.net.FileReference; + protected var delegate:flash.net.FileReference; } COMPILE::JS { - private var _delegate:WrappedHTMLElement; + protected var delegate:WrappedHTMLElement; } /** @@ -76,9 +76,9 @@ package org.apache.flex.file.beads COMPILE::JS public function createDelegate():void { - _delegate = document.createElement('input') as WrappedHTMLElement; - _delegate.setAttribute('type', 'file'); - goog.events.listen(_delegate, 'change', fileChangeHandler); + delegate = document.createElement('input') as WrappedHTMLElement; + delegate.setAttribute('type', 'file'); + goog.events.listen(delegate, 'change', fileChangeHandler); } /** @@ -87,8 +87,8 @@ package org.apache.flex.file.beads COMPILE::SWF public function createDelegate():void { - _delegate = new flash.net.FileReference(); - _delegate.addEventListener(flash.events.Event.SELECT, fileSelectHandler); + delegate = new flash.net.FileReference(); + delegate.addEventListener(flash.events.Event.SELECT, fileSelectHandler); } /** @@ -97,9 +97,9 @@ package org.apache.flex.file.beads COMPILE::SWF protected function fileSelectHandler(event:flash.events.Event):void { - host.model = new FileModel(_delegate); - // _delegate reference passed to model, so cleanup this bead to keep encapsulation - _delegate.removeEventListener(flash.events.Event.SELECT, fileSelectHandler); + host.model = new FileModel(delegate); + // delegate reference passed to model, so cleanup this bead to keep encapsulation + delegate.removeEventListener(flash.events.Event.SELECT, fileSelectHandler); createDelegate(); } @@ -115,11 +115,11 @@ package org.apache.flex.file.beads { COMPILE::SWF { - _delegate.browse(); + delegate.browse(); } COMPILE::JS { - _delegate.click(); + delegate.click(); } } @@ -151,7 +151,7 @@ package org.apache.flex.file.beads COMPILE::JS private function fileChangeHandler(e:org.apache.flex.events.Event):void { - host.model = new FileModel((_delegate as HTMLInputElement).files[0]); + host.model = new FileModel((delegate as HTMLInputElement).files[0]); } } http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/e019d1c1/frameworks/projects/Network/src/main/flex/org/apache/flex/file/beads/FileBrowserWithFilter.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Network/src/main/flex/org/apache/flex/file/beads/FileBrowserWithFilter.as b/frameworks/projects/Network/src/main/flex/org/apache/flex/file/beads/FileBrowserWithFilter.as new file mode 100644 index 0000000..f66ea32 --- /dev/null +++ b/frameworks/projects/Network/src/main/flex/org/apache/flex/file/beads/FileBrowserWithFilter.as @@ -0,0 +1,63 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.file.beads +{ + COMPILE::SWF + { + import flash.net.FileFilter; + } + + /** + * The FileBrowserWithFilter adds a filtering option to FileBrowser + * + * + * @toplevel + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.9 + */ + public class FileBrowserWithFilter extends FileBrowser + { + public var filter:String = ""; + + /** + * + * @copy org.apache.flex.file.beads.FileBrowser#browse() + * @flexjsignorecoercion HTMLInputElement + */ + + override public function browse():void + { + COMPILE::JS + { + (delegate as HTMLInputElement).accept = filter; + super.browse(); + } + COMPILE::SWF + { + // TODO translate mime types too + var flashFilter:String = filter.replace(/,/g, ";"); + flashFilter = flashFilter.replace(/\./g, "*."); + var fileFilter:FileFilter = new FileFilter(filter, flashFilter); + delegate.browse([fileFilter]); + } + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/e019d1c1/frameworks/projects/Network/src/main/flex/org/apache/flex/file/beads/FileModel.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Network/src/main/flex/org/apache/flex/file/beads/FileModel.as b/frameworks/projects/Network/src/main/flex/org/apache/flex/file/beads/FileModel.as index 10e07b3..9d65c75 100644 --- a/frameworks/projects/Network/src/main/flex/org/apache/flex/file/beads/FileModel.as +++ b/frameworks/projects/Network/src/main/flex/org/apache/flex/file/beads/FileModel.as @@ -76,7 +76,7 @@ package org.apache.flex.file.beads /** - * @copy org.apache.flex.core.IAlertModel#title + * @copy org.apache.flex.file.IFileModel#size */ public function get size():Number { http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/e019d1c1/frameworks/projects/Network/src/main/resources/basic-manifest.xml ---------------------------------------------------------------------- diff --git a/frameworks/projects/Network/src/main/resources/basic-manifest.xml b/frameworks/projects/Network/src/main/resources/basic-manifest.xml index 4a55df4..59fcbd1 100644 --- a/frameworks/projects/Network/src/main/resources/basic-manifest.xml +++ b/frameworks/projects/Network/src/main/resources/basic-manifest.xml @@ -25,6 +25,7 @@ <component id="CORSCredentialsBead" class="org.apache.flex.net.beads.CORSCredentialsBead"/> <component id="FileProxy" class="org.apache.flex.file.FileProxy"/> <component id="FileBrowser" class="org.apache.flex.file.beads.FileBrowser"/> + <component id="FileBrowserWithFilter" class="org.apache.flex.file.beads.FileBrowserWithFilter"/> <component id="FileLoader" class="org.apache.flex.file.beads.FileLoader"/> <component id="FileUploader" class="org.apache.flex.file.beads.FileUploader"/> <component id="FileUploaderWithResponseData" class="org.apache.flex.file.beads.FileUploaderWithResponseData"/>