hotel_view.php
5.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
use yii\helpers\Html;
?>
<div class="hotels_result">
<?php $i=0; foreach($model as $hotel):?>
<div class="image_block_hotel">
<h2>Миниатюра</h2>
<div class="form-group field-goods-file">
<label class="control-label" for="fileupload">File</label>
<input type="hidden" name="UploadForm[file]" value="">
<input type="file" class="fileupload" name="UploadForm[file]" data-url="index.php?r=site/download-photo">
<div class="help-block"></div>
</div>
<div class="form-group field-goods-image">
<label class="control-label" for="picture_link">Картинка</label>
<input type="hidden" class="picture_link form-control" name="Hotel[<?=$i?>][photo]" value="<?$hotel->photo?>">
</div>
<div class="img_block">
<?= $hotel->photo ? '<img src='.$hotel->photo.'>': '' ?>
</div>
</div>
<div class="form-group"><label class="control-label" for="hotel-name">Name</label> <input type="text" id="hotel-name" value="<?= $hotel->name ?>" class="form-control" name="Hotel[<?=$i?>][name]"></div>
<div class="form-group"><label class="control-label" for="hotel-address">Address</label> <textarea id="hotel-address" class="form-control" name="Hotel[<?=$i?>][address]"><?= $hotel->address ?></textarea></div>
<div class="form-group"><label class="control-label" for="hotel-price">Price</label> <input type="text" id="hotel-price" value="<?= $hotel->price ?>" class="form-control" name="Hotel[<?=$i?>][price]"></div>
<div class="form-group"><label class="control-label" for="hotel-distance">Distance</label> <input type="text" id="hotel-distance" value="<?= $hotel->distance ?>" class="form-control" name="Hotel[<?=$i?>][distance]"></div>
<div class="form-group"><label class="control-label" for="hotel-rating">Rating</label> <input type="number" id="hotel-rating" value="<?= $hotel->rating ?>" class="form-control" name="Hotel[<?=$i++?>][rating]"></div>
<?php endforeach; ?>
</div>
<p class="btn btn-success add_hotel">Добавить поле</p>
<script>
$( document ).ready(function(){
var start_i = [<?=$i?>];
$('.add_hotel').click(function(){
var block = $('.hotels_result');
var sub_block =
'<div class="image_block_hotel">'+
'<h2>Миниатюра</h2>'+
'<div class="form-group field-goods-file">'+
'<label class="control-label" for="fileupload">File</label>'+
'<input type="hidden" name="UploadForm[file]" value="">'+
'<input type="file" class="fileupload" name="UploadForm[file]" data-url="index.php?r=site/download-photo">'+
'</div>'+
'<div class="form-group field-goods-image">'+
'<label class="control-label" for="picture_link">Картинка</label>'+
'<input type="hidden" class="picture_link form-control" name="Hotel['+ start_i +'][photo]" value="">'+
'</div>'+
'<div class="img_block">'+
'</div>'+
'</div>'+
'<div class="form-group"><label class="control-label" for="hotel-photo">Photo</label> <input type="text" class="form-control" name="Hotel['+ start_i +'][photo]"></div>'+
'<div class="form-group"><label class="control-label" for="hotel-name">Name</label> <input type="text" class="form-control" name="Hotel['+ start_i +'][name]"></div>'+
'<div class="form-group"><label class="control-label" for="hotel-address">Address</label> <textarea class="form-control" name="Hotel['+ start_i +'][address]"></textarea></div>'+
'<div class="form-group"><label class="control-label" for="hotel-price">Price</label> <input type="text" class="form-control" name="Hotel['+ start_i +'][price]"></div>'+
'<div class="form-group"><label class="control-label" for="hotel-distance">Distance</label> <input type="text" class="form-control" name="Hotel['+ start_i +'][distance]"></div>'+
'<div class="form-group"><label class="control-label" for="hotel-rating">Rating</label> <input type="number" class="form-control" name="Hotel['+ start_i++ +'][rating]"></div>';
block.append(sub_block);
$('.fileupload').fileupload({
dataType: 'json',
done: function (e, data) {
var host = window.location.host.toString();
var img = '<img src="http://'+host+data.result.link+'">';
console.log($(this).parents('.image_block_hotel'));
var block = $(this).parents('.image_block_hotel').find('.img_block');
block.find('img').remove();
block.append(img);
$(this).parents('.image_block_hotel').find('.picture_link').val(data.result.link);
}
});
});
$('.fileupload').fileupload({
dataType: 'json',
done: function (e, data) {
var host = window.location.host.toString();
var img = '<img src="http://'+host+data.result.link+'">';
var block = $(this).parents('.image_block_hotel').find('.img_block');
block.find('img').remove();
block.append(img);
$(this).parents('.image_block_hotel').find('.picture_link').val(data.result.link);
}
});
});
</script>