<script type="text/javascript" src="<?php echo Yii::app()->baseUrl;?>/js/admin/swfupload/swfupload.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->baseUrl;?>/js/admin/swfupload/handlers.js"></script>
<script type="text/javascript">
    var swfu;
    window.onload = function () {
        swfu = new SWFUpload({
            // Backend Settings
            upload_url: "<?php echo $this->createUrl('/admin/softpcontent/upload',array('id'=>$soft->id));?>",
            post_params: {"PHPSESSID": "<?php echo session_id();?>"},

            // File Upload Settings
            file_post_name : "SoftPcontent[Filedata]",
            file_size_limit : "10 MB",	// 2MB
            file_types : "*.*",
            file_types_description : "JPG Images",
            file_upload_limit : "0",

            file_queue_error_handler : fileQueueError,
            file_dialog_complete_handler : fileDialogComplete,
            upload_progress_handler : uploadProgress,
            upload_error_handler : uploadError,
            upload_success_handler : uploadSuccess,
            upload_complete_handler : uploadComplete,

            // Button Settings
            //button_image_url : "SmallSpyGlassWithTransperancy_17x18.png",
            button_placeholder_id : "spanButtonPlaceholder",
            button_width: 180,
            button_height: 18,
            button_text : '<span class="button">选择软件(不能大于10M)</span>',
            button_text_style : '.button { font-family: Helvetica, Arial, sans-serif; font-size: 12pt; } .buttonSmall { font-size: 10pt; }',
            button_text_top_padding: 0,
            button_text_left_padding: 18,
            button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
            button_cursor: SWFUpload.CURSOR.HAND,

            // Flash Settings
            flash_url : "<?php echo Yii::app()->baseUrl;?>/js/admin/swfupload/swfupload.swf",

            custom_settings : {upload_target : "divFileProgressContainer"},

            debug: false
        });
    };
</script>

<script type="text/javascript">
function changeName(id) {
    var url = '<?php echo $this->createUrl('/admin/softpcontent/ajaxchangename');?>&id='+id;
    var newName = $('#name_'+id).val();
    if ('' == newName) {
        alert('请输入正确的文件名');
    }

    $.ajax({
        type: 'post',
        url: url,
        data: 'name='+newName,
        success:function(msg){
            if (msg != '') {
                alert(msg);
            }
            $("#msg").html('');
        },
        beforeSend:function(){
            $("#msg").html('修改软件名称中...');
        }
    });
}

function changeSupport(id) {
    var url = '<?php echo $this->createUrl('/admin/softpcontent/ajaxchangesupport');?>&id='+id;
    var newSupport = $('#support_'+id).val();
    $.ajax({
        type: 'post',
        url: url,
        data: 'support='+newSupport,
        success:function(msg){
            if (msg != '') {
                alert(msg);
            }
            $("#msg").html('');
        },
        beforeSend:function(){
            $("#msg").html('修改软件机型列表中...');
        }
    });
}

function changePid(id) {
    var url = '<?php echo $this->createUrl('/admin/softpcontent/ajaxchangepid');?>&id='+id;
    var pid = $('#pid_'+id).val();
    $.ajax({
        type: 'post',
        url: url,
        data: 'pid='+pid,
        success:function(msg){
            if (msg != '') {
                alert(msg);
            }
            $("#msg").html('');
        },
        beforeSend:function(){
            $("#msg").html('修改软件平台中...');
        }
    });
}

function changeInfo(id) {
    var url = '<?php echo $this->createUrl('/admin/softpcontent/ajaxchangeinfo');?>&id='+id;
    var newInfo = $('#info_'+id).val();
    $.ajax({
        type: 'post',
        url: url,
        data: 'info='+newInfo,
        success:function(msg){
            if (msg != '') {
                alert(msg);
            }
            $("#msg").html('');
        },
        beforeSend:function(){
            $("#msg").html('修改软件信息中...');
        }
    });
}

function deletePcontent(id, self) {
    var url = '<?php echo $this->createUrl('/admin/softpcontent/ajaxdelete');?>';
    $(self).parent().parent().remove();
    $.ajax({
        type: 'get',
        url: url,
        data: 'id='+id,
        success:function(msg){
            if (msg != '') {
                alert(msg);
            }
            $("#msg").html('');
        },
        beforeSend:function(){
            $("#msg").html('软件删除中...')
        }
    });
}
</script>
<div id='msg'></div>
<table>
    <thead>
        <tr>
            <td>名称</td>
            <td>平台</td>
            <td>支持机型</td>
            <td>描述</td>
            <td>操作</td>
        </tr>
    </thead>
    <tbody>
        <?php foreach ($softList as $value):?>
            <tr>
            <td><?php echo CHtml::textField('name_'.$value->id, $value->name, array('onChange'=>'changeName('.$value->id.')'));?></td>
            <td><?php echo CHtml::dropDownList('pid_'.$value->id, $value->pid, CHtml::listData($platForms, 'id', 'name'), array('onChange'=>'changePid('.$value->id.')'));?></td>
            <td><?php echo CHtml::textArea('support_'.$value->id, $value->support, array('onChange'=>'changeSupport('.$value->id.')'));?></td>
            <td><?php echo CHtml::textArea('info_'.$value->id, $value->info, array('onChange'=>'changeInfo('.$value->id.')'));?></td>
            <td><?php echo CHtml::link('删除', '', array('onClick'=>'deletePcontent('.$value->id.', this)'));?></td>
            </tr>
        <?php endforeach;?>
    </tbody>
</table>

<div>
	<h2>批量上传软件</h2>
		<form>
		<div style="display: inline; border: solid 1px #7FAAFF; background-color: #C5D9FF; padding: 4px;">
			<span id="spanButtonPlaceholder"></span>

		</div>
	</form>
		<div id="divFileProgressContainer" style="height: 75px;"></div>
	<div id="thumbnails"></div>
</div>