<link rel="stylesheet" href="/js/jquery-ui/smoothness/jquery-ui-1.8.21.custom.css" type="text/css">
<script type="text/javascript" src="/js/jquery-ui/jquery-ui-1.8.21.custom.min.js"></script>
<script language="javascript">
    var editor;
    KindEditor.ready(function(K) {
        editor = K.create('#ta_content', {
            width: '100%',
            height: '480px',
            //fileManagerJson:'/js/kcfinder/browse.php',
            //allowFileManager:true,
            allowImageUpload: false,
            filterMode: false,
            langType: 'en',
            items: [
                'ace', '|', 'undo', 'redo', '|', 'preview', 'cut', 'copy', 'paste', 'plainpaste', 'wordpaste', '|',
                'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', '|',
                'clearhtml', 'quickformat', 'removeformat', 'selectall', '/', 'fullscreen', '|',
                'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
                'italic', 'underline', 'strikethrough', 'lineheight', '|', 'table', 'hr', 'emoticons', 'image', 'map', 'pagebreak',
                'link', 'unlink', '|', 'about', '|', 'source'
            ],
            afterChange: function() {
                K('#display_count').html(getWordCount(editor.text()));
            },
        });
    });

//加载预览样式
    function load_preview_css() {
        $("iframe.ke-edit-iframe").contents().find("head").append('<?php echo $this->config->item("css_source_" . $this->config->item("site_code")); ?><style>.drop1{height:auto !important;} .photoRight img{max-width:100%;height:auto !important;}</style>');
        $("iframe.ke-edit-iframe").contents().find(".ke-content").css({"max-width": "1024px", "margin-left": "auto", "margin-right": "auto"});

    }

    $(document).ready(function() {
        //每隔三分钟自动保存一次任务内容
        setInterval(function() {
            editor.sync();
            var data = $('#form_article').serialize();
            var url = '<?php echo site_url('welcome/edit_submit') ?>';
            $.post(url, data, function(responseText) {
                var responseText = eval("(" + responseText + ")");//转换为json对象 
                for (var key in responseText) {
                    if (responseText[key].name != 'ok') {
                        $("#auto-save").html('(自动保存失败...)');
                    }
                }
            });
        }, 180000);

        //ajax获取获取google分析数据的日期设置
        $("#startdate,#enddate").datepicker({
            showButtonPanel: true
        });
        $("#total-analytics>a").trigger("click");

        $("#rating-container>ul>li").hover(function() {
            $(this).tooltip('show');
        });
    });


    //快速图片上传
    function openKCFinder_ta_photo() {
        window.CallBack = openKCFinder_ta_photo_callback;
        window.open('/media/popselectpicture.php?site_lgc=1', 'kcfinder_textbox', 'status=0, toolbar=0, location=0, menubar=0, directories=0,resizable=1, scrollbars=0, width=800, height=600');
    }

    function openKCFinder_ta_photo_callback(result) {
        if (result != null && result.Pinfo[0]) {
            $('#ta_photo').val(result.Pinfo[0].PUrl);
            $("#ta_photo_img").attr("src", "<?php echo $this->config->item('media_image_url'); ?>" + result.Pinfo[0].PUrl);
        }
    }

    //选择内容图片
    function openKCFinder_Content() {
        window.CallBack = openKCFinder_Content_callback;
        window.open('/media/popselectpicture.php?site_lgc=1', 'kcfinder_textbox', 'status=0, toolbar=0, location=0, menubar=0, directories=0,resizable=1, scrollbars=0, width=800, height=600');
    }
    function openKCFinder_Content_callback(result) {
        var site_image_url = '<?php echo $this->config->item('media_image_url') ?>';
        if (result != null) {
            for (var key in result.Pinfo) {
                editor.insertHtml('<img src="' + site_image_url + result.Pinfo[key].PUrl + '" alt="' + result.Pinfo[key].PName + '" width="' + result.Pinfo[key].Width + '" height="' + result.Pinfo[key].Height + '" />');
            }
        }
    }


</script>
<div class="row-fluid">
    <div class="span8 offset2" style="min-height:650px;">
        <legend>Task requirement</legend>
        <div style="background:#f5f5f5;padding:15px;margin-bottom:15px;">
            <div class="row-fluid">
                <div class="span12">
                    <strong>Task name:</strong>:
                    <?php echo $task->t_title; ?>
                </div>
            </div>
            <div class="row-fluid">
                <div class="span3">
                    <strong>Task type:</strong>
                    <?php echo $task->t_td_type; ?>
                </div>
                <div class="span3">
                    <strong>Send by:</strong>
                    <?php echo get_author_name($task->t_ht_op_code); ?>
                </div>
                <div class="span6">
                    <strong>Task Deadline:</strong>
                    <?php echo date('m/d/Y', strtotime($task->t_expires)); ?>
                </div> 
            </div>
            <div class="row-fluid">
                <p><strong>Task requirement：</strong><?php echo $task->t_content; ?></p>
            </div>
        </div>

        <legend class="<?php if ($task_detail->ta_content == '') echo 'hide'; ?>">
            <span>Task details</span>
        </legend>
        <form action="#" class="<?php if ($task_detail->ta_content == '') echo 'hide'; ?>"  name="form_article" id="form_article" method="post">
            <label class="control-label" >Title</label>
            <input type="text" class="span12" id="ta_title" name="ta_title" placeholder="Title" value="<?php if (isset($task_detail->ta_title)) echo $task_detail->ta_title; ?>">
            <label><strong>Content</strong><em id="auto-save" class="small"></em></label>
            <a href="javascript:void(0);" onclick="openKCFinder_Content();" title="Insert an image"><i class="icon-picture pull-right"></i></a>
            <i class="icon-stop icon-white pull-right"> </i>
            <i class="icon-stop icon-white pull-right" id="display_count">-</i>
            <textarea rows="12" class="span12" id="ta_content" name="ta_content"><?php if (isset($task_detail->ta_content)) echo $task_detail->ta_content; ?></textarea>                      
            <p> </p>
            <label><strong>Brief introduction</strong></label>
            <textarea rows="3" class="span12" id="ta_summary" name="ta_summary" placeholder="Brief introduction"><?php if (isset($task_detail->ta_summary)) echo $task_detail->ta_summary; ?></textarea>                    
            <label class="control-label" ><strong>SEO title</strong></label>
            <input type="text" class="span12" id="ta_seo_title" name="ta_seo_title" placeholder="SEO title" value="<?php if (isset($task_detail->ta_seo_title)) echo $task_detail->ta_seo_title; ?>">
            <label class="control-label" ><strong>SEO description</strong></label>
            <input type="text" class="span12" id="ta_seo_description" name="ta_seo_description" placeholder="SEO discription" value="<?php if (isset($task_detail->ta_seo_description)) echo $task_detail->ta_seo_description; ?>">
            <label class="control-label" ><strong>SEO Keywords</strong></label>
            <input type="text" class="span12" id="ta_seo_keywords" name="ta_seo_keywords" placeholder="SEO keyworkds" value="<?php if (isset($task_detail->ta_seo_keywords)) echo $task_detail->ta_seo_keywords; ?>">
            <label class="control-label" ><strong>Link Picture</strong></label>
            <div class="media" style="background: #f5f5f5;padding: 15px;">
                <div class="pull-left">
                    <img style="width:250px;" onclick="openKCFinder_ta_photo();" src="<?php echo empty($task_detail->ta_photo) ? '/css/images/uploadPic.jpg' : $this->config->item('media_image_url') . $task_detail->ta_photo; ?>" class="img-polaroid span4" name="ta_photo_img" id="ta_photo_img" >
                </div>
                <div class="media-body">
                    <button type="button" onclick="openKCFinder_ta_photo();" class="btn" style="margin:25px 0;">Choose</button><br>
                    <button type="button" onclick="$('#ta_photo').val('');
                            $('#ta_photo_img').attr('src', '/css/images/uploadPic.jpg');" class="btn" style="margin-bottom:12px;"> Reset　</button>
                    <p>Click the “Choose” button<br> to choose a photo from our Photo Galleries.</p>
                </div>
                <input type="hidden" name="ta_photo" id="ta_photo" value="<?php if (isset($task_detail->ta_photo)) echo $task_detail->ta_photo; ?>" />
                <input type="hidden" name="ht_user" value="<?php echo $task->t_ht_op_code; ?>">
                <input type="hidden" name="t_a_id" value="<?php echo $task->t_a_id; ?>">
                <input type="hidden" id="t_id" name="t_id" value="<?php echo $task->t_id; ?>" >
                <input type="hidden" id="ta_ic_id" name="ta_ic_id" value="<?php if (isset($task_detail->ta_ic_id)) echo $task_detail->ta_ic_id; ?>" >
            </div>
        </form> 
        <div class="btn-group pull-right" style="margin-bottom:50px;">
            <?php ($task->t_a_id<=0) ? $disabled = '' : $disabled = ' style="display:none;" '; ?>
            <button class="btn btn-info" <?php echo $disabled; ?> data-toggle="modal" data-target="#undertake_modal">Accept the task</button>
            <p> </p>
        </div>

    </div>
</div>

<!-- 承接任务 -->
<div class="modal fade" id="undertake_modal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3>Accept the task</h3>
    </div>
    <div class="modal-body">
        <p>Make sure again.</p>
        <form action="<?php echo site_url('taskhall/undertake') ?>"   name="form_undertake" id="form_undertake" method="post">
            <input type="hidden" id="t_id" name="t_id" value="<?php echo $task->t_id; ?>" >
        </form>
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">No</button>
        <button class="btn btn-primary" onclick="submitForm('form_undertake');">Yes</button>
    </div>
</div>

<!-- 放弃任务 -->
<div class="modal fade" id="canceltake_modal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3>Give up the task</h3>
    </div>
    <div class="modal-body">
        <p>Make sure again.</p>
        <form action="<?php echo site_url('taskhall/canceltake') ?>"   name="form_canceltake" id="form_canceltake" method="post">
            <input type="hidden" id="t_id" name="t_id" value="<?php echo $task->t_id; ?>" >
        </form>	
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">No</button>
        <button class="btn btn-primary" onclick="submitForm('form_canceltake');">Yes</button>
    </div>
</div>