public function showInventoryBar(AspidAuth $aspidAuth, ComboboxFactory $comboboxFactory, ItemGroupDictionary $itemGroupDictionary) { if ($aspidAuth->checkRole("COMMANDER")) { echo '<div class="private-navbar">'; $itemBlock = $this->getItemBlock(); echo ' <button type="button" id="addNewInventoryItemBtn" class="btn btn-labeled btn-primary" style="width:180px;"> <span class="btn-label"><i class="glyphicon glyphicon-plus"></i></span><span>Добавить предмет</span></button> ' . $comboboxFactory->getItemGroupCombobox(null, null, $itemGroupDictionary) . ' <script> $("#addNewInventoryItemBtn").click(function(){ $("#inventoryContainer").append("' . $itemBlock . '"); var typeId = $(".dropdown-menu.rank-combobox li a").parents(".btn-item-group").attr("group_id"); setClassForBlock(typeId); }); function setClassForBlock(groupId){ if(groupId == 1){ $(".item-block").last().addClass("item-block-essential"); } else if(groupId == 2){ $(".item-block").last().addClass("item-block-needed"); } $(".item-block").last().find(".i-type").val(groupId); } </script> '; } echo '</div>'; }
function showInventoryBar(AspidAuth $aspidAuth, ComboboxFactory $comboboxFactory, ItemGroupDictionary $itemGroupDictionary) { if ($aspidAuth->checkRole("COMMANDER")) { echo '<div class="row private-navbar blackblock" style="z-index: 10; border-bottom: 1px dotted #1a4413;">'; $itemBlock = getItemBlock(new Item()); echo ' <button type="button" id="addNewInventoryItemBtn" class="btn btn-labeled btn-primary" style="width:180px;"> <span class="btn-label"><i class="glyphicon glyphicon-plus"></i></span><span>Добавить предмет</span></button> <button type="button" id="switchToNonCom" class="btn btn-labeled btn-danger" style="width:300px;"> <span class="btn-label"><i class="glyphicon glyphicon-star"></i></span><span>Выключить командирский режим</span></button> <!--' . $comboboxFactory->getItemGroupCombobox(null, null, $itemGroupDictionary) . '--> <script> $("#addNewInventoryItemBtn").click(function(){ $("#inventoryContainer").append("' . $itemBlock . '"); //var typeId = $(".dropdown-menu.rank-combobox li a").parents(".btn-item-group").attr("group_id"); setClassForBlock(1); prepareListeners(true); }); $("#switchToNonCom").click(function(){ window.location.href = "http://www.msk-aspid.ru/inventory.php?noncom"; }); function setClassForBlock(groupId){ if(groupId == 1){ $(".item-block").last().addClass("item-block-essential"); $(".item-block").last().find(".itemTypeLabel").text("Обязательное снаряжение"); } else if(groupId == 2){ $(".item-block").last().addClass("item-block-needed"); $(".item-block").last().find(".itemTypeLabel").text("Второстепенное снаряжение"); } else if(groupId == 3){ $(".item-block").last().find(".itemTypeLabel").text("Рекомендуемое снаряжение"); } $(".item-block").last().find(".i-type").val(groupId); } function prepareListeners(forLastOnly){ var tmp; if(forLastOnly){ tmp = $(".del-item-button").last(); } else { tmp = $(".del-item-button"); } tmp.click( function(){ var form = $(this).closest("form"); if(form.find(".i-id").val() != ""){ if(!confirm("Точно удалить?")){ return; } form.find(".i-name").val("DELETEIT"); }; var form = $(this).closest("form"); saveItemToBase(form); $(this).closest(".item-row").remove(); } ); if(forLastOnly){ tmp = $(".save-item-button").last(); } else { tmp = $(".save-item-button"); } tmp.click( function(){ var form = $(this).parents("form").first(); if(form.find(".i-name").val()){ saveItemToBase(form); } else { form.find(".i-name").focus(); } } ) if(forLastOnly){ tmp = $("input:radio.itemGroupRadio").slice(-3); } else { tmp = $("input:radio.itemGroupRadio"); } tmp.change( function(){ var value = $(this).val(); var itemBlock = $(this).parents(".item-block").first(); itemBlock.removeClass("item-block-essential"); itemBlock.removeClass("item-block-needed"); if(value == 1){ itemBlock.addClass("item-block-essential"); itemBlock.find(".itemTypeLabel").text("Обязательное снаряжение"); } else if(value == 2){ itemBlock.addClass("item-block-needed"); itemBlock.find(".itemTypeLabel").text("Второстепенное снаряжение"); } else if(value == 3){ itemBlock.find(".itemTypeLabel").text("Рекомендуемое снаряжение"); } itemBlock.find(".i-type").val(value); if(itemBlock.find(".i-id").val()){ var form = $(this).parents("form").first(); saveItemToBase(form); } } ); } function saveItemToBase(form){ console.log("--- logging form ---"); console.log(form); console.log("=== saveItemToBase ==="); var json = form.serializeArray(); console.log(JSON.stringify(json)); $.ajax({ url: "phpscripts/save_inventory.php", type: "post", data: { "jsn": JSON.stringify(json)}, success: function(response) { console.log(">>> RESPONSE <<<") console.log(response); console.log("<<< RESPONSE >>>") var reply = JSON.parse(response); form.find(".i-id").val(reply.message); }, error: function() { console.log("***ERROR***\\n" + response + "\\n*** *** ***"); } }); } </script> '; } echo '</div>'; }
<table class="table"> <thead> <tr> <th>#</th> <th>Вконтакте</th> <th>Позывной</th> <th>Группа</th> <th>Должность</th> </tr> </thead> <tbody> '; $canModify = $auth->checkRole('TEAM_EDIT') == 1; $groupDictionary = new GroupDictionary($userDAO); $rankDictionary = new RankDictionary($userDAO); $comboboxFactory = new ComboboxFactory(); $i = 1; foreach ($set as $row) { if ($canModify) { $group = $comboboxFactory->getUserGroupComboboxHtml($row['group_id'], $row['uid'], $groupDictionary); $nickname = '<input uid="' . $row['uid'] . '" type="text" placeholder="Введите позывной..." class="darktextinput nicknameinput">'; if ($row['nickname'] != null) { $nickname = '<input uid="' . $row['uid'] . '" type="text" placeholder="Введите позывной..." value="' . $row['nickname'] . '" class="darktextinput nicknameinput">'; } if ($row['rank_id'] != 1) { $rank = $comboboxFactory->getRankComboboxHtml($row['rank_id'], $row['uid'], $rankDictionary); } else { $rank = '<span class="highlighted_rank" style="margin-left : 30px;">Командир команды</span>'; } } else { $group = $groupDictionary->getNameById($row['group_id']);