PageRenderTime 71ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/manager/includes/class.contentlanguage.js.php

http://punchcms.googlecode.com/
PHP | 1870 lines | 1405 code | 277 blank | 188 comment | 258 complexity | ce8ed8991f92e030513eeb7a3e0cd28a MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. session_save_path($_SERVER["DOCUMENT_ROOT"] . "/sessions");
  3. session_start();
  4. require_once('./inc.constantes.php');
  5. require_once('../libraries/lib.language.php');
  6. $objLang = null;
  7. if (array_key_exists("objLang", $_SESSION)) $objLang = unserialize($_SESSION["objLang"]);
  8. if (!is_object($objLang)) {
  9. require_once('../config.php');
  10. $objLang = new Language($_CONF['app']['defaultLang'], $_CONF['app']['langPath']);
  11. }
  12. ?>
  13. /**************************************************************************
  14. * ContentLanguage Class.
  15. *************************************************************************/
  16. /***
  17. * ContentLanguage object.
  18. */
  19. var ContentLanguage = function() {
  20. this.version = '1.1.2'; // 2.0 when jQuery is implemented?
  21. this.currentLanguage = 0;
  22. this.hover = false;
  23. this.buttonType = "";
  24. this.defaultLanguage = 0;
  25. this.actives = {};
  26. this.cascades = {};
  27. this.fields = {};
  28. this.FIELDTYPE = {
  29. 'DATE': '1',
  30. 'TEXT': '2',
  31. 'TEXTAREA': '3',
  32. 'FILE': '4',
  33. 'NUMBER': '5',
  34. 'SELECT_LIST': '6',
  35. 'IMAGE': '7',
  36. 'USER': '8',
  37. 'LINK': '9',
  38. 'CHECKBOX': '10',
  39. 'CHECK_LIST': '11',
  40. 'SIMPLETEXT': '12'
  41. };
  42. }
  43. ContentLanguage.require = function(libraryName) {
  44. var $objScript = jQuery("<script></script>");
  45. objScript.attr({
  46. type: "text/javascript",
  47. src: libraryName
  48. });
  49. jQuery("head").append($objScript);
  50. }
  51. ContentLanguage.load = function() {
  52. if(typeof jQuery == "undefined")
  53. throw("ContentLanguage class requires the jQuery library >= 1.4.2");
  54. alert("Old loading code in class.contentlanguage.js.php on line 62");
  55. // $A(document.getElementsByTagName("script")).findAll( function(s) {
  56. // return (s.src && s.src.match(/pcms\.js(\?.*)?$/))
  57. // }).each( function(s) {
  58. // var path = s.src.replace(/pcms\.js(\?.*)?$/,'');
  59. // var includes = s.src.match(/\?.*load=([a-z,]*)/);
  60. // (includes ? includes[1] : 'ptemplate,pfield').split(',').each(
  61. // function(include) { ContentLanguage.require(path+include+'.js') });
  62. // });
  63. }
  64. ContentLanguage.remove = function(intId) {
  65. var blnConfirm = confirm("<?php echo $objLang->get("languageRemoveAlert", "alert") ?>");
  66. if (blnConfirm == true) {
  67. strReturnTo = "";
  68. document.location.href = "?cid=<?php echo NAV_PCMS_LANGUAGES ?>&eid=" + intId + "&cmd=<?php echo CMD_REMOVE ?>&returnTo=" + strReturnTo;
  69. }
  70. }
  71. ContentLanguage.setDefault = function(intId) {
  72. document.location.href = "?cid=<?php echo NAV_PCMS_LANGUAGES ?>&eid=" + intId + "&cmd=<?php echo CMD_SET_DEFAULT ?>";
  73. }
  74. ContentLanguage.prepareAdd = function() {
  75. jQuery("#languageForm").slideDown();
  76. }
  77. ContentLanguage.prototype.init = function() {
  78. jQuery("#language_active").bind("mouseover mouseout mousedown", function(event) {
  79. switch(event.type){
  80. case "mouseover":
  81. return objContentLanguage.buttonOver('activeElement', this);
  82. break;
  83. case "mouseout":
  84. return objContentLanguage.buttonOut('activeElement', this);
  85. break;
  86. case "mousedown":
  87. return objContentLanguage.toggleActiveElement();
  88. break;
  89. }
  90. });
  91. jQuery("#frm_language option[value="+ this.defaultLanguage +"]").attr("selected","selected");
  92. }
  93. ContentLanguage.prototype.swap = function(languageId) {
  94. var $objImage = jQuery("#language_cascade"),
  95. $objImageActive = jQuery("#language_active"),
  96. $objButton = $objImage.parent();
  97. this.toTemp();
  98. this.currentLanguage = languageId;
  99. //*** Check is current and default language is equal.
  100. if (this.currentLanguage == this.defaultLanguage || this.actives[this.currentLanguage] != true || this.actives[this.defaultLanguage] != true) {
  101. $objImage.attr("src", "images/lang_unlocked_disabled.gif");
  102. $objButton.unbind("mouseover mouseout click");
  103. } else {
  104. if (this.cascades[this.currentLanguage] !== true) {
  105. $objImage.attr("src", "images/lang_unlocked.gif");
  106. } else {
  107. $objImage.attr("src", "images/lang_locked.gif");
  108. }
  109. $objButton.bind("mouseover mouseout click", function(event){
  110. var objReturn;
  111. switch(event.type){
  112. case "mouseover":
  113. objReturn = objContentLanguage.buttonOver("cascadeElement", this);
  114. break;
  115. case "mouseout":
  116. objReturn = objContentLanguage.buttonOut("cascadeElement", this);
  117. break;
  118. case "click":
  119. objReturn = objContentLanguage.toggleCascadeElement();
  120. break;
  121. }
  122. return objReturn;
  123. });
  124. }
  125. //*** Check the active state.
  126. if (this.actives[this.currentLanguage] != true) {
  127. if (this.hover) overlib("<?php echo $objLang->get("langEnable", "tip") ?>");
  128. $objImageActive.attr("src", "images/lang_disabled.gif");
  129. } else {
  130. if (this.hover) overlib("<?php echo $objLang->get("langDisable", "tip") ?>");
  131. $objImageActive.attr("src", "images/lang_enabled.gif");
  132. }
  133. for (var count in this.fields) {
  134. this.toggleCascadeState(this.fields[count].id, this.fields[count].cascades[this.currentLanguage]);
  135. this.toScreen(this.fields[count].id);
  136. }
  137. }
  138. ContentLanguage.prototype.addField = function(fieldId, strCascades, intType, objOptions) {
  139. //*** Create and store the field object in the global fields array.
  140. switch (intType) {
  141. case this.FIELDTYPE.DATE:
  142. var objField = new DateField(fieldId, this, strCascades);
  143. break;
  144. case this.FIELDTYPE.TEXT:
  145. case this.FIELDTYPE.SIMPLETEXT:
  146. var objField = new TextField(fieldId, this, strCascades);
  147. break;
  148. case this.FIELDTYPE.CHECKBOX:
  149. var objField = new CheckBox(fieldId, this, strCascades);
  150. break;
  151. case this.FIELDTYPE.TEXTAREA:
  152. var objField = new TextAreaField(fieldId, this, strCascades);
  153. break;
  154. case this.FIELDTYPE.FILE:
  155. case this.FIELDTYPE.IMAGE:
  156. var objField = new FileField(fieldId, this, strCascades, objOptions);
  157. break;
  158. case this.FIELDTYPE.SELECT_LIST:
  159. var objField = new SelectListField(fieldId, this, strCascades);
  160. break;
  161. case this.FIELDTYPE.CHECK_LIST:
  162. var objField = new CheckListField(fieldId, this, strCascades);
  163. break;
  164. }
  165. this.fields[fieldId] = objField;
  166. this.toScreen(fieldId);
  167. }
  168. ContentLanguage.prototype.toScreen = function(fieldId) {
  169. this.fields[fieldId].toScreen();
  170. }
  171. ContentLanguage.prototype.toTemp = function(fieldId) {
  172. if (fieldId == undefined) {
  173. for (var intCount in this.fields) {
  174. this.fields[intCount].toTemp();
  175. }
  176. } else {
  177. this.fields[fieldId].toTemp();
  178. }
  179. }
  180. ContentLanguage.prototype.dateToTemp = function(objDate) {
  181. if (objDate != undefined) {
  182. objContentLanguage.toTemp(objDate.params.inputField.id);
  183. }
  184. }
  185. ContentLanguage.prototype.transferField = function(fieldId) {
  186. this.fields[fieldId].transferField();
  187. }
  188. ContentLanguage.prototype.sort = function(fieldId) {
  189. this.fields[fieldId].sort();
  190. }
  191. ContentLanguage.prototype.removeUploadField = function(fieldId, objTrigger) {
  192. this.fields[fieldId].removeUploadField(objTrigger);
  193. }
  194. ContentLanguage.prototype.removeCurrentField = function(fieldId, objTrigger) {
  195. this.fields[fieldId].removeCurrentField(objTrigger);
  196. }
  197. ContentLanguage.prototype.buttonOver = function(strButtonType, objImage, fieldId) {
  198. var $objImage = (objImage instanceof jQuery) ? objImage : jQuery(objImage), // Make sure it's a jQuery object
  199. $objButton = $objImage.parent();
  200. this.hover = true;
  201. this.buttonType = strButtonType;
  202. switch (strButtonType) {
  203. case "cascadeElement":
  204. if (this.cascades[this.currentLanguage] !== true) {
  205. $objImage.attr("src", "images/lang_locked.gif");
  206. overlib("<?php echo $objLang->get("langElementCascade", "tip") ?>");
  207. } else {
  208. $objImage.attr("src", "images/lang_unlocked.gif");
  209. overlib("<?php echo $objLang->get("langElementUnlock", "tip") ?>");
  210. }
  211. break;
  212. case "cascadeField":
  213. if (this.fields[fieldId].cascades[this.currentLanguage] !== true) {
  214. $objImage.attr("src", "images/lang_locked.gif");
  215. overlib("<?php echo $objLang->get("langFieldCascade", "tip") ?>");
  216. } else {
  217. $objImage.attr("src", "images/lang_unlocked.gif");
  218. overlib("<?php echo $objLang->get("langFieldUnlock", "tip") ?>");
  219. }
  220. break;
  221. case "activeElement":
  222. if (this.actives[this.currentLanguage] != true) {
  223. overlib("<?php echo $objLang->get("langEnable", "tip") ?>");
  224. $objImage.attr("src", "images/lang_enabled.gif");
  225. } else {
  226. overlib("<?php echo $objLang->get("langDisable", "tip") ?>");
  227. $objImage.attr("src", "images/lang_disabled.gif");
  228. }
  229. break;
  230. }
  231. }
  232. ContentLanguage.prototype.buttonOut = function(strButtonType, objImage, fieldId) {
  233. var $objImage = (objImage instanceof jQuery) ? objImage : jQuery(objImage), // Make sure it's a jQuery object
  234. $objButton = $objImage.parent();
  235. this.hover = false;
  236. this.buttonType = strButtonType;
  237. switch (strButtonType) {
  238. case "cascadeElement":
  239. if (this.cascades[this.currentLanguage] !== true) {
  240. $objImage.attr("src", "images/lang_unlocked.gif");
  241. } else {
  242. $objImage.attr("src", "images/lang_locked.gif");
  243. }
  244. nd();
  245. break;
  246. case "cascadeField":
  247. if (this.fields[fieldId].cascades[this.currentLanguage] !== true) {
  248. $objImage.attr("src", "images/lang_unlocked.gif");
  249. } else {
  250. $objImage.attr("src", "images/lang_locked.gif");
  251. }
  252. nd();
  253. break;
  254. case "activeElement":
  255. if (this.actives[this.currentLanguage] != true) {
  256. $objImage.attr("src", "images/lang_disabled.gif");
  257. } else {
  258. $objImage.attr("src", "images/lang_enabled.gif");
  259. }
  260. nd();
  261. break;
  262. }
  263. }
  264. ContentLanguage.prototype.toggleCascadeElement = function() {
  265. //*** Set the toggle in the object.
  266. if (this.cascades[this.currentLanguage]) {
  267. if (this.cascades[this.currentLanguage] == true) {
  268. this.cascades[this.currentLanguage] = false;
  269. } else {
  270. this.cascades[this.currentLanguage] = true;
  271. }
  272. } else {
  273. this.cascades[this.currentLanguage] = true;
  274. }
  275. //*** Toggle button image.
  276. if (this.cascades[this.currentLanguage] == true) {
  277. if (this.hover) overlib("<?php echo $objLang->get("langElementUnlock", "tip") ?>");
  278. jQuery("#language_cascade").attr("src", "images/lang_unlocked.gif");
  279. } else {
  280. if (this.hover) overlib("<?php echo $objLang->get("langElementCascade", "tip") ?>");
  281. jQuery("#language_cascade").attr("src", "images/lang_locked.gif");
  282. }
  283. //*** Take action according to the state.
  284. for (var count in this.fields) {
  285. this.toggleCascadeState(this.fields[count].id, this.cascades[this.currentLanguage]);
  286. this.toScreen(this.fields[count].id);
  287. }
  288. }
  289. ContentLanguage.prototype.toggleCascadeField = function(fieldId) {
  290. //*** Set the toggle in the object.
  291. if (this.fields[fieldId].cascades[this.currentLanguage]) {
  292. if (this.fields[fieldId].cascades[this.currentLanguage] == true) {
  293. this.fields[fieldId].cascades[this.currentLanguage] = false;
  294. } else {
  295. this.fields[fieldId].cascades[this.currentLanguage] = true;
  296. }
  297. } else {
  298. this.fields[fieldId].cascades[this.currentLanguage] = true;
  299. }
  300. //*** Reset global cascade state.
  301. this.cascades[this.currentLanguage] = false;
  302. jQuery("#language_cascade").attr("src", "images/lang_unlocked.gif");
  303. //*** Take action according to the state.
  304. this.toggleCascadeState(this.fields[fieldId].id, this.fields[fieldId].cascades[this.currentLanguage]);
  305. this.toScreen(this.fields[fieldId].id);
  306. }
  307. ContentLanguage.prototype.toggleActiveElement = function() {
  308. if (this.actives[this.currentLanguage] == true) {
  309. this.actives[this.currentLanguage] = false;
  310. } else {
  311. this.actives[this.currentLanguage] = true;
  312. }
  313. //*** Reset cascades if default language is disabled.
  314. if (this.currentLanguage == this.defaultLanguage && this.actives[this.currentLanguage] != true) {
  315. //*** Reset element cascade.
  316. this.cascades[this.currentLanguage] = false;
  317. //*** Reset field cascades.
  318. for (var count in this.fields) {
  319. this.fields[count].cascades = {};
  320. }
  321. }
  322. //*** Set buttons and other stuff.
  323. this.toggleActivesState();
  324. this.swap(this.currentLanguage);
  325. }
  326. ContentLanguage.prototype.toggleCascadeState = function(fieldId, state) {
  327. //*** Toggle object property.
  328. this.fields[fieldId].cascades[this.currentLanguage] = state;
  329. //*** Set the cascade input field.
  330. var strValue = this.fields[fieldId].getCascades();
  331. jQuery("#" + fieldId + "_cascades").val(strValue);
  332. }
  333. ContentLanguage.prototype.toggleActivesState = function() {
  334. //*** Set the actives input field.
  335. jQuery("#language_actives").val(this.getActives());
  336. }
  337. ContentLanguage.prototype.setActives = function(strActives) {
  338. var arrActives = strActives.split(",");
  339. this.actives = {};
  340. for (var count = 0; count < arrActives.length; count++) {
  341. this.actives[arrActives[count]] = true;
  342. }
  343. this.swap(this.currentLanguage);
  344. }
  345. ContentLanguage.prototype.getActives = function() {
  346. var strReturn = "";
  347. var arrTemp = new Array();
  348. for (var count in this.actives) {
  349. if (this.actives[count] == true) {
  350. arrTemp.push(count);
  351. }
  352. }
  353. strReturn = arrTemp.join(",");
  354. return strReturn;
  355. }
  356. ContentLanguage.prototype.setFieldValue = function(fieldId, strValue) {
  357. jQuery("#" + fieldId + "_" + this.currentLanguage).val(strValue);
  358. }
  359. ContentLanguage.prototype.loadStoragePage = function(objTrigger) {
  360. var strUrl = "ajax.php",
  361. $objFiles = jQuery("#storageBrowser_" + objTrigger.id + " ul"),
  362. $objList = jQuery("#storageBrowser_" + objTrigger.id + " div.storageList"),
  363. $objLoader = jQuery("<div/>",{
  364. "class":"storageLoader",
  365. "html": "<?php echo $objLang->get("loadingFiles", "form") ?>",
  366. "css":{
  367. "display":"block"
  368. }
  369. }),
  370. strPost = {
  371. cmd: "StorageItems::getFileListHTML",
  372. parentId: jQuery('#frm_storage_' + objTrigger.id).find('option:selected').val().split("_").pop()
  373. };
  374. if ($objFiles.length > 0) $objFiles.find(":first").remove();
  375. jQuery(".storageLoader").remove(); // Clear all loaders before inserting a new one.
  376. $objList.append($objLoader);
  377. var request = jQuery.get(strUrl, strPost, function(data) { objTrigger.parent.showStoragePage(data, objTrigger); }, "xml");
  378. }
  379. ContentLanguage.prototype.showStoragePage = function(objResponse, objTrigger) {
  380. var $objField = jQuery(objResponse).find("field"),
  381. $objLoader = jQuery("#storageBrowser_" + objTrigger.id + " div.storageLoader"),
  382. $objList = jQuery("#storageBrowser_" + objTrigger.id + " div.storageList");
  383. $objLoader.fadeOut();
  384. $objList.html($objField.text());
  385. //*** Attach events to the thumbs.
  386. jQuery("#storageBrowser_" + objTrigger.id + " li").each(function(i){
  387. var $objLink = jQuery(this).find("a:first");
  388. $objLink
  389. .bind("mouseover mouseout click", function(event){
  390. var $objLabel = jQuery(this).parent().find("span:first");
  391. switch(event.type){
  392. case "mouseover":
  393. return overlib($objLabel.html());
  394. break;
  395. case "mouseout":
  396. return nd();
  397. break;
  398. case "click":
  399. objTrigger.transferStorage(jQuery(this), $objLabel.html());
  400. return false;
  401. break;
  402. }
  403. });
  404. }); // End .each()
  405. }
  406. /***
  407. * ContentField object.
  408. */
  409. function ContentField(strId, objParent, strCascades) {
  410. this.id = strId || 0;
  411. this.parent = objParent || null;
  412. this.cascades = {};
  413. if (strCascades != undefined) this.setCascades(strCascades);
  414. }
  415. ContentField.prototype.getCascades = function() {
  416. var strReturn = "";
  417. var arrTemp = new Array();
  418. for (var count in this.cascades) {
  419. if (this.cascades[count] == true && count != "") {
  420. arrTemp.push(count);
  421. }
  422. }
  423. strReturn = arrTemp.join(",");
  424. return strReturn;
  425. }
  426. ContentField.prototype.setCascades = function(strCascades) {
  427. var arrCascades = strCascades.split(",");
  428. this.cascades = {};
  429. for (var count = 0; count < arrCascades.length; count++) {
  430. this.cascades[arrCascades[count]] = true;
  431. }
  432. jQuery("#" + this.id + "_cascades").val(this.getCascades());
  433. }
  434. ContentField.prototype.setIconCascade = function() {
  435. var $objImage = jQuery("#" + this.id + "_cascade"),
  436. $objButton = $objImage.parent(),
  437. strId = this.id;
  438. //*** Attach mouse events to the cascade button.
  439. if (this.parent.currentLanguage == this.parent.defaultLanguage || this.parent.actives[this.parent.currentLanguage] != true || this.parent.actives[this.parent.defaultLanguage] != true) {
  440. $objButton.unbind("mouseover mouseout click");
  441. //*** Set the cascade icon.
  442. if (this.cascades[this.parent.currentLanguage] == true) {
  443. var strImageSrc = "images/lang_locked_disabled.gif";
  444. } else {
  445. var strImageSrc = "images/lang_unlocked_disabled.gif";
  446. $objButton.bind("click", function(){ return false; }); // No need to be clickable
  447. }
  448. $objImage.attr("src", strImageSrc);
  449. } else {
  450. $objButton.unbind("mouseover mouseout click"); // Clear all events before binding new ones
  451. $objButton.bind("mouseover mouseout click", function(event){
  452. var objReturn;
  453. switch(event.type){
  454. case "mouseover":
  455. objContentLanguage.buttonOver('cascadeField', this, strId);
  456. break;
  457. case "mouseout":
  458. objContentLanguage.buttonOut('cascadeField', this, strId);
  459. break;
  460. case "click":
  461. objContentLanguage.toggleCascadeField(strId);
  462. break;
  463. }
  464. return false;
  465. });
  466. //*** Set the cascade icon.
  467. if (this.cascades[this.parent.currentLanguage] == true) {
  468. if (this.parent.hover && this.parent.buttonType == "cascadeField") overlib("<?php echo $objLang->get("langFieldUnlock", "tip") ?>");
  469. $objImage.attr("src", "images/lang_locked.gif");
  470. } else {
  471. if (this.parent.hover && this.parent.buttonType == "cascadeField") overlib("<?php echo $objLang->get("langFieldCascade", "tip") ?>");
  472. $objImage.attr("src", "images/lang_unlocked.gif");
  473. }
  474. }
  475. }
  476. ContentField.prototype.toScreen = function() {
  477. this.setIconCascade();
  478. jQuery("#" + this.id).val(jQuery("#" + this.id + "_" + this.parent.currentLanguage).val());
  479. return true;
  480. }
  481. ContentField.prototype.toTemp = function() {
  482. var strValue = jQuery("#" + this.id).val();
  483. jQuery("#" + this.id + "_" + this.parent.currentLanguage).val(strValue);
  484. return true;
  485. }
  486. /***
  487. * TextField object.
  488. */
  489. function TextField(strId, objParent, strCascades) {
  490. this.base = ContentField;
  491. this.base(strId, objParent, strCascades);
  492. };
  493. TextField.prototype = new ContentField();
  494. TextField.prototype.toScreen = function() {
  495. //*** Attach mouse events to the cascade button.
  496. this.setIconCascade();
  497. //*** Insert value into the field.
  498. if (this.parent.actives[this.parent.currentLanguage] != true) {
  499. //*** The element is not active.
  500. jQuery("#" + this.id + "_alt").html("<?php echo $objLang->get("langDisabled", "label") ?>");
  501. jQuery("#" + this.id).hide();
  502. jQuery("#" + this.id + "_alt").show();
  503. } else if (this.cascades[this.parent.currentLanguage] == true) {
  504. //*** The field is cascading.
  505. var strValue = jQuery("#" + this.id + "_" + this.parent.defaultLanguage).val();
  506. jQuery("#" + this.id + "_alt").html((strValue == "") ? "&nbsp;" : strValue);
  507. jQuery("#" + this.id).hide();
  508. jQuery("#" + this.id + "_alt").show();
  509. if(jQuery("#" + this.id + "_element").length > 0)
  510. {
  511. jQuery("#" + this.id + "_element").html(jQuery("#" + this.id + "_"+ this.parent.defaultLanguage +"_element").val());
  512. }
  513. } else {
  514. //*** The field needs no special treatment.
  515. jQuery("#" + this.id + "_alt").hide();
  516. jQuery("#" + this.id).show();
  517. jQuery("#" + this.id).val(jQuery("#" + this.id + "_" + this.parent.currentLanguage).val());
  518. if(jQuery("#" + this.id + "_element").length > 0)
  519. {
  520. jQuery("#" + this.id + "_element").html(jQuery("#" + this.id + "_"+ this.parent.currentLanguage +"_element").val());
  521. }
  522. }
  523. }
  524. TextField.prototype.toTemp = function() {
  525. jQuery("#" + this.id + "_" + this.parent.currentLanguage).val(jQuery("#" + this.id).val());
  526. }
  527. /***
  528. * TextAreaField object.
  529. */
  530. function TextAreaField(strId, objParent, strCascades) {
  531. this.base = ContentField;
  532. this.base(strId, objParent, strCascades);
  533. };
  534. TextAreaField.prototype = new ContentField();
  535. TextAreaField.prototype.toScreen = function() {
  536. //*** Attach mouse events to the cascade button.
  537. this.setIconCascade();
  538. //*** Insert value into the field.
  539. if (this.parent.actives[this.parent.currentLanguage] != true) {
  540. //*** The element is not active.
  541. jQuery("#" + this.id + "_alt").html("<?php echo $objLang->get("langDisabled", "label") ?>");
  542. jQuery("#" + this.id + "_alt").show();
  543. jQuery("#cke_" + this.id).hide();
  544. } else if (this.cascades[this.parent.currentLanguage] == true) {
  545. //*** The field is cascading.
  546. var strValue = jQuery("#" + this.id + "_" + this.parent.defaultLanguage).val();
  547. jQuery("#" + this.id + "_alt").html((strValue == "") ? "&nbsp;" : strValue);
  548. jQuery("#" + this.id + "_alt").show();
  549. jQuery("#cke_" + this.id).hide();
  550. } else {
  551. //*** The field needs no special treatment.
  552. jQuery("#" + this.id + "_alt").hide();
  553. jQuery("#cke_" + this.id).show();
  554. if (typeof CKEDITOR != "undefined") {
  555. var objArea = CKEDITOR.instances[this.id];
  556. if (typeof objArea == "object"){
  557. objArea.setData(jQuery("#" + this.id + "_" + this.parent.currentLanguage).val());
  558. }else{
  559. $("#" + this.id).val(jQuery("#" + this.id + "_" + this.parent.currentLanguage).val());
  560. }
  561. }
  562. }
  563. }
  564. TextAreaField.prototype.toTemp = function() {
  565. var strValue = CKEDITOR.instances[this.id].getData();
  566. if (strValue == "<p>&nbsp;</p>") strValue = "";
  567. jQuery("#" + this.id + "_" + this.parent.currentLanguage).val(strValue);
  568. }
  569. /***
  570. * FileField object.
  571. */
  572. function FileField(strId, objParent, strCascades, objOptions) {
  573. var __this = this;
  574. this.base = ContentField;
  575. this.base(strId, objParent, strCascades);
  576. //*** Set local properties.
  577. this.$objTrigger = jQuery("#" + strId);
  578. this.subFiles = {};
  579. this.maxFiles = 1;
  580. this.maxChar = 50;
  581. this.fileCount = 1;
  582. this.thumbPath = "";
  583. this.uploadPath = "";
  584. this.selectType = [];
  585. this.fileType = "*.*";
  586. this.swfUpload = null;
  587. //*** Parse the options.
  588. for (var intCount in objOptions) {
  589. this[intCount] = objOptions[intCount];
  590. }
  591. //*** Attach event to the file button.
  592. if (this.$objTrigger.is("input") && this.$objTrigger.attr("type") == "file"){
  593. //*** What to do when a file is selected.
  594. this.$objTrigger.bind("change", function(){
  595. objParent.transferField(strId);
  596. });
  597. } else {
  598. //*** This can only be applied to file input elements!
  599. alert("Error: " + strId + " is not a file input element!");
  600. }
  601. //*** Attach event to the library button.
  602. jQuery("#browseStorage_" + strId).toggle(
  603. function(){
  604. __this.openStorageBrowser();
  605. jQuery(this).text("<?php echo $objLang->get("pcmsInlineStorage", "menu"); ?>");
  606. return false;
  607. },
  608. function(){
  609. __this.closeStorageBrowser();
  610. jQuery(this).text("<?php echo $objLang->get("pcmsInlineStorage", "menu"); ?>");
  611. return false;
  612. }
  613. );
  614. //*** Attach event to the library folder select.
  615. jQuery("#frm_storage_" + strId).bind("change", function(){
  616. __this.parent.loadStoragePage(__this);
  617. return false;
  618. });
  619. //*** Create containers.
  620. var arrLang = [this.parent.currentLanguage, this.parent.defaultLanguage];
  621. for (var intCount = 0; intCount < arrLang.length; intCount++) {
  622. if (!this.subFiles[arrLang[intCount]]) {
  623. var intCurrent = (jQuery("#" + this.id + "_" + arrLang[intCount] + "_current").val()) ? parseInt(jQuery("#" + this.id + "_" + arrLang[intCount] + "_current").val()) : 0;
  624. this.subFiles[arrLang[intCount]] = {currentFiles:intCurrent, toUpload:new Array, uploaded:new Array()};
  625. for (var intCountX = 1; intCountX < intCurrent + 1; intCountX++) {
  626. this.subFiles[arrLang[intCount]].uploaded.push(jQuery("#" + this.id + "_" + arrLang[intCount] + "_" + intCountX).get(0));
  627. this.fileCount++;
  628. }
  629. }
  630. }
  631. //*** Initiate SWFUpload code.
  632. var settings = {
  633. jsParent : __this,
  634. flash_url : "/libraries/swfupload.swf",
  635. upload_url: "/upload.php",
  636. post_params: {
  637. "PHPSESSID" : "<?php echo session_id(); ?>",
  638. "fileId" : __this.id
  639. },
  640. file_size_limit : "100 MB",
  641. file_types : __this.fileType,
  642. file_types_description : "Files",
  643. file_upload_limit : __this.maxFiles - ((this.subFiles[this.parent.currentLanguage].toUpload.length) + this.subFiles[this.parent.currentLanguage].currentFiles),
  644. file_queue_limit : __this.maxFiles - ((this.subFiles[this.parent.currentLanguage].toUpload.length) + this.subFiles[this.parent.currentLanguage].currentFiles),
  645. custom_settings : {
  646. progressTarget : __this.id + "_uploadProgress",
  647. cancelButtonId : __this.id + "_cancel"
  648. },
  649. debug: false,
  650. // Button Settings
  651. button_image_url : "/images/XPButtonUploadText_61x22.png",
  652. button_placeholder_id : __this.id + "_browse",
  653. button_window_mode: SWFUpload.WINDOW_MODE.OPAQUE,
  654. button_width: 61,
  655. button_height: 22,
  656. // The event handler functions are defined in handlers.js
  657. swfupload_loaded_handler : __this.swfUploadLoaded,
  658. file_queued_handler : __this.fileQueued,
  659. file_queue_error_handler : __this.fileQueueError,
  660. file_dialog_complete_handler : __this.fileDialogComplete,
  661. upload_start_handler : __this.uploadStart,
  662. upload_progress_handler : __this.uploadProgress,
  663. upload_error_handler : __this.uploadError,
  664. upload_success_handler : __this.uploadSuccess,
  665. upload_complete_handler : __this.uploadComplete,
  666. queue_complete_handler : __this.queueComplete, // Queue plugin event
  667. // SWFObject settings
  668. minimum_flash_version : "9.0.28",
  669. swfupload_pre_load_handler : __this.swfUploadPreLoad,
  670. swfupload_load_failed_handler : __this.swfUploadLoadFailed
  671. };
  672. this.swfUpload = new SWFUpload(settings);
  673. };
  674. FileField.prototype = new ContentField();
  675. FileField.prototype.toScreen = function() {
  676. //*** Attach mouse events to the cascade button.
  677. this.setIconCascade();
  678. //*** Insert value into the field.
  679. if (this.parent.actives[this.parent.currentLanguage] != true) {
  680. //*** The element is not active.
  681. jQuery("#" + this.id + "_alt").html("<?php echo $objLang->get("langDisabled", "label") ?>");
  682. jQuery("#" + this.id + "_widget").hide();
  683. //Fadein
  684. jQuery("#" + this.id + "_alt").fadeIn();
  685. } else if (this.cascades[this.parent.currentLanguage] == true) {
  686. //*** The field is cascading.
  687. var strValue = "";
  688. for (var intCount = 0; intCount < this.subFiles[this.parent.defaultLanguage].uploaded.length; intCount++) {
  689. var arrValue = this.subFiles[this.parent.defaultLanguage].uploaded[intCount].value.split(":");
  690. strValue += this.shortName(arrValue[0], 40) + "<br />";
  691. }
  692. for (var intCount = 0; intCount < this.subFiles[this.parent.defaultLanguage].toUpload.length; intCount++) {
  693. var arrValue = this.subFiles[this.parent.defaultLanguage].toUpload[intCount].val().split(":");
  694. strValue += this.shortName(arrValue[0], 40) + "<br />";
  695. }
  696. jQuery("#" + this.id + "_alt").html((strValue == "") ? "&nbsp;" : strValue);
  697. jQuery("#" + this.id + "_widget").hide();
  698. //Fadein
  699. jQuery("#" + this.id + "_alt").fadeIn();
  700. } else {
  701. //*** The field needs no special treatment.
  702. jQuery("#" + this.id + "_widget").show();
  703. jQuery("#" + this.id + "_alt").hide();
  704. //*** Insert upload rows.
  705. jQuery("#" + this.id + "_widget div.required").show();
  706. jQuery("#filelist_new_" + this.id).hide();
  707. jQuery("#filelist_new_" + this.id + " div.multifile").each(function() {
  708. jQuery(this).remove();
  709. });
  710. //*** Init object if not exists.
  711. if (!this.subFiles[this.parent.currentLanguage]) {
  712. var intCurrent = (jQuery("#" + this.id + "_" + this.parent.currentLanguage + "_current").val()) ? parseInt(jQuery("#" + this.id + "_" + this.parent.currentLanguage + "_current").val()) : 0;
  713. this.subFiles[this.parent.currentLanguage] = {currentFiles:intCurrent, toUpload:new Array, uploaded:new Array()};
  714. for (var intCount = 1; intCount < intCurrent + 1; intCount++) {
  715. this.subFiles[this.parent.currentLanguage].uploaded.push(jQuery("#" + this.id + "_" + this.parent.currentLanguage + "_" + intCount).get(0));
  716. this.fileCount++;
  717. }
  718. }
  719. for (var intCount = 0; intCount < this.subFiles[this.parent.currentLanguage].toUpload.length; intCount++) {
  720. var filledElement = this.subFiles[this.parent.currentLanguage].toUpload[intCount];
  721. if (this.swfUpload.movieCount > 0) {
  722. this.addSwfUploadRow(filledElement);
  723. } else {
  724. this.addUploadRow(filledElement);
  725. }
  726. jQuery("#filelist_new_" + this.id).show();
  727. }
  728. //*** Insert current rows.
  729. jQuery("#filelist_current_" + this.id).hide();
  730. jQuery("#filelist_current_" + this.id + " div.multifile").each(function() {
  731. jQuery(this).remove();
  732. });
  733. for (var intCount = 0; intCount < this.subFiles[this.parent.currentLanguage].uploaded.length; intCount++) {
  734. var filledElement = this.subFiles[this.parent.currentLanguage].uploaded[intCount],
  735. blnStorage = (filledElement.value.split(":").length > 2) ? true : false;
  736. this.addCurrentRow(filledElement, blnStorage);
  737. jQuery("#filelist_current_" + this.id).show();
  738. }
  739. //*** SWFUpload fields.
  740. try {
  741. this.swfUpload.setFileUploadLimit(this.maxFiles - ((this.subFiles[this.parent.currentLanguage].toUpload.length) + this.subFiles[this.parent.currentLanguage].currentFiles));
  742. this.swfUpload.setFileQueueLimit(this.maxFiles - ((this.subFiles[this.parent.currentLanguage].toUpload.length) + this.subFiles[this.parent.currentLanguage].currentFiles));
  743. var objStats = this.swfUpload.getStats();
  744. objStats.successful_uploads = this.subFiles[this.parent.currentLanguage].toUpload.length;
  745. this.swfUpload.setStats(objStats);
  746. } catch (e) {
  747. //*** Nothing.
  748. }
  749. var strId = this.id;
  750. jQuery.debug({content: $("#" + this.id + "_widget h3").next()});
  751. $("#" + this.id + "_widget h3").next().each(function(){
  752. if($(this).children().length < 0){
  753. jQuery.debug("Niet zichtbaar");
  754. }
  755. });
  756. jQuery("#filelist_current_" + this.id).sortable({
  757. dropOnEmpty: true,
  758. connectWith: "#groups, #allgroups",
  759. update: function(){
  760. objContentLanguage.sort(strId);
  761. },
  762. axis: "y"
  763. });
  764. jQuery("#filelist_current_" + this.id).disableSelection();
  765. }
  766. }
  767. FileField.prototype.openStorageBrowser = function() {
  768. var __this = this,
  769. closeLabel = "<?php echo $objLang->get("pcmsCloseInlineStorage", "menu"); ?>";
  770. //*** Slide open.
  771. jQuery("#storageBrowser_" + this.id).slideDown("fast", function(){
  772. jQuery("#browseStorage_" + __this.id).text(closeLabel);
  773. __this.parent.loadStoragePage(__this);
  774. });
  775. }
  776. FileField.prototype.closeStorageBrowser = function() {
  777. var __this = this,
  778. defaultLabel = "<?php echo $objLang->get("pcmsInlineStorage", "menu"); ?>";
  779. jQuery("#storageBrowser_" + this.id).slideUp("fast", function(){
  780. jQuery("#browseStorage_" + __this.id).text(defaultLabel);
  781. });
  782. }
  783. FileField.prototype.transferField = function() {
  784. var $filledElement = jQuery("#" + this.id),
  785. objParent = this.parent,
  786. strId = this.id;
  787. jQuery("#filelist_new_" + this.id).show();
  788. this.subFiles[this.parent.currentLanguage].toUpload.push($filledElement);
  789. $filledElement
  790. .attr("id", strId + "_" + objParent.currentLanguage + "_" + this.fileCount++)
  791. .attr("name", strId + "_" + objParent.currentLanguage + "_new[]");
  792. //*** Create empty replacement.
  793. var $objElement = jQuery("<input />")
  794. $objElement
  795. .attr("type", "file")
  796. .addClass("input-file")
  797. .attr("id", strId)
  798. .attr("name", strId + "_new")
  799. .bind("change", function(){
  800. objParent.transferField(strId);
  801. });
  802. $objElement.insertBefore($filledElement.next());
  803. //*** Add row to the upload list.
  804. this.addUploadRow($filledElement);
  805. //*** Appease Safari: display:none doesn't seem to work correctly in Safari.
  806. $filledElement.css({
  807. "position" : "absolute",
  808. "left" : "-100000px"
  809. });
  810. }
  811. FileField.prototype.addUploadRow = function(element) { // element is a jQuery object
  812. var objParent = this.parent,
  813. strId = this.id,
  814. $element = (element instanceof jQuery) ? element : jQuery(element), // Make sure it's a jQuery object
  815. $objRow = jQuery("<div />",{
  816. id: "file_" + $element.attr("id"),
  817. "class": "multifile",
  818. data: {"element": $element}
  819. }),
  820. $objButton = jQuery("<a />"),
  821. $objRowValue = jQuery("<p />");
  822. //$objRow
  823. // .attr("id", "file_" + $element.attr("id"))
  824. // .addClass("multifile")
  825. // .data("element", $element);
  826. $objButton
  827. .attr("href", "")
  828. .addClass("button")
  829. .html("&#735;")
  830. .attr("title", this.removeLabel)
  831. .bind("click", function(){
  832. objParent.removeUploadField(strId, this);
  833. return false;
  834. });
  835. $objRow.append($objButton);
  836. var arrValue = $element.val().split(":");
  837. var strValue = this.shortName(arrValue[0], this.maxChar);
  838. $objRowValue
  839. .html(strValue)
  840. $objRow
  841. .append($objRowValue);
  842. jQuery("#filelist_new_" + strId).append($objRow);
  843. //*** Check max files.
  844. if ((this.subFiles[this.parent.currentLanguage].toUpload.length + 1) + this.subFiles[this.parent.currentLanguage].currentFiles > this.maxFiles) {
  845. jQuery("#" + this.id + "_widget div.required").hide();
  846. jQuery("#storageBrowser_" + this.id).hide();
  847. }
  848. jQuery("#filelist_new_" + this.id).sortable({
  849. items: "div",
  850. axis: "y",
  851. update: function(){
  852. objContentLanguage.sort(strId);
  853. }
  854. });
  855. }
  856. FileField.prototype.addCurrentRow = function(element, blnStorage) { // Element should be a jQuery element
  857. var objParent = this.parent,
  858. strId = this.id,
  859. $element = (element instanceof jQuery) ? element : jQuery(element), // Make sure it's a jQuery object
  860. $objRow = jQuery("<div />"),
  861. $objButton = jQuery("<a />"),
  862. $objThumb = jQuery("<a />"),
  863. $objRowValue = jQuery("<p />"),
  864. $objAltText = jQuery("<p />");
  865. $objRow
  866. .attr("id", 'file_' + $element.attr("id"))
  867. .addClass((blnStorage) ? "multifile storage" : "multifile")
  868. .css({"position":"relative"})
  869. .data("element", $element);
  870. $objButton
  871. .addClass("button")
  872. .html("&#735;")
  873. .attr("title", this.removeLabel)
  874. .attr("href", "#")
  875. .bind("click", function(){
  876. objParent.removeCurrentField(strId, this);
  877. return false;
  878. });
  879. $objRow.append($objButton);
  880. var arrValue = $element.attr("value").split(":"),
  881. labelValue = arrValue.shift(),
  882. fileValue = arrValue.shift(),
  883. libraryValue = arrValue.shift(),
  884. alttextValue = arrValue.shift();
  885. //*** Image thumbnail.
  886. if (this.thumbPath != "") {
  887. var __this = this;
  888. if (this.isImage(fileValue)) {
  889. $objThumb
  890. .addClass("thumbnail")
  891. .html("<img src=\"thumb.php?src=" + this.thumbPath + fileValue + "\" alt=\"\" />")
  892. .attr("href", "")
  893. .bind("mouseover mouseout", function(event){
  894. if(event.type == "mouseover"){
  895. return overlib('<img src="' + __this.thumbPath + fileValue + '" alt="" />', FULLHTML);
  896. }
  897. else {
  898. return nd();
  899. }
  900. });
  901. } else {
  902. $objThumb
  903. .addClass("document")
  904. .html("<img src=\"/images/ico_document.gif\" alt=\"\" />")
  905. .attr("href", "")
  906. .bind("click mouseover mouseout", function(event){
  907. switch(event.type){
  908. case "mouseover":
  909. return overlib('This file will open in a new window.');
  910. break;
  911. case "mouseout":
  912. return nd();
  913. break;
  914. case "click":
  915. window.open(__this.thumbPath + fileValue);
  916. return false;
  917. break;
  918. }
  919. });
  920. }
  921. $objRow.append($objThumb); // Add the thumb to the row
  922. }
  923. //*** Label.
  924. $objRowValue.html(labelValue);
  925. $objRow.append($objRowValue);
  926. //*** Description.
  927. //$objAltText
  928. // .addClass("alt-text")
  929. // .html((alttextValue == "" || alttextValue == undefined) ? this.altLabel : alttextValue)
  930. // .bind("click", function() {
  931. // __this.startAltEdit(jQuery(this));
  932. // });
  933. $objRow.append($objAltText);
  934. jQuery("#filelist_current_" + strId).append($objRow);
  935. //*** Check max files.
  936. if ((this.subFiles[this.parent.currentLanguage].toUpload.length + 1) + this.subFiles[this.parent.currentLanguage].currentFiles > this.maxFiles) {
  937. jQuery("#" + strId + "_widget div.required").hide();
  938. jQuery("#storageBrowser_" + strId).hide();
  939. }
  940. }
  941. FileField.prototype.addSwfUploadRow = function(element, file) {
  942. var __this = this,
  943. strId = this.id,
  944. $element = (element instanceof jQuery) ? element : jQuery(element), // Make it a jQuery object
  945. $objRow = jQuery("<div/>"),
  946. $objButton = jQuery("<a/>"),
  947. $objThumb = jQuery("<a/>"),
  948. $tempFile = jQuery($element.data("file")),
  949. $objRowValue = jQuery("<p/>"),
  950. $objProgressBar = jQuery("<div/>"),
  951. $objProgressWrapper = jQuery("<div/>"),
  952. $objAltText = jQuery("<p/>");
  953. $objRow.attr("id", "file_" + $element.attr("id"));
  954. if (file !== undefined) {
  955. $objRow.addClass("multifile storage " + file.id);
  956. } else {
  957. $objRow.addClass("multifile storage " + $element.data("file").id);
  958. }
  959. $objRow
  960. .css("position","relative")
  961. .data("element", $element);
  962. if (file !== undefined) {
  963. $objRow.bind("mouseover mouseout", function(event) {
  964. if(event.type == "mouseover"){
  965. jQuery(this).find("a img").attr("src", "/images/ico_loading_mo.gif")
  966. //jQuery("#" + $objRow.attr("id")).find("a img").eq(0).attr("src", "/images/ico_loading_mo.gif");
  967. }
  968. else { // Then it's a mouseout event
  969. jQuery(this).find("a img").attr("src", "/images/ico_loading.gif");
  970. //jQuery("#" + $objRow.attr("id")).find("a img").eq(0).attr("src", "/images/ico_loading.gif");
  971. }
  972. });
  973. }
  974. //*** Delete button.
  975. $objButton.addClass("button");
  976. if (file !== undefined) {
  977. $objButton
  978. .html("&#735;")
  979. .attr("title", this.cancelLabel)
  980. .bind("click", function(event) {
  981. __this.cancelCurrentSwfUpload($element.attr("id"), file);
  982. event.stopPropagation();
  983. return false;
  984. });
  985. } else {
  986. $objButton
  987. .html("&#735;")
  988. .attr("title", this.removeLabel)
  989. .bind("click", function(event) {
  990. __this.cancelCurrentSwfUpload($element.attr("id"), $element.data("file"));
  991. event.stopPropagation();
  992. return false;
  993. });
  994. }
  995. $objButton.attr("href","");
  996. $objRow.append($objButton);
  997. var arrValue = $element.attr("value").split(":"),
  998. labelValue = arrValue.shift(),
  999. fileValue = arrValue.shift(),
  1000. libraryValue = arrValue.shift(),
  1001. alttextValue = arrValue.shift();
  1002. //*** Image thumbnail.
  1003. $objThumb.attr("href","")
  1004. if (file !== undefined) {
  1005. $objThumb
  1006. .addClass("document")
  1007. .html("<img src=\"/images/ico_loading.gif\" alt=\"\" />")
  1008. .bind("mouseover mouseout", function(event) {
  1009. if(event.type == "mouseover"){
  1010. return overlib('This file is being uploaded.');
  1011. }
  1012. else { // It's a mouseout event
  1013. return nd();
  1014. }
  1015. });
  1016. } else {
  1017. if (__this.thumbPath != "") {
  1018. if (__this.isImage(tempFile.name)) {
  1019. $objThumb
  1020. .addClass("thumbnail")
  1021. .html("<img src=\"thumb.php?src=" + __this.uploadPath + tempFile.name + "\" alt=\"\" />")
  1022. .bind("mouseover mouseout", function(event) {
  1023. if(event.type == "mouseover") {
  1024. return overlib("<img src=\"" + __this.uploadPath + tempFile.name + "\" alt=\"\" />", FULLHTML);
  1025. }
  1026. else {
  1027. return nd();
  1028. }
  1029. });
  1030. } else {
  1031. $objThumb
  1032. .addClass("document")
  1033. .html("<img src=\"/images/ico_document.gif\" alt=\"\" />")
  1034. .bind("mouseover mouseout click", function(event) {
  1035. switch(event.type){
  1036. case "click":
  1037. //window.open(__this.thumbPath + "upload/" + $tempFile.attr("name"));
  1038. window.open(__this.uploadPath + tempFile.name);
  1039. event.stopPropagation(); // kill all further bubbling
  1040. return false;
  1041. break;
  1042. case "mouseover":
  1043. return overlib("This file will open in a new window.");
  1044. break;
  1045. case "mouseout":
  1046. return nd();
  1047. break;
  1048. }
  1049. });
  1050. }
  1051. }
  1052. }
  1053. $objRow.append($objThumb);
  1054. //*** Label.
  1055. $objRowValue.html(labelValue);
  1056. $objRow.append($objRowValue);
  1057. if (file !== undefined) {
  1058. //*** Progress.
  1059. $objProgressBar.addClass("progressBar");
  1060. $objProgressWrapper
  1061. .addClass("progressWrapper")
  1062. .append($objProgressBar);
  1063. $objRow.append($objProgressWrapper);
  1064. } else {
  1065. //*** Description.
  1066. //$objAltText
  1067. // .addClass("alt-text")
  1068. // .html(this.altLabel)
  1069. // .bind("click", function() {
  1070. // __this.startAltEdit(jQuery(this));
  1071. // });
  1072. //$objRow.append($objAltText);
  1073. }
  1074. jQuery("#filelist_new_" + strId).append($objRow);
  1075. //*** Check max files.
  1076. if ((this.subFiles[this.parent.currentLanguage].toUpload.length + 1) + this.subFiles[this.parent.currentLanguage].currentFiles > this.maxFiles) {
  1077. jQuery("#storageBrowser_" + strId).hide();
  1078. }
  1079. jQuery("#filelist_new_" + strId).sortable({
  1080. items: "div",
  1081. update: function(){
  1082. objContentLanguage.sort(strId);
  1083. },
  1084. axis: "y"
  1085. });
  1086. }
  1087. FileField.prototype.removeSwfUploadRow = function(inputId, file) {
  1088. var arrTemp = new Array();
  1089. jQuery("#" + inputId).remove();
  1090. jQuery("#file_" + inputId).remove();
  1091. //*** Remove remotely.
  1092. objData = {
  1093. "do": "remove",
  1094. "file": file.name,
  1095. "PHPSESSID": "<?php echo session_id(); ?>"
  1096. };
  1097. jQuery.post("upload.php", objData,
  1098. function(data){
  1099. // TODO: Implement some feedback here
  1100. },
  1101. "xml");
  1102. for (var intCount = 0; intCount < this.subFiles[this.parent.currentLanguage].toUpload.length; intCount++) {
  1103. if (this.subFiles[this.parent.currentLanguage].toUpload[intCount].value != file.name) {
  1104. arrTemp.push(this.subFiles[this.parent.currentLanguage].toUpload[intCount]);
  1105. }
  1106. }
  1107. this.subFiles[this.parent.currentLanguage].toUpload = arrTemp;
  1108. jQuery("#" + this.id + "_widget div.required").show();
  1109. if (this.subFiles[this.parent.currentLanguage].toUpload.length == 0) {
  1110. jQuery("#filelist_new_" + this.id).hide();
  1111. }
  1112. }
  1113. FileField.prototype.removeUploadField = function(objTrigger) {
  1114. var strId = this.id,
  1115. $objTrigger = (objTrigger instanceof jQuery) ? objTrigger : jQuery(objTrigger), // Make it a jQuery object
  1116. cacheValue = $objTrigger.parent().data("element").val();
  1117. $objTrigger.parent().data("element").remove();
  1118. $objTrigger.parent().remove();
  1119. // objTrigger.parentNode.element.parentNode.removeChild(objTrigger.parentNode.element);
  1120. // objTrigger.parentNode.parentNode.removeChild(objTrigger.parentNode);
  1121. var arrTemp = new Array();
  1122. for (var intCount = 0; intCount < this.subFiles[this.parent.currentLanguage].toUpload.length; intCount++) {
  1123. if (this.subFiles[this.parent.currentLanguage].toUpload[intCount].value != cacheValue) {
  1124. arrTemp.push(this.subFiles[this.parent.currentLanguage].toUpload[intCount]);
  1125. }
  1126. }
  1127. this.subFiles[this.parent.currentLanguage].toUpload = arrTemp;
  1128. jQuery("#" + strId + "_widget div.required").show();
  1129. if (this.subFiles[this.parent.currentLanguage].toUpload.length == 0) {
  1130. jQuery("#filelist_new_" + strId).hide();
  1131. }
  1132. }
  1133. FileField.prototype.removeCurrentField = function(objTrigger) {
  1134. var strId = this.id,
  1135. $objTrigger = (objTrigger instanceof jQuery) ? objTrigger : jQuery(objTrigger), // Make it a jQuery object
  1136. cacheValue = $objTrigger.parent().data("element").val(),
  1137. arrTemp = new Array();
  1138. jQuery("#" + this.id + "_widget div.required").show();
  1139. for (var intCount = 0; intCount < this.subFiles[this.parent.currentLanguage].uploaded.length; intCount++) {
  1140. if (this.subFiles[this.parent.currentLanguage].uploaded[intCount].value != cacheValue) {
  1141. arrTemp.push(this.subFiles[this.parent.currentLanguage].uploaded[intCount]);
  1142. }
  1143. }
  1144. this.subFiles[this.parent.currentLanguage].uploaded = arrTemp;
  1145. this.subFiles[this.parent.currentLanguage].currentFiles--;
  1146. $objTrigger.parent().data("element").remove();
  1147. $objTrigger.parent().remove();
  1148. if (this.subFiles[this.parent.currentLanguage].uploaded.length == 0) {
  1149. jQuery("#filelist_current_" + this.id).hide();
  1150. }
  1151. this.toScreen();
  1152. }
  1153. FileField.prototype.shortName = function(strInput, maxLength) {
  1154. if (strInput.length > maxLength) {
  1155. //*** Get filename.
  1156. var pathDelimiter = (strInput.search(/\\/gi) > -1) ? "\\" : "/";
  1157. var arrPath = strInput.split(pathDelimiter);
  1158. var strFile = arrPath.pop();
  1159. //*** Calculate remaining length.
  1160. var reminingLength = (maxLength - strFile.length > 0) ? maxLength - strFile.length : 3;
  1161. var strPath = arrPath.join(pathDelimiter);
  1162. strInput = strPath.substr(0, reminingLength) + "..." + pathDelimiter + strFile;
  1163. }
  1164. return strInput;
  1165. }
  1166. FileField.prototype.transferStorage = function(objLink, strLabel) { // objLink is a jQuery object.
  1167. var $objElement = jQuery("<input />");
  1168. objLink.fadeOut("fast", function(){ jQuery(this).fadeIn("slow"); });
  1169. //*** Create input element.
  1170. $objElement.attr({
  1171. type: "hidden",
  1172. id: this.id + "_" + this.parent.currentLanguage + "_" + this.fileCount++,
  1173. name: this.id + "_" + this.parent.currentLanguage + "[]",
  1174. value: strLabel + ":" + objLink.find("img:first").attr("alt").split("/").pop() + ":" + objLink.attr("id").split("_").pop()
  1175. });
  1176. jQuery("#filelist_new_" + this.id).append($objElement);
  1177. this.subFiles[this.parent.currentLanguage].currentFiles++;
  1178. this.subFiles[this.parent.currentLanguage].uploaded.push($objElement.get(0));
  1179. jQuery("#filelist_current_" + this.id).show();
  1180. this.addCurrentRow($objElement, true);
  1181. }
  1182. FileField.prototype.isImage = function(fileName) {
  1183. var blnReturn = false;
  1184. var extension = fileName.toLowerCase().split(".").pop();
  1185. var arrImages = ['jpg', 'jpeg', 'gif', 'png'];
  1186. for (var count = 0; count < arrImages.length; count++) {
  1187. if (arrImages[count] == extension) {
  1188. blnReturn = true;
  1189. break;
  1190. }
  1191. }
  1192. return blnReturn;
  1193. }
  1194. FileField.prototype.toTemp = function() {};
  1195. FileField.prototype.sort = function() {
  1196. var arrFields = jQuery("#filelist_current_" + this.id).sortable("serialize").split("&"),
  1197. $objParent = jQuery("#" + this.id + "_widget");
  1198. for (var intCount = 0; intCount < arrFields.length; intCount++) {
  1199. var strTemp = arrFields[intCount].replace("file_" + this.id + "_" + this.parent.currentLanguage + "[]=", ""),
  1200. $objTemp = jQuery("#" + this.id + "_" + this.parent.currentLanguage + "_" + strTemp);
  1201. if ($objTemp) {
  1202. $objTemp.remove();
  1203. $objParent.append($objTemp);
  1204. }
  1205. }
  1206. }
  1207. FileField.prototype.swfUploadPreLoad = function() {
  1208. //alert("swfUploadPreLoad");
  1209. }
  1210. FileField.prototype.swfUploadLoaded = function() {
  1211. jQuery("#" + this.settings.jsParent.id).hide();
  1212. }
  1213. FileField.prototype.swfUploadLoadFailed = function() {
  1214. //*** TODO: Modal jQueryUI feedback box?
  1215. //alert("swfUploadLoadFailed");
  1216. }
  1217. FileField.prototype.fileQueued = function(file) {
  1218. //alert("FileField.prototype.fileQueued: " + file.name);
  1219. }
  1220. FileField.prototype.fileQueueError = function(file, errorCode, message) {
  1221. try {
  1222. if (errorCode === SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED) {
  1223. alert("You have attempted to queue too many files.\n" + (message === 0 ? "You have reached the upload limit." : "You may select " + (message > 1 ? "up to " + message + " files." : "one file.")));
  1224. return;
  1225. }
  1226. switch (errorCode) {
  1227. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  1228. alert("File " + file.name + " is too big.");
  1229. break;
  1230. case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
  1231. alert("File " + file.name + " is a zero size file.");
  1232. break;
  1233. case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
  1234. alert("File " + file.name + " is an invalid file type.");
  1235. break;
  1236. default:
  1237. alert("Upload encountered a problem.");
  1238. break;
  1239. }
  1240. } catch (ex) {
  1241. alert("Upload encountered a problem.");
  1242. }
  1243. }
  1244. FileField.prototype.fileDialogComplete = function(numFilesSelected, numFilesQueued) {
  1245. try {
  1246. if (numFilesSelected > 0) {
  1247. //document.getElementById("btnCancel").style.display = "inline";
  1248. }
  1249. this.startUpload();
  1250. } catch (ex) {
  1251. //this.debug(ex);
  1252. }
  1253. }
  1254. FileField.prototype.uploadStart = function(file) {
  1255. var $objElement = jQuery("<input />");
  1256. jQuery("#filelist_new_" + this.settings.jsParent.id).show();
  1257. //*** Create input element.
  1258. $objElement
  1259. .attr("type", "hidden")
  1260. .attr("id", this.settings.jsParent.id + "_" + this.settings.jsParent.parent.currentLanguage + "_" + this.settings.jsParent.fileCount++)
  1261. .attr("name", this.settings.jsParent.id + "_" + this.settings.jsParent.parent.currentLanguage + "[]")
  1262. .attr("value", file.name + ":::")
  1263. .data("file", file);
  1264. jQuery("#filelist_new_" + this.settings.jsParent.id).append($objElement);
  1265. this.settings.jsParent.subFiles[this.settings.jsParent.parent.currentLanguage].toUpload.push($objElement);
  1266. this.settings.jsParent.addSwfUploadRow($objElement, file);
  1267. }
  1268. FileField.prototype.uploadProgress = function(file, bytesLoaded, bytesTotal) {
  1269. var percent = Math.ceil((bytesLoaded / bytesTotal) * 100);
  1270. jQuery("div." + file.id + " div.progressBar").css({width:percent + "%"});
  1271. }
  1272. FileField.prototype.uploadSuccess = function(file, serverData) {
  1273. var __this = this.settings.jsParent;
  1274. jQuery("div." + file.id + " div.progressWrapper:first").remove();
  1275. jQuery("div." + file.id + ":first").unbind("mouseover").unbind("mouseout");
  1276. jQuery("div." + file.id + " a.button:first").html("&#735;").attr("title", __this.removeLabel);
  1277. if (__this.thumbPath != "") {
  1278. if (__this.isImage(file.name)) {
  1279. jQuery("div." + file.id + " a img:first").attr("src","thumb.php?src=" + __this.uploadPath + file.name);
  1280. jQuery("div." + file.id + " a.document:first")
  1281. .removeClass("document")
  1282. .addClass("thum…

Large files files are truncated, but you can click here to view the full file