PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/cms/scripts/themes.js

http://kancms.googlecode.com/
JavaScript | 267 lines | 205 code | 56 blank | 6 comment | 25 complexity | a6ca5c6f8b658e545baab26601fd54a8 MD5 | raw file
Possible License(s): BSD-2-Clause, GPL-2.0, LGPL-2.1
  1. // JavaScript Document
  2. var themes = {
  3. ajax_page: "ajax_pages/themes.php",
  4. init: function() {
  5. $p(".theme-name-link").bind("click", themes.themeNameAction );
  6. // chrome and firefox throw errors by not returning a usable HTMLElement
  7. // opera and IE9+ will execute following without error
  8. try {
  9. $p(".theme-name-link").node(0).click(); //.fire('click');
  10. } catch(e) {}
  11. $p("#theme-install-link").bind('click', function() {
  12. $p.post('forms/theme_upload_form.php', "", function(data) {
  13. $p.showDialog({
  14. title: 'Installing New Theme',
  15. content: data,
  16. okButtonText: "Upload And Install",
  17. okButtonAction: function() {
  18. $p.postMultiPartForm( themes.ajax_page, "#theme_upload_form", null, function(data) {
  19. if( $p.trim(data) != "" ) {
  20. alert(data);
  21. } else {
  22. history.go(0);
  23. }
  24. $p.hideDialog();
  25. });
  26. return false;
  27. }
  28. });
  29. });
  30. });
  31. $p("#theme-duplicate-link").bind('click',function() {
  32. var id = $p(this).attr("data-id");
  33. $p.confirm("This action will duplicate this theme info and its files. Do you want to continue?", function() {
  34. var query = "action=duplicate&theme_id=" + id;
  35. $p.post( themes.ajax_page, query, function(data) {
  36. var obj = $p.parseJSON(data);
  37. if( obj ) {
  38. var a = $p.create("a").addClass("theme-name-link").attr("data-id", obj.id).attr("href","#")
  39. .attr("title", "Preview Theme On Right").html( " " + ($p(".row-checker").count() + 1) + ". " + obj.ThemeName)
  40. .bind('click', themes.themeNameAction).node(0);
  41. var input = $p.create("input").attr("type","checkbox").attr("name","row-check")
  42. .attr("class","row-checker").val( obj.id ).node(0);
  43. var div = $p.create("div").attr("id","row-" + obj.id).addClass("row").node(0);
  44. div.appendChild(input);
  45. div.appendChild(a);
  46. document.getElementById("theme-rows").appendChild(div);
  47. }
  48. });
  49. });
  50. });
  51. $p("#theme-edit-link").bind('click',function() {
  52. var id = $p(this).attr("data-id");
  53. var query = "action=edit_theme&theme_id=" + id;
  54. $p.post( themes.ajax_page, query, function(data) {
  55. $p.showDialog({
  56. title: "Edit Theme",
  57. content: data,
  58. okButtonText: "Save Changes",
  59. okButtonAction: function() {
  60. themes.updateTheme();
  61. }
  62. }, function() {
  63. ui.htmlMiniEditor("ThemeDesc");
  64. });
  65. });
  66. });
  67. $p("#theme-export-link").bind('click',function(){
  68. var href = "ajax_pages/themes.php?action=export_theme&theme_id=" + $p(this).attr("data-id");
  69. window.location.href = href;
  70. });
  71. $p("#theme-delete-link").bind('click',function() {
  72. var id = $p(this).attr("data-id");
  73. $p.confirm("Do you want to delete this theme?", function() {
  74. var query = "action=delete_theme&theme_id=" + id;
  75. $p.post( themes.ajax_page, query, function() {
  76. $p("#row-" + id).remove();
  77. });
  78. });
  79. });
  80. $p("#all-checker").bind('click',function() {
  81. var checked = this.checked;
  82. $p.all(".row-checker",function(el){
  83. el.checked = checked;
  84. });
  85. });
  86. $p("#add-link").bind('click',function() {
  87. $p.post('forms/theme_create_form.php', "", function(data) {
  88. $p.showDialog({
  89. title: 'Create New Theme',
  90. content: data,
  91. okButtonText: 'Create New Theme',
  92. okButtonAction: function() {
  93. return themes.createTheme();
  94. }
  95. });
  96. ui.htmlMiniEditor("ThemeDesc");
  97. });
  98. });
  99. $p("#delete-link").bind('click',function(){
  100. $p.confirm("Do you want to delete the selected theme(s)?",function() {
  101. var selected = [];
  102. $p.all(".row-checker:checked",function(el) {
  103. selected.push( el.value );
  104. });
  105. var query = "action=delete_themes&ids=" + selected;
  106. $p.post( themes.ajax_page, query, function(data) {
  107. for(var i = 0; i < selected.length; i++) {
  108. $p("#row-" + selected[i]).remove();
  109. }
  110. });
  111. });
  112. });
  113. $p('#theme-create-form #ThemeFolder').bind('keyup', function() {
  114. var folderPath = this.value;
  115. var folderName = folderPath.split("/")[3];
  116. if( folderName != "<folder-name>" ){
  117. $p("#root-folder-text").html(folderName);
  118. }
  119. });
  120. // prevent the theme-create-form from submitting when the button is clicked
  121. $p('#create-theme-btn').bind('click', function() {
  122. if( !$p("#theme-create-form").validate() ) {
  123. return;
  124. }
  125. if( $p('#ThemeFolder').val() == "../assets/themes/<folder-name>/" ) {
  126. $p.inform("Please Edit The Folder Name Value To Use To Create The Theme Folder");
  127. return;
  128. }
  129. $p("#theme-create-form").node(0).submit();
  130. });
  131. if( document.getElementById("ThemeDesc") ) {
  132. ui.htmlMiniEditor("ThemeDesc");
  133. ui.htmlMiniEditor("CSSDescription");
  134. }
  135. },
  136. themeNameAction: function() {
  137. var id = $p(this).attr("data-id");
  138. var query = "action=load_info&theme_id=" + id;
  139. $p(".split_view .row").removeClass("selected");
  140. $p(".split_view #row-" + id).addClass("selected");
  141. $p(".nav .nav-link").attr("data-id", id);
  142. $p.post( themes.ajax_page, query, function(data) {
  143. $p("#info_view").html(data);
  144. file_utils.attachFolderHandlers();
  145. });
  146. },
  147. createTheme: function() {
  148. var valid = $p("#create-theme-form").validate();
  149. if( !valid ) {
  150. return false;
  151. }
  152. if( $p('#ThemeFolder').val() == "../assets/themes/<folder-name>/" ) {
  153. alert("Please Edit The Folder Name Value To Use To Create The Theme Folder");
  154. return false;
  155. }
  156. // save the contents of the description field
  157. tinyMCE.triggerSave();
  158. var query = "action=create_theme&" + $p("#create-theme-form").serialize();
  159. $p.post( themes.ajax_page, query, function(data) {
  160. if( $p.trim(data) != "" ) {
  161. $p.inform(data);
  162. } else {
  163. window.history.go(0);
  164. }
  165. });
  166. return true;
  167. },
  168. updateTheme: function() {
  169. var valid = $p("#update-theme-form").validate();
  170. if( !valid ) {
  171. return false;
  172. }
  173. if( $p('#ThemeFolder').val() == "../assets/themes/<folder-name>/" ) {
  174. alert("Please Edit The Folder Name Value To Use To Create The Theme Folder");
  175. return false;
  176. }
  177. // save the contents of the description field
  178. try {
  179. tinyMCE.triggerSave();
  180. } catch(e) {};
  181. var query = "action=update_theme&" + $p("#update-theme-form").serialize();
  182. $p.post( themes.ajax_page, query, function(data) {
  183. if( $p.trim(data) != "" ) {
  184. $p.inform(data);
  185. } else {
  186. window.history.go(0);
  187. }
  188. });
  189. return true;
  190. }
  191. };
  192. function initEditorContent() {
  193. var hf = document.getElementById("CSSContent");
  194. document.getElementById("editorApplet").setEditorContent( hf.value );
  195. }
  196. function showAppletEditor() {
  197. var fields = document.getElementById("cssedit_form").getElementsByTagName("input");
  198. for(var i = 0; i < fields.length; i++) {
  199. fields.item(i).disabled = true;
  200. }
  201. pageManager.show('editor_area');
  202. }
  203. function saveAppletEditorContent() {
  204. var field = document.getElementById("CSSContent");
  205. field.value = document.getElementById("editorApplet").getEditorContent();
  206. pageManager.hide('editor_area');
  207. var fields = document.getElementById("cssedit_form").getElementsByTagName("input");
  208. for(var i = 0; i < fields.length; i++) {
  209. fields.item(i).disabled = false;
  210. }
  211. }