templates.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /**
  2. *
  3. * @author: Malishev Dmitry <dima.malishev@gmail.com>
  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_create_file: ['<div class="confirm-box rename warning">\
  46. <div class="message">Create file</div>\
  47. <!-- div class="warning">File <span class="title">"reading.txt"</span> already exists</div -->\
  48. <div class="warning"></div>\
  49. <div class="actions">\
  50. <input type="text" id="rename-title" class="new-title" />\
  51. </div>\
  52. <div class="controls replace">\
  53. <p class="cancel" onClick="FM.popupClose();">cancel</p>\
  54. <p class="ok" onClick="FM.confirmCreateFile();">create</p>\
  55. </div>\
  56. </div>'],
  57. popup_create_dir: ['<div class="confirm-box rename warning">\
  58. <div class="message">Create directory</div>\
  59. <!-- div class="warning">File <span class="title">"reading.txt"</span> already exists</div -->\
  60. <div class="warning"></div>\
  61. <div class="actions">\
  62. <input type="text" id="rename-title" class="new-title" />\
  63. </div>\
  64. <div class="controls replace">\
  65. <p class="cancel" onClick="FM.popupClose();">cancel</p>\
  66. <p class="ok" onClick="FM.confirmCreateDir();">create</p>\
  67. </div>\
  68. </div>']
  69. }
  70. };
  71. // Internals
  72. var Tpl = App.Templates;
  73. var Templator = function()
  74. {
  75. var init = function()
  76. {
  77. fb.info('Templator work');
  78. Templator.splitThemAll();
  79. Templator.freezeTplIndexes();
  80. };
  81. /**
  82. * Split the tpl strings into arrays
  83. */
  84. Templator.splitThemAll = function(){
  85. fb.info('splitting tpls');
  86. jQuery.each(App.Templates.html, function(o){
  87. //try{
  88. var tpls = App.Templates.html[o];
  89. jQuery.each(tpls, function(t){
  90. tpls[t] = tpls[t][0].split('~!');
  91. });
  92. //}catch(e){fb.error('%o %o', o, e);}
  93. });
  94. },
  95. /**
  96. * Iterates tpls
  97. */
  98. Templator.freezeTplIndexes = function(){
  99. fb.info('freezing tpl keys');
  100. jQuery.each(App.Templates.html, Templator.cacheTplIndexes);
  101. },
  102. /**
  103. * Grab the tpl group key and process it
  104. */
  105. Templator.cacheTplIndexes = function(key)
  106. {
  107. var tpls = App.Templates.html[key];
  108. jQuery.each(tpls, function(o)
  109. {
  110. var tpl = tpls[o];
  111. Templator.catchIndex(key, o, tpl);
  112. });
  113. },
  114. /**
  115. * Set the indexes
  116. */
  117. Templator.catchIndex = function(key, ref_key, tpl)
  118. {
  119. 'undefined' == typeof App.Templates._indexes[key] ? App.Templates._indexes[key] = {} : false;
  120. 'undefined' == typeof App.Templates._indexes[key][ref_key] ?
  121. App.Templates._indexes[key][ref_key] = {} : false;
  122. jQuery(tpl).each(function(index, o) {
  123. if (':' == o.charAt(0)) {
  124. App.Templates._indexes[key][ref_key][o.toString()] = index;
  125. }
  126. });
  127. }
  128. /**
  129. * Get concrete templates
  130. */
  131. init();
  132. return Templator;
  133. };
  134. Templator.getTemplate = function(ns, key){
  135. return [
  136. App.Templates._indexes[ns][key],
  137. App.Templates.html[ns][key].slice(0)
  138. ];
  139. }
  140. // init templator
  141. Tpl.Templator = Templator();
  142. Tpl.get = function(key, group){
  143. return Tpl.Templator.getTemplate(group, key);
  144. }