PageRenderTime 78ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/application/modules/Core/views/scripts/_FancyUpload.tpl

https://github.com/grandison/budo16
Smarty Template | 263 lines | 231 code | 32 blank | 0 comment | 13 complexity | 28d3f5acd04fa4b6e4298fd7b5166dcf MD5 | raw file
  1. <?php
  2. /**
  3. * SocialEngine
  4. *
  5. * @category Application_Core
  6. * @package Storage
  7. * @copyright Copyright 2006-2010 Webligo Developments
  8. * @license http://www.socialengine.net/license/
  9. * @version $Id: _FancyUpload.tpl 7305 2010-09-07 06:49:55Z john $
  10. * @author Sami
  11. */
  12. ?>
  13. <?php
  14. $this->headScript()
  15. ->appendFile($this->baseUrl() . '/externals/fancyupload/Swiff.Uploader.js')
  16. ->appendFile($this->baseUrl() . '/externals/fancyupload/Fx.ProgressBar.js')
  17. ->appendFile($this->baseUrl() . '/externals/fancyupload/FancyUpload2.js');
  18. $this->headLink()
  19. ->appendStylesheet($this->baseUrl() . '/externals/fancyupload/fancyupload.css');
  20. $this->headTranslate(array(
  21. 'Overall Progress ({total})', 'File Progress', 'Uploading "{name}"',
  22. 'Upload: {bytesLoaded} with {rate}, {timeRemaining} remaining.', '{name}',
  23. 'Remove', 'Click to remove this entry.', 'Upload failed',
  24. '{name} already added.',
  25. '{name} ({size}) is too small, the minimal file size is {fileSizeMin}.',
  26. '{name} ({size}) is too big, the maximal file size is {fileSizeMax}.',
  27. '{name} could not be added, amount of {fileListMax} files exceeded.',
  28. '{name} ({size}) is too big, overall filesize of {fileListSizeMax} exceeded.',
  29. 'Server returned HTTP-Status <code>#{code}</code>',
  30. 'Security error occurred ({text})',
  31. 'Error caused a send or load operation to fail ({text})',
  32. ));
  33. ?>
  34. <script type="text/javascript">
  35. var uploadCount = 0;
  36. var extraData = <?php echo $this->jsonInline($this->data); ?>;
  37. //var extraData = {"classified_id":15};
  38. window.addEvent('domready', function() { // wait for the content
  39. // our uploader instance
  40. var up = new FancyUpload2($('demo-status'), $('demo-list'), { // options object
  41. // we console.log infos, remove that in production!!
  42. verbose: false,
  43. multiple: false,
  44. appendCookieData: true,
  45. // url is read from the form, so you just have to change one place
  46. url: $('form-upload').action + '?ul=1',
  47. // path to the SWF file
  48. path: '<?php echo $this->baseUrl() . '/externals/fancyupload/Swiff.Uploader.swf';?>',
  49. // remove that line to select all files, or edit it, add more items
  50. typeFilter: {
  51. 'Images (*.jpg, *.jpeg, *.gif, *.png)': '*.jpg; *.jpeg; *.gif; *.png'
  52. },
  53. // this is our browse button, *target* is overlayed with the Flash movie
  54. target: 'demo-browse',
  55. data: extraData,
  56. // graceful degradation, onLoad is only called if all went well with Flash
  57. onLoad: function() {
  58. $('demo-status').removeClass('hide'); // we show the actual UI
  59. $('demo-fallback').destroy(); // ... and hide the plain form
  60. // We relay the interactions with the overlayed flash to the link
  61. this.target.addEvents({
  62. click: function() {
  63. return false;
  64. },
  65. mouseenter: function() {
  66. this.addClass('hover');
  67. },
  68. mouseleave: function() {
  69. this.removeClass('hover');
  70. this.blur();
  71. },
  72. mousedown: function() {
  73. this.focus();
  74. }
  75. });
  76. // Interactions for the 2 other buttons
  77. $('demo-clear').addEvent('click', function() {
  78. up.remove(); // remove all files
  79. var fileids = document.getElementById('fancyuploadfileids');
  80. fileids.value ="";
  81. return false;
  82. });
  83. },
  84. // Edit the following lines, it is your custom event handling
  85. /**
  86. * Is called when files were not added, "files" is an array of invalid File classes.
  87. *
  88. * This example creates a list of error elements directly in the file list, which
  89. * hide on click.
  90. */
  91. onSelectFail: function(files) {
  92. files.each(function(file) {
  93. new Element('li', {
  94. 'class': 'validation-error',
  95. html: file.validationErrorMessage || file.validationError,
  96. title: MooTools.lang.get('FancyUpload', 'removeTitle'),
  97. events: {
  98. click: function() {
  99. this.destroy();
  100. }
  101. }
  102. }).inject(this.list, 'top');
  103. }, this);
  104. },
  105. onComplete: function hideProgress() {
  106. var demostatuscurrent = document.getElementById("demo-status-current");
  107. var demostatusoverall = document.getElementById("demo-status-overall");
  108. var demosubmit = document.getElementById("submit-wrapper");
  109. demostatuscurrent.style.display = "none";
  110. demostatusoverall.style.display = "none";
  111. demosubmit.style.display = "block";
  112. },
  113. onFileStart: function() {
  114. uploadCount += 1;
  115. $('demo-browse').style.display = "none";
  116. $('demo-clear').style.display = "none";
  117. },
  118. onFileRemove: function(file) {
  119. uploadCount -= 1;
  120. file_id = file.photo_id;
  121. request = new Request.JSON({
  122. 'format' : 'json',
  123. 'url' : '<?php echo $this->url(Array('module'=>'core', 'controller' => 'admin-ads', 'action'=>'removephoto'), 'default') ?>',
  124. 'data': {
  125. 'photo_id' : file_id
  126. },
  127. 'onSuccess' : function(responseJSON) {
  128. var html_code_element = document.getElementById("html_field-wrapper");
  129. html_code_element.style.display = "none";
  130. $('demo-browse').style.display = "block";
  131. return false;
  132. }
  133. });
  134. request.send();
  135. var fileids = document.getElementById('fancyuploadfileids');
  136. if (uploadCount == 0)
  137. {
  138. var democlear = document.getElementById("demo-clear");
  139. var demolist = document.getElementById("demo-list");
  140. var demosubmit = document.getElementById("submit-wrapper");
  141. democlear.style.display = "none";
  142. demolist.style.display = "none";
  143. demosubmit.style.display = "none";
  144. }
  145. fileids.value = fileids.value.replace(file_id, "");
  146. },
  147. onSelectSuccess: function(file) {
  148. $('demo-list').style.display = 'block';
  149. var democlear = document.getElementById("demo-clear");
  150. var demostatuscurrent = document.getElementById("demo-status-current");
  151. var demostatusoverall = document.getElementById("demo-status-overall");
  152. democlear.style.display = "inline";
  153. demostatuscurrent.style.display = "block";
  154. demostatusoverall.style.display = "block";
  155. up.start();
  156. } ,
  157. /**
  158. * This one was directly in FancyUpload2 before, the event makes it
  159. * easier for you, to add your own response handling (you probably want
  160. * to send something else than JSON or different items).
  161. */
  162. onFileSuccess: function(file, response) {
  163. var json = new Hash(JSON.decode(response, true) || {});
  164. if (json.get('status') == '1') {
  165. file.element.addClass('file-success');
  166. file.info.set('html', '<span>Upload complete.</span>');
  167. var fileids = document.getElementById('fancyuploadfileids');
  168. fileids.value = fileids.value + json.get('photo_id') + " ";
  169. $('photo_id').value = json.get('photo_id');
  170. file.photo_id = json.get('photo_id');
  171. // show the html code element and populate with uploaded image html
  172. var html_code_element = document.getElementById("html_field-wrapper");
  173. html_code_element.style.display = "block";
  174. $('html_code').value = json.get('photo_url');
  175. } else {
  176. file.element.addClass('file-failed');
  177. file.info.set('html', '<span>An error occurred:</span> ' + (json.get('error') ? (json.get('error')) : response));
  178. }
  179. },
  180. /**
  181. * onFail is called when the Flash movie got bashed by some browser plugin
  182. * like Adblock or Flashblock.
  183. */
  184. onFail: function(error) {
  185. switch (error) {
  186. case 'hidden': // works after enabling the movie and clicking refresh
  187. alert('<?php echo $this->string()->escapeJavascript($this->translate("To enable the embedded uploader, unblock it in your browser and refresh (see Adblock).")) ?>');
  188. break;
  189. case 'blocked': // This no *full* fail, it works after the user clicks the button
  190. alert('<?php echo $this->string()->escapeJavascript($this->translate("To enable the embedded uploader, enable the blocked Flash movie (see Flashblock).")) ?>');
  191. break;
  192. case 'empty': // Oh oh, wrong path
  193. alert('<?php echo $this->string()->escapeJavascript($this->translate("A required file was not found, please be patient and we'll fix this.")) ?>');
  194. break;
  195. case 'flash': // no flash 9+
  196. alert('<?php echo $this->string()->escapeJavascript($this->translate("To enable the embedded uploader, install the latest Adobe Flash plugin.")) ?>');
  197. }
  198. }
  199. });
  200. });
  201. </script>
  202. <input type="hidden" name="<?php echo $this->name;?>" id="fancyuploadfileids" value ="" />
  203. <fieldset id="demo-fallback">
  204. <legend><?php echo $this->translate('File Upload');?></legend>
  205. <p>
  206. <?php echo $this->translate("CORE_VIEWS_SCRIPTS_FANCYUPLOAD_DESCRIPTION");?>
  207. </p>
  208. <label for="demo-photoupload">
  209. <?php echo $this->translate('Upload a Photo:');?>
  210. <input type="file" name="Filedata" />
  211. </label>
  212. </fieldset>
  213. <div id="demo-status" class="hide">
  214. <div>
  215. <?php echo $this->translate('CORE_VIEWS_SCRIPTS_FANCYUPLOAD_ADDPHOTOS');?>
  216. </div>
  217. <div>
  218. <a class="buttonlink icon_photos_new" href="javascript:void(0);" id="demo-browse"><?php echo $this->translate('Add Photos');?></a>
  219. <a class="buttonlink icon_clearlist" href="javascript:void(0);" id="demo-clear" style='display: none;'><?php echo $this->translate('Clear List');?></a>
  220. </div>
  221. <div class="demo-status-overall" id="demo-status-overall" style="display: none">
  222. <div class="overall-title"></div>
  223. <img src="<?php echo $this->baseUrl() . '/externals/fancyupload/assets/progress-bar/bar.gif';?>" class="progress overall-progress" />
  224. </div>
  225. <div class="demo-status-current" id="demo-status-current" style="display: none">
  226. <div class="current-title"></div>
  227. <img src="<?php echo $this->baseUrl() . '/externals/fancyupload/assets/progress-bar/bar.gif';?>" class="progress current-progress" />
  228. </div>
  229. <div class="current-text"></div>
  230. </div>
  231. <ul id="demo-list"></ul>