| @@ 188-228 (lines=41) @@ | ||
| 185 | )); |
|
| 186 | } |
|
| 187 | ||
| 188 | private function publishInitScript($options) |
|
| 189 | { |
|
| 190 | Yii::app()->clientScript->registerScript(__CLASS__.'#'.$this->htmlOptions['id'], " |
|
| 191 | jQuery(function($) |
|
| 192 | { |
|
| 193 | 'use strict'; |
|
| 194 | ||
| 195 | var formId = '{$this->htmlOptions['id']}'; |
|
| 196 | var gridId = '{$this->htmlOptions['gridId']}' |
|
| 197 | var multiply = '{$this->multiple}'; |
|
| 198 | var options = {$options}; |
|
| 199 | ||
| 200 | var td = $('#' + gridId).parents('td'); |
|
| 201 | var files = td.find('.fileupload-files'); |
|
| 202 | var buttons = td.find('.fileupload-buttonbar'); |
|
| 203 | ||
| 204 | if( !multiply && td.find('.items a').length ) |
|
| 205 | buttons.hide(); |
|
| 206 | ||
| 207 | var fileUploader = $('#' + formId).fileupload(options); |
|
| 208 | fileUploader.bind('fileuploadstop', function(e, data) |
|
| 209 | { |
|
| 210 | $.fn.yiiGridView.update(gridId); |
|
| 211 | if( !multiply ) |
|
| 212 | files.find('tbody').empty(); |
|
| 213 | }); |
|
| 214 | fileUploader.bind('fileuploaddestroy', function(e, data) |
|
| 215 | { |
|
| 216 | if( !multiply ) |
|
| 217 | buttons.show(); |
|
| 218 | }); |
|
| 219 | fileUploader.bind('fileuploadadded', function(e, data){ |
|
| 220 | if( !multiply ){ |
|
| 221 | buttons.hide(); |
|
| 222 | files.find('button.delete').click(function(){ |
|
| 223 | if( !files.find('.items a').length ) buttons.show(); |
|
| 224 | }); |
|
| 225 | } |
|
| 226 | }); |
|
| 227 | });", CClientScript::POS_END); |
|
| 228 | } |
|
| 229 | ||
| 230 | private function publishAssets() |
|
| 231 | { |
|
| @@ 265-301 (lines=37) @@ | ||
| 262 | } |
|
| 263 | } |
|
| 264 | ||
| 265 | private function registerDropZoneScript() |
|
| 266 | { |
|
| 267 | Yii::app()->clientScript->registerScript(__CLASS__.'DropZoneScript#'.$this->htmlOptions['gridId'], " |
|
| 268 | $(document).bind('dragover', function (e) { |
|
| 269 | var dropzoneContainer = $('#{$this->htmlOptions['gridId']}'); |
|
| 270 | var dropzone = $('<div id=\"dropzone\" />').html('<p>Перетащите файлы сюда</p>').appendTo(dropzoneContainer); |
|
| 271 | ||
| 272 | setTimeout(function() { |
|
| 273 | var dropZone = $('#dropzone'), |
|
| 274 | timeout = window.dropZoneTimeout; |
|
| 275 | if (!timeout) { |
|
| 276 | dropZone.addClass('in'); |
|
| 277 | } else { |
|
| 278 | clearTimeout(timeout); |
|
| 279 | } |
|
| 280 | var found = false, |
|
| 281 | node = e.target; |
|
| 282 | do { |
|
| 283 | if (node === dropZone[0]) { |
|
| 284 | found = true; |
|
| 285 | break; |
|
| 286 | } |
|
| 287 | node = node.parentNode; |
|
| 288 | } while (node != null); |
|
| 289 | if (found) { |
|
| 290 | dropZone.addClass('hover'); |
|
| 291 | } else { |
|
| 292 | dropZone.removeClass('hover'); |
|
| 293 | } |
|
| 294 | window.dropZoneTimeout = setTimeout(function () { |
|
| 295 | window.dropZoneTimeout = null; |
|
| 296 | dropZone.removeClass('in hover'); |
|
| 297 | }, 100); |
|
| 298 | }, 0); |
|
| 299 | }); |
|
| 300 | ", Yii::app()->clientScript->coreScriptPosition); |
|
| 301 | } |
|
| 302 | ||
| 303 | private function registerCropImageScript() |
|
| 304 | { |
|