trainers_view.php
4.18 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
<?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="Trainers[<?=$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="Trainers[<?=$i?>][name]"></div>
<div class="form-group"><label class="control-label" for="hotel-address">Описание</label> <textarea id="hotel-address" class="form-control" name="Trainers[<?=$i++?>][description]"><?= $hotel->description ?></textarea></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="Trainers['+ start_i +'][photo]" value="">'+
'</div>'+
'<div class="img_block">'+
'</div>'+
'</div>'+
'<div class="form-group"><label class="control-label" for="hotel-name">Name</label> <input type="text" class="form-control" name="Trainers['+ start_i +'][name]"></div>'+
'<div class="form-group"><label class="control-label" for="hotel-address">Описание</label> <textarea id="hotel-address" class="form-control" name="Trainers['+ start_i++ +'][description]"></textarea></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>