EXT 可选择图片列表的表单控件实现
先看一下表单效果:
点击图标,显示图标列表:
实现代码:
         var appform = new Ext.form.FormPanel({
 	        id: 'appform',
 	        cardStep:0,
 	        url:Adc.url.appAction,
 	        padding:'10px 20px',
 	        labelWidth: 80,
 	        baseCls: 'x-plain',
 	        method:'POST',
 	        defaults: {
 	            xtype: 'textfield'
 	        },
 	        items:[{
 	            fieldLabel: '编号',
 	            name : 'appId',
                 hidden:true,
 	            value : appId,
 	            anchor :'100%'
 	        },{
 	            fieldLabel: '名称',
 	            name : 'appName',
 	            allowBlank:false, //不允许为空
 	            blankText:'页面名称不能为空',
 	            emptyText:'请输入应用名称',
 	            maxLength:20,
 	            anchor :'100%'
 	        },
 	        {
 	            fieldLabel: '应用分类',
 	            name : 'catlogId',
 	            //hidden:true,
 	             readOnly : !me.editMode,
                // value :me.catalogId,
 	             xtype:'catalogselectfield',
                 //emptyText:'请选择',
                 //allowBlank:false, //不允许为空
 	            action:Adc.url.getCatlogTreeMethod,
 	            catId:Adc.constant.APP_CATLOG_ID,
 	            anchor :'100%'
 	        },
 	         {
                fieldLabel: '应用图标',
                name : 'appIcon',
                xtype:'appIconSelectField',
                imageFilePath:'resources/appDev/images/appIcon/',
                value:'resources/appDev/images/appIcon/defaultmenu_icon.png',
                anchor :'100%'
             }
 	         ,
 	        {
 	            xtype : 'textarea',
 	            fieldLabel: '描述',
 	            name : 'appDesc',
 	            allowBlank:true,
 	            emptyText:'请输入应用描述信息',
 	            maxLength:200,
 	            flex: 1,
 	            anchor :'100% 30%'
 	        },
 	        {
                 fieldLabel: '模板',
                 name : 'tplId',
                 allowBlank:false, //不允许为空
                 xtype:'templateselectfield',
                 anchor :'100%'
             },
 	        {
 	            fieldLabel: '状态',
 	            name : 'appStatus',
 	            hidden:true,
 	            value:'0',
 	            anchor :'100%'
 	        },{
 	            name : 'action',
 	            hidden:true,
 	            value:Adc.url.createAppMethod,
 	            anchor :'100%'
 	        },{
                 fieldLabel: '应用首页',
                 name : 'idxPageId',
                 value:me.pageId,
                 hidden:true,
                 anchor :'100%'
             }]
 	    });
AppIconSelectField.js
 Ext.ns('Adc.components');
 Adc.components.AppIconSelectField = Ext.extend(Ext.form.TextField,{
	    imageFilePath:'resources/appDev/images/appIcon/',
	    imageFilePreffix:'topmenu_icon',
	    imageFileSuffix:'.png',
	    maxImgCount:120,
	    constructor:function(config){
	        Ext.apply(this,config);
	        this.initImageData();
	        Adc.components.AppIconSelectField.superclass.constructor.call(this,config);
	    },
	    initImageData:function(){
	        var data ={};
	        data.images=[];
	        for(i=1;i<this.maxImgCount;i++){
	            //i=i<10?'0'+i:i;
	            var name = this.imageFilePreffix+i+this.imageFileSuffix;
	            var url = this.imageFilePath + name;
	            var o ={};
	            o.name = name;
	            o.url = url;
	            data.images.push(o);
	        };
	        this.imageData = data;
	    },
	    initComponent: function() {
	        Adc.components.AppIconSelectField.superclass.initComponent.call(this);
	        //添加事件
	        this.addEvents(
	            //当输入框被赋值时触发
	            'datachange'
	        );
	    },
	    onRender : function(ct, position) {
	        Adc.components.AppIconSelectField.superclass.onRender.call(this, ct, position);
	        //将输入表单隐藏
	        try{
	            this.el.dom.setAttribute('type','hidden');
	        }catch(e){
	            this.el.dom.style.display="none";
	        }
	        this.buidImageField();
	    },
	    buidImageField:function(){
	        this.wrap =  this.el.wrap({cls: 'x-form-field-wrap adc-form-field-img-wrap'});
	        var imgEl = this.wrap.createChild({
	            tag: 'img',
	            src: 'resources/appDev/images/appIcon/topmenu_icon01.png',
	            width:45,
                height:45
	        });
	        this.imgEl = imgEl;
	        var trigger = this.wrap.createChild({
	            tag: 'img',
	            src: Ext.BLANK_IMAGE_URL,
	            alt: "",
	            cls: "x-form-trigger adc-form-appIcon-trigger " + this.triggerClass
	        });
	        this.trigger = trigger;
	        this.initTrigger();
	        if(!this.width){
	            this.wrap.setWidth(this.imgEl.getWidth()+this.trigger.getWidth()+5);
	        }
	        this.resizeEl = this.positionEl = this.wrap;
	    },
	    initTrigger:function(){
	        this.mon(this.trigger, 'click', this.onTriggerClick, this, {preventDefault:true});
	    },
	    buildImageView:function(){
	        var me = this;
	        var imgEl = me.imgEl;
	        var data = me.imageData;
		    var store = new Ext.data.JsonStore({
		        data:data,
		        root: 'images',
		        fields: ['name', 'url']
		    });
		    var tpl = new Ext.XTemplate(
		    		'<tpl for=".">',
	                '<div id="{url}" class="x-plain app-icon-view-wrap">',
	                    '<div class="app-icon-body"><img src="{url}" style="width: 45px; height: 45px;" title="{name}"></div>',
	                '</div>',
	                '</tpl>',
	                '<div class="x-clear"></div>'
		    );
		    var imageView = new Ext.DataView({
	            store: store,
	            tpl: tpl,
	            autoHeight:true,
	            singleSelect: true,
	            trackOver:true,
	            overClass:'tpl-model-view-over',
	            itemSelector:'div.app-icon-view-wrap',
	            selectedClass :'tpl-model-view-selected',
	            emptyText: '没有可显示的图片'
	        });
	        var win = new Ext.Window({
	            width:850,
	            height:450,
	            modal: true,
	            title:'请选择',
	            layout:'fit',
	            items:imageView
	        });
	        imageView.on('click',function(view,index,node,e){
	            var rec = store.data.get(index);
	            var url = rec.data.url;
	            me.value = url;
	            me.el.dom.value = url;
	            imgEl.dom.setAttribute('src',url);
	            win.close();
	        });
	        win.show();
	        win.body.setStyle('background-color','#fff');
	    },
	    getValue:function(){
	        return this.value;
	    },
	    setValue : function(v){
	        this.value = v;
	        this.el.dom.value = v;
	        if(this.imgEl){
	            this.imgEl.dom.setAttribute('src',v);
	        }
	        return this;
	    },
	    onTriggerClick:function(trigger){
	        this.buildImageView();
	    }
	});
Ext.reg('appIconSelectField',Adc.components.AppIconSelectField);
EXT 可选择图片列表的表单控件实现的更多相关文章
- 认识HTML中表格、列表标签以及表单控件
		前端之HTML,CSS(二) HTML标签 列表标签 无序列表:闭标签,由<ul><li></li>...</ul>组合而成,效果成纵向列表.格式:&l ... 
- HTML入门(列表、表单、常用表单控件、浮动框架、iframe、 摘要与细节、度量标签)
		一.列表 1.作用:默认显示方式为从上到下的显示数据 2.列表的组成 列表类型和列表项 3.列表的分类:有序列表 无序列表 自定义列表 无序列表语法为ul>li, 语法:ul代表列表,l ... 
- 415 DOM 查找列表框、下拉菜单控件、对表格元素/表单控件进行增删改操作、创建元素并且复制节点与删除、 对表格操作、通用性和标准的事件监听方法(点击后弹窗效果以及去掉效果)
		DOM访问列表框.下拉菜单的常用属性: form.length.options.selectedindex.type 使用options[index]返回具体选项所对应的常用属性:defa ... 
- Bootstrap 表单控件一(单行输入框input,下拉选择框select ,文本域textarea)
		单行输入框,常见的文本输入框,也就是input的type属性值为text.在Bootstrap中使用input时也必须添加type类型,如果没有指定type类型,将无法得到正确的样式,因为Bootst ... 
- 基于CkEditor实现.net在线开发之路(3)常用From表单控件介绍与说明
		上一章已经简单介绍了CKEditor控件可以编写C#代码,然后可以通过ajax去调用,但是要在网页上面编写所有C#后台逻辑,肯定痛苦死了,不说实现复杂的逻辑,就算实现一个简单增删改查,都会让人头痛欲裂 ... 
- 基于 el-form 封装一个依赖 json 动态渲染的表单控件
		nf-form 表单控件的功能 基于 el-form 封装了一个表单控件,包括表单的子控件. 既然要封装,那么就要完善一些,把能想到的功能都要实现出来,不想留遗憾. 毕竟UI库提供的功能都很强大了,不 ... 
- 了解HTML表单之13个表单控件
		目录 传统控件 button select option optgroup textarea fieldset legend label 新增控件 datalist keygen output pro ... 
- HTML5(常用的表单控件)
		常用的HTML5的表单控件: Input 类型: color color 类型用在input字段主要用于选取颜色,如下所示: 从拾色器中选择一个颜色: 选择你喜欢的颜色: <input type ... 
- 我教女朋友学编程Html系列(6)—Html常用表单控件
		做过网页的人都知道,html表单控件十分重要.基本上我们注册会员.登录用户,都需要填写用户名.密码,那些框框都是表单控件. 本来今天就想写一些常用的html表单控件,于是开始搜资料,找到了一个网页,作 ... 
随机推荐
- eclipse清除运行Maven build...后积累的配置项
			1.使用eclipse运行maven命令,经常会积累很多的配置项. 2.清理配置项同样在 Run As ---> Run configurations...中. 
- VC++中解决“在查找预编译头使用时跳过”的方法
			Visual C++ Concepts: Building a C/C++ ProgramCompiler Warning (level 1) C4627Error Message": sk ... 
- css3渐变生成器网页
			http://westciv.com/tools/gradients/ http://www.colorzilla.com/gradient-editor/ 
- Python_入门
			本章内容: 1.Python的种类 2.Python的环境 3.Python入门(解释器.编码.pyc文件.脚步传入参数.变量.输入.流程控制与缩进.while循环) 4.练习题 Python的种类 ... 
- Python之路-shell&计划任务
			开发脚本自动部署及监控1.编写脚本自动部署反向代理.web.nfs:要求: I.部署nginx反向代理三个web服务,调度算法使用加权轮询: II.所有web服务使用共享存储nfs ... 
- 老李推荐:第6章5节《MonkeyRunner源码剖析》Monkey原理分析-事件源-事件源概览-事件
			老李推荐:第6章5节<MonkeyRunner源码剖析>Monkey原理分析-事件源-事件源概览-事件 从网络过来的命令字串需要解析翻译出来,有些命令会在翻译好后直接执行然后返回,但有 ... 
- Java面试题:写代码使得分别出现StackOverflowError和OutOfMemoryError
			转载自:http://www.cnblogs.com/xudong-bupt/p/3360206.html 今天做了个笔试,这是其中的一道题目:写代码使得分别出现StackOverflowError和 ... 
- Android安全开发之启动私有组件漏洞浅谈
			0x00 私有组件浅谈 android应用中,如果某个组件对外导出,那么这个组件就是一个攻击面.很有可能就存在很多问题,因为攻击者可以以各种方式对该组件进行测试攻击.但是开发者不一定所有的安全问题都能 ... 
- .NET中数据访问方式(一):LINQ
			语言集成查询(Language-Integrated Query),简称LINQ,.NET中的LINQ体系如下图所示: 在编程语言层次,LINQ对于不同的数据源提供了相同的查询语法,方便了程序员操 ... 
- 抽象工厂模式(Abstract Factory)
			(二)抽象工厂模式(Abstract Factory) 1.抽象工厂模式(Abstract Factory),提供了一个创建一系列相关或相互依赖对象的接口,而无需指定它们具体的类. 2.抽象工厂模式是 ... 
