<div class="title">產品分類詳情</div>
<ul class="table-toolbar"style="text-align: left;">
    <li><a class="toolbar-element btn btn-default btn-create" href="/product_category" ><span class="iconify" data-icon="typcn-arrow-back" data-inline="false"></span><i style="margin-right: 8px;"></i>返回</a></li>
</ul>
<div class="form-container">
    <form id="frmphp" class="form-horizontal" role="form" method="post" action="/product_category/save">
        <input type="hidden" name="id" value="<?= $product_category['id']; ?>" />
		<?php $disabled=(intval($product_category['inuse'])>0)?' disabled':''; ?>
		<?php
		if ($disabled !== '') {
			echo '<span class="edit-warning">* 此項目正被使用，不能修改狀態</span>';
		}
		?>
        <div class="form-group mas-col">
            <div class="col-sm-2 text-center mas-title"><label for="categoryname">分類名稱</label></div>
            <div class="col-sm-10 text-center mas-title mas-box "><input id="categoryname" type="text" class="form-control mas-input" name="name" value="<?= $product_category['name']; ?>" /></div>
        </div>
        <div class="form-group mas-col">
            <div class="col-sm-2 text-center mas-title"><label for="status">狀態</label></div>
            <div class="col-sm-10 text-center mas-title mas-box ">
                <select class="select mas-select form-control" name="status" id="status" <?=$disabled?>>
                    <?php
                        foreach ($status as $idx => $value) {
                            if ($idx == $product_category['status']) {
                                $selected = ' selected="selected"';
                            }
                            else {
                                $selected = '';
                            }
                            echo sprintf('<option value="%s"%s>%s</option>', $idx, $selected, $value);
                        }
                    ?>
                </select>
            </div>
        </div>
        <div class="form-group mas-col">
            <div class="col-sm-2 text-center mas-title"><label for="remark">備註</label></div>
            <div class="col-sm-10 mas-box"><textarea id="remark"  class="form-control mas-textarea" rows="3" name="remark" ><?= $product_category['remark']; ?></textarea></div>
        </div>
        <div class="form-footer">
			<button class="btn btn-footer submit" type="button" id='btnEdit' style="display:none;">編輯</button>
			<button class="btn btn-footer submit" type="button" id='btnCancel' style="display:none;">取消</button>
            <a class="btn btn-footer reset" href="javascript:window.location.reload(true)">重設</a>
            <button class="btn btn-footer submit" type="button" id='btnSubmit'>提交</button>
        </div>
    </form>
</div>
<script>
	var viewMode = true;
    function validform() {
        var msg = '';
        if ($('#categoryname').val() === '') {
            msg += "請輸入分類名稱\n";
        }
        if (msg !== '') {
            alert(msg);
            return false;
        }
        return true;
    }

	function changeMode() {
		$('.btn-footer').toggle();
		$('.form-control').prop('disabled', viewMode);
	}

	$(document).ready(function () {
         var li = $('#sidebar-menu li').filter(function(i){
            return $(this).find('.menu-dropdown').find('.menu-text').text()===' 產品';
        });
        li.addClass('active open');
        changeMode();
    });
    
    $(document).on('click','#btnSubmit', function () {
        if (validform()) {
            $('#frmphp').submit();
        }
    });
	$(document).on('click', '#btnEdit', function () {
		viewMode = false;
		changeMode();
	});
	$(document).on('click', '#btnCancel', function () {
		window.location.href = '/product_category';
	});
</script>
