templates.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /**
  2. *
  3. * @author: Malishev Dmitry <[email protected]>
  4. */
  5. App.Templates.html = {
  6. WEB: {
  7. hint: ['']
  8. },
  9. // file manager
  10. FM: {
  11. entry_line: ['<li class="dir">\
  12. <span class="marker"></span>\
  13. <span class="icon ~!:ITEM_TYPE~!" ></span>\
  14. <input type="hidden" class="source" value=\'~!:SOURCE~!\'/>\
  15. <span class="filename ripple" ~!:CL_ACTION_1~!>~!:NAME~!</span>\
  16. <span class="mode">~!:PERMISSIONS~!</span>\
  17. <span class="owner">~!:OWNER~!</span>\
  18. <span class="size">~!:SIZE~!</span>\
  19. <span class="date">~!:DATE~!</span>\
  20. <span class="time">~!:TIME~!</span>\
  21. </li>'],
  22. popup_delete: ['<div class="confirm-box delete popup-box">\
  23. <div class="message">Are you sure you want to delete file <span class="title">"~!:FILENAME~!"</span>?</div>\
  24. <div class="controls">\
  25. <p class="cancel" onClick="FM.popupClose();">cancel</p>\
  26. <p class="ok" onClick="FM.confirmDelete();">delete</p>\
  27. </div>\
  28. </div>'],
  29. popup_rename_: ['<div class="confirm-box rename warning">\
  30. <div class="message">Rename file <span class="title">"~!:FILENAME~!"</span></div>\
  31. <!-- div class="warning">File <span class="title">"reading.txt"</span> already exists</div -->\
  32. <div class="warning"></div>\
  33. <div class="actions">\
  34. <input type="text" id="rename-title" class="new-title" />\
  35. </div>\
  36. <div class="controls">\
  37. <p class="cancel" onClick="FM.popupClose();">cancel</p>\
  38. <p class="ok" onClick="FM.confirmRename();">rename</p>\
  39. </div>\
  40. <div class="controls replace">\
  41. <p class="cancel" onClick="FM.popupClose();">cancel</p>\
  42. <p class="ok" onClick="FM.confirmRename();">rename</p>\
  43. </div>\
  44. </div>'],
  45. popup_rename: ['<div class="confirm-box unpack warning">\
  46. <div class="message">Extract archive <span class="title">"~!:FILENAME~!"</span> to <span class="title">"~!:DIRNAME~!"</span></div>\
  47. <div class="warning"></div>\
  48. <div class="actions">\
  49. <label><input type="checkbox" name="overwrite" class="title" />Overwrite exising files</label>\
  50. </div>\
  51. <div class="controls">\
  52. <p class="cancel" onClick="FM.popupClose();">cancel</p>\
  53. <p class="ok" onClick="FM.confirmRename();">Extract</p>\
  54. </div>\
  55. </div>'],
  56. popup_create_file: ['<div class="confirm-box rename warning">\
  57. <div class="message">Create file</div>\
  58. <!-- div class="warning">File <span class="title">"reading.txt"</span> already exists</div -->\
  59. <div class="warning"></div>\
  60. <div class="actions">\
  61. <input type="text" id="rename-title" class="new-title" />\
  62. </div>\
  63. <div class="controls replace">\
  64. <p class="cancel" onClick="FM.popupClose();">cancel</p>\
  65. <p class="ok" onClick="FM.confirmCreateFile();">create</p>\
  66. </div>\
  67. </div>'],
  68. popup_create_dir: ['<div class="confirm-box rename warning">\
  69. <div class="message">Create directory</div>\
  70. <!-- div class="warning">File <span class="title">"reading.txt"</span> already exists</div -->\
  71. <div class="warning"></div>\
  72. <div class="actions">\
  73. <input type="text" id="rename-title" class="new-title" />\
  74. </div>\
  75. <div class="controls replace">\
  76. <p class="cancel" onClick="FM.popupClose();">cancel</p>\
  77. <p class="ok" onClick="FM.confirmCreateDir();">create</p>\
  78. </div>\
  79. </div>']
  80. }
  81. };
  82. // Internals
  83. var Tpl = App.Templates;
  84. var Templator = function()
  85. {
  86. var init = function()
  87. {
  88. fb.info('Templator work');
  89. Templator.splitThemAll();
  90. Templator.freezeTplIndexes();
  91. };
  92. /**
  93. * Split the tpl strings into arrays
  94. */
  95. Templator.splitThemAll = function(){
  96. fb.info('splitting tpls');
  97. jQuery.each(App.Templates.html, function(o){
  98. //try{
  99. var tpls = App.Templates.html[o];
  100. jQuery.each(tpls, function(t){
  101. tpls[t] = tpls[t][0].split('~!');
  102. });
  103. //}catch(e){fb.error('%o %o', o, e);}
  104. });
  105. },
  106. /**
  107. * Iterates tpls
  108. */
  109. Templator.freezeTplIndexes = function(){
  110. fb.info('freezing tpl keys');
  111. jQuery.each(App.Templates.html, Templator.cacheTplIndexes);
  112. },
  113. /**
  114. * Grab the tpl group key and process it
  115. */
  116. Templator.cacheTplIndexes = function(key)
  117. {
  118. var tpls = App.Templates.html[key];
  119. jQuery.each(tpls, function(o)
  120. {
  121. var tpl = tpls[o];
  122. Templator.catchIndex(key, o, tpl);
  123. });
  124. },
  125. /**
  126. * Set the indexes
  127. */
  128. Templator.catchIndex = function(key, ref_key, tpl)
  129. {
  130. 'undefined' == typeof App.Templates._indexes[key] ? App.Templates._indexes[key] = {} : false;
  131. 'undefined' == typeof App.Templates._indexes[key][ref_key] ?
  132. App.Templates._indexes[key][ref_key] = {} : false;
  133. jQuery(tpl).each(function(index, o) {
  134. if (':' == o.charAt(0)) {
  135. App.Templates._indexes[key][ref_key][o.toString()] = index;
  136. }
  137. });
  138. }
  139. /**
  140. * Get concrete templates
  141. */
  142. init();
  143. return Templator;
  144. };
  145. Templator.getTemplate = function(ns, key){
  146. return [
  147. App.Templates._indexes[ns][key],
  148. App.Templates.html[ns][key].slice(0)
  149. ];
  150. }
  151. // init templator
  152. Tpl.Templator = Templator();
  153. Tpl.get = function(key, group){
  154. return Tpl.Templator.getTemplate(group, key);
  155. }