Built files from Bizgaze WebServer
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

usertheme.js 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. var Unibase;
  2. (function (Unibase) {
  3. let Themes;
  4. (function (Themes) {
  5. let Compact;
  6. (function (Compact) {
  7. let Components;
  8. (function (Components) {
  9. class UserTheme extends Unibase.Platform.Core.BaseComponent {
  10. constructor() {
  11. super(...arguments);
  12. this.layoutElement = '#user-themes #menu-layouts .card-body .row.layout-row a';
  13. this.detailsViewElement = '#user-themes #detail-list-view .card-body .row.detail-row a';
  14. this.backgroundImageElement = '#user-themes #background-image-view .card-body .row a';
  15. this.displayModeElement = '#user-themes #theme-switcher-colors .card-body .row a';
  16. this.currentUserTheme = {
  17. LayoutId: 0,
  18. DetailsViewId: 0,
  19. DisplayModeId: 0,
  20. BackgroundImageId: 0,
  21. ThemeId: 0,
  22. IsCompanyTheme: false,
  23. };
  24. }
  25. userTheme(isCompany, companyId, roleId, isRole) {
  26. let instance = this;
  27. var _fileCacheHelper = Unibase.Platform.Helpers.FileCacheHelper.Instance();
  28. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadCssFiles(['platform/layout/components/layoutbuilder/style.layoutbuilder.css'], function () {
  29. if (companyId == undefined || companyId == "" || companyId == null) {
  30. companyId = 0;
  31. }
  32. if (roleId == undefined || roleId == "" || roleId == null) {
  33. roleId = 0;
  34. }
  35. Unibase.Platform.Layouts.Managers.ThemeLayoutManager.Instance().getLayoutBuilderInfo(companyId, roleId).then(function (response) {
  36. $(".biz-wrapper").addClass("biz-settings-toggle");
  37. $(".hk-wrapper").addClass("biz-settings-toggle");
  38. / Plain Html /;
  39. let leftHtml = Unibase.Platform.Layouts.Components.LayoutBuilder_Template.Instance().getLeftHtml();
  40. let onclick = "Unibase.Themes.Compact.Components.UserTheme.Instance().saveUserTheme()";
  41. if (isCompany || isRole) {
  42. onclick = "Unibase.Themes.Compact.Components.UserTheme.Instance().saveCompanyTheme()";
  43. }
  44. let html = `
  45. <div class="user-themes" id="user-themes">
  46. <div class="user-themes-header"></div>
  47. <div class="user-themes-body">
  48. ${leftHtml}
  49. </div>
  50. <div class="user-themes-footer">
  51. <a href="javascript:;" class="btn btn-theme px-4 w-100" type="button" onclick="` + onclick + `">Apply</a>
  52. </div>
  53. </div>`;
  54. $("#settings-panel-body").html(html);
  55. $("#settings-panel-head-title").html("Themes");
  56. let themeSwitchHtml = ` <div class="card theme-switcher">
  57. <div class="card-header">
  58. <a href="javascript:;" class="no-collapse biz-primary-text-color-removed" > Theme Switcher </a>
  59. </div>
  60. <div class="title-devider biz-border-color-removed"> </div>
  61. <div id="theme-switcher-colors">
  62. <div class="card-body pb-0" >
  63. <div class="row dropdown-menu-scrollbar checkbox-container">
  64. </div>
  65. </div>
  66. </div>
  67. </div>`;
  68. $("#user-themes .background-change").before(themeSwitchHtml);
  69. response.result.LayoutInfo.forEach((layout) => {
  70. let curLayout = layout;
  71. let layoutId = curLayout.LayoutId;
  72. curLayout.Thumbnail = curLayout.Thumbnail.replace(".png", ".svg");
  73. $("#user-themes #menu-layouts .layout-row").append(`<a href="javascript:;" class="col-6 p-0 pr-2 p-relative" data-id="${layoutId}" data-index="${curLayout.LayoutIndex}">
  74. <img src="${curLayout.Thumbnail}" class="rounded w-100 h-100" data-dynamic="1" onerror="ReloadImage(event)" title="${curLayout.LayoutName}" />
  75. <i class="zmdi zmdi-check"></i>
  76. </a>`);
  77. });
  78. $(instance.layoutElement).click(function () {
  79. $(instance.layoutElement).removeClass('active');
  80. $(this).addClass('active');
  81. let id = Number($(this).attr('data-id'));
  82. instance.currentUserTheme.LayoutId = id;
  83. });
  84. response.result.DetailViewInfo.forEach((viewLayout) => {
  85. if (viewLayout.DetailsViewName != "Popup") {
  86. let id = viewLayout.DetailsViewId;
  87. $("#user-themes #detail-list-view .detail-row").append(`<a href="javascript:;" class="col-6 p-0 mb-2 pr-2 p-relative" data-id="${id}">
  88. <img src="${viewLayout.Thumbnail}" class="rounded w-100 h-100" data-dynamic="1" onerror="ReloadImage(event)" title="${viewLayout.DetailsViewName}" />
  89. <i class="zmdi zmdi-check"></i>
  90. </a>`);
  91. }
  92. });
  93. $('.isStructSettingsEnableChk').parent().siblings().remove();
  94. $('[for="isStructSettingsEnableChk"]').remove();
  95. $(instance.detailsViewElement).click(function () {
  96. $(instance.detailsViewElement).removeClass('active');
  97. $(this).addClass('active');
  98. let id = Number($(this).attr('data-id'));
  99. instance.currentUserTheme.DetailsViewId = id;
  100. });
  101. response.result.DisplayModesInfo.forEach((displayMode) => {
  102. $("#user-themes #theme-switcher-colors .row").append(`<a href="javascript:;" class="p-relative mr-2 mb-2" data-id="${displayMode.DisplayModeId}" title="${displayMode.DisplayModeName}">
  103. <div class="p-relative color-box border biz-border-color-removed" style="background-color:${displayMode.PrimaryColor}">
  104. </div>
  105. <i class="zmdi zmdi-check"></i>
  106. </a>`);
  107. });
  108. $(instance.displayModeElement).click(function () {
  109. $(instance.displayModeElement).removeClass('active');
  110. $(this).addClass('active');
  111. $(`${instance.backgroundImageElement}.solid-color .color-box`).css("background-color", $(this).find('.color-box').css("background-color"));
  112. $(`${instance.backgroundImageElement}.solid-color color-box`).addClass('active');
  113. let id = Number($(this).attr('data-id'));
  114. instance.currentUserTheme.DisplayModeId = id;
  115. });
  116. let solidColorImage = `<a href="javascript:;" class="col-4 p-relative px-1 solid-color active" data-id="0">
  117. <div class="p-relative color-box border biz-border-color-removed" style="height:65px">
  118. </div>
  119. <i class="zmdi zmdi-check"></i>
  120. </a>`;
  121. $("#user-themes #background-image-view .row").append(solidColorImage);
  122. response.result.BackgroundImages.forEach((backgroundImage) => {
  123. let IsDefaultClass = backgroundImage.IsDefault ? 'default' : '';
  124. $("#user-themes #background-image-view .row").append(`<a href="javascript:;" class="col-4 p-relative px-1 ${IsDefaultClass}" data-url="${backgroundImage.Thumbnail}" data-id="${backgroundImage.BackgroundImageId}">
  125. <div class="p-relative">
  126. <img src="${backgroundImage.Thumbnail}" class="rounded w-100" data-dynamic="1" onerror = "ReloadImage(event)" />
  127. <div class="delete" data-id="${backgroundImage.BackgroundImageId}">
  128. <i class="fa fa-trash"></i>
  129. </div>
  130. </div>
  131. <i class="zmdi zmdi-check"></i>
  132. </a>`);
  133. });
  134. $(instance.backgroundImageElement).click(function () {
  135. $(instance.backgroundImageElement).removeClass('active');
  136. $(this).addClass('active');
  137. instance.currentUserTheme.BackgroundImageId = Number($(this).attr('data-id'));
  138. });
  139. let currentTheme = Unibase.Themes.Compact.Components.Index.Instance().currentTheme;
  140. if (isCompany || isRole) {
  141. currentTheme = response.result.CompanyTheme;
  142. if (currentTheme === '') {
  143. instance.currentUserTheme.LayoutId = 0;
  144. instance.currentUserTheme.DetailsViewId = 0;
  145. instance.currentUserTheme.DisplayModeId = 0;
  146. instance.currentUserTheme.BackgroundImageId = 0;
  147. instance.currentUserTheme.ThemeId = 0;
  148. }
  149. if (isRole && $(".hdn_themeid").length === 0) {
  150. $('._bizgaze_popup_container').last().find('.section_Hidden').append(`<input type="hidden" class="hdn_themeid" value="0"><input type="hidden" class="hdn_displaymodeid" value="0">`);
  151. }
  152. if (currentTheme === '' && $(".hdn_themeid").val() != "0") {
  153. instance.bindSelectedUserThemeSettings();
  154. return;
  155. }
  156. }
  157. $(`${instance.layoutElement}[data-id="${currentTheme.layoutId}"]`).click();
  158. $(`${instance.detailsViewElement}[data-id="${currentTheme.detailsViewId}"]`).click();
  159. $(`${instance.displayModeElement}[data-id="${currentTheme.displayModeId}"]`).click();
  160. $(`${instance.backgroundImageElement}[data-id="${currentTheme.backgroundImageId}"]`).click();
  161. instance.currentUserTheme.ThemeId = currentTheme.themeId;
  162. instance.currentUserTheme.IsCompanyTheme = currentTheme.isCompanyTheme;
  163. });
  164. });
  165. }
  166. bindSelectedUserThemeSettings() {
  167. const instance = this;
  168. const currentTheme = JSON.parse($(".hdn_themeid").val().toString());
  169. const { LayoutId, DetailsViewId, DisplayModeId, BackgroundImageId } = currentTheme;
  170. $(`${instance.layoutElement}[data-id="${LayoutId}"]`).trigger('click');
  171. $(`${instance.detailsViewElement}[data-id="${DetailsViewId}"]`).trigger('click');
  172. $(`${instance.displayModeElement}[data-id="${DisplayModeId}"]`).trigger('click');
  173. $(`${instance.backgroundImageElement}[data-id="${BackgroundImageId}"]`).trigger('click');
  174. }
  175. init(isCompany, companyId) {
  176. let instance = this;
  177. var _fileCacheHelper = Unibase.Platform.Helpers.FileCacheHelper.Instance();
  178. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadCssFiles(['platform/layout/components/layoutbuilder/style.layoutbuilder.css'], function () {
  179. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFiles(['platform/core/infos/status.js', 'platform/layout/managers/themelayoutmanager.js'], function () {
  180. if (companyId == undefined || companyId == "" || companyId == null) {
  181. companyId = 0;
  182. }
  183. Unibase.Platform.Layouts.Managers.ThemeLayoutManager.Instance().getLayoutBuilderInfo(companyId, 0).then(function (response) {
  184. $(".biz-wrapper").addClass("biz-settings-toggle");
  185. $(".hk-wrapper").addClass("biz-settings-toggle");
  186. let leftHtml = Unibase.Platform.Layouts.Components.LayoutBuilder_Template.Instance().getLeftHtml();
  187. let onclick = "Unibase.Themes.Compact.Components.UserTheme.Instance().saveUserTheme()";
  188. if (isCompany) {
  189. onclick = "Unibase.Themes.Compact.Components.UserTheme.Instance().saveCompanyTheme()";
  190. }
  191. let html = `<div class="user-themes" id="user-themes">
  192. <div class="user-themes-header"></div>
  193. <div class="user-themes-body">
  194. ${leftHtml}
  195. </div>
  196. <div class="user-themes-footer">
  197. <a href="javascript:;" class="btn btn-theme px-4 w-100" type="button" onclick="` + onclick + `">Apply</a>
  198. </div>
  199. </div>`;
  200. $("#settings-panel-body").html(html);
  201. $("#settings-panel-head-title").html("Themes");
  202. let themeSwitchHtml = `<div class="card theme-switcher">
  203. <div class="card-header">
  204. <a href="javascript:;" class="no-collapse biz-primary-text-color-removed" > Theme Switcher </a>
  205. </div>
  206. <div class="title-devider biz-border-color-removed"> </div>
  207. <div id="theme-switcher-colors">
  208. <div class="card-body pb-0" >
  209. <div class="row dropdown-menu-scrollbar checkbox-container">
  210. </div>
  211. </div>
  212. </div>
  213. </div>`;
  214. $("#user-themes .background-change").before(themeSwitchHtml);
  215. response.result.LayoutInfo.forEach((layout) => {
  216. let curLayout = layout;
  217. let layoutId = curLayout.LayoutId;
  218. curLayout.Thumbnail = curLayout.Thumbnail.replace(".png", ".svg");
  219. $("#user-themes #menu-layouts .layout-row").append(`<a href="javascript:;" class="col-6 p-0 pr-2 p-relative" data-id="${layoutId}" data-index="${curLayout.LayoutIndex}">
  220. <img src="${curLayout.Thumbnail}" class="rounded w-100 h-100" data-dynamic="1" onerror="ReloadImage(event)" title="${curLayout.LayoutName}" />
  221. <i class="zmdi zmdi-check"></i>
  222. </a>`);
  223. });
  224. $(instance.layoutElement).click(function () {
  225. $(instance.layoutElement).removeClass('active');
  226. $(this).addClass('active');
  227. let id = Number($(this).attr('data-id'));
  228. instance.currentUserTheme.LayoutId = id;
  229. });
  230. response.result.DetailViewInfo.forEach((viewLayout) => {
  231. if (viewLayout.DetailsViewName != "Popup") {
  232. let id = viewLayout.DetailsViewId;
  233. $("#user-themes #detail-list-view .detail-row").append(`<a href="javascript:;" class="col-6 p-0 mb-2 pr-2 p-relative" data-id="${id}">
  234. <img src="${viewLayout.Thumbnail}" class="rounded w-100 h-100" data-dynamic="1" onerror="ReloadImage(event)" title="${viewLayout.DetailsViewName}" />
  235. <i class="zmdi zmdi-check"></i>
  236. </a>`);
  237. }
  238. });
  239. $(instance.detailsViewElement).click(function () {
  240. $(instance.detailsViewElement).removeClass('active');
  241. $(this).addClass('active');
  242. let id = Number($(this).attr('data-id'));
  243. instance.currentUserTheme.DetailsViewId = id;
  244. });
  245. response.result.DisplayModesInfo.forEach((displayMode) => {
  246. $("#user-themes #theme-switcher-colors .row").append(`<a href="javascript:;" class="p-relative mr-2 mb-2" data-id="${displayMode.DisplayModeId}" title="${displayMode.DisplayModeName}">
  247. <div class="p-relative color-box border biz-border-color-removed" style="background-color:${displayMode.PrimaryColor}">
  248. </div>
  249. <i class="zmdi zmdi-check"></i>
  250. </a>`);
  251. });
  252. $(instance.displayModeElement).click(function () {
  253. $(instance.displayModeElement).removeClass('active');
  254. $(this).addClass('active');
  255. $(`${instance.backgroundImageElement}.solid-color .color-box`).css("background-color", $(this).find('.color-box').css("background-color"));
  256. $(`${instance.backgroundImageElement}.solid-color color-box`).addClass('active');
  257. let id = Number($(this).attr('data-id'));
  258. instance.currentUserTheme.DisplayModeId = id;
  259. });
  260. let solidColorImage = `<a href="javascript:;" class="col-4 p-relative px-1 solid-color active" data-id="0">
  261. <div class="p-relative color-box border biz-border-color-removed" style="height:65px">
  262. </div>
  263. <i class="zmdi zmdi-check"></i>
  264. </a>`;
  265. $("#user-themes #background-image-view .row").append(solidColorImage);
  266. response.result.BackgroundImages.forEach((backgroundImage) => {
  267. let IsDefaultClass = backgroundImage.IsDefault ? 'default' : '';
  268. $("#user-themes #background-image-view .row").append(`<a href="javascript:;" class="col-4 p-relative px-1 ${IsDefaultClass}" data-url="${backgroundImage.Thumbnail}" data-id="${backgroundImage.BackgroundImageId}">
  269. <div class="p-relative">
  270. <img src="${backgroundImage.Thumbnail}" class="rounded w-100" data-dynamic="1" onerror = "ReloadImage(event)" />
  271. <div class="delete" data-id="${backgroundImage.BackgroundImageId}">
  272. <i class="fa fa-trash"></i>
  273. </div>
  274. </div>
  275. <i class="zmdi zmdi-check"></i>
  276. </a>`);
  277. });
  278. $(instance.backgroundImageElement).click(function () {
  279. $(instance.backgroundImageElement).removeClass('active');
  280. $(this).addClass('active');
  281. instance.currentUserTheme.BackgroundImageId = Number($(this).attr('data-id'));
  282. });
  283. let currentTheme = Unibase.Themes.Compact.Components.Index.Instance().currentTheme;
  284. if (isCompany) {
  285. currentTheme = response.result.CompanyTheme;
  286. }
  287. $(`${instance.layoutElement}[data-id="${currentTheme.layoutId}"]`).click();
  288. $(`${instance.detailsViewElement}[data-id="${currentTheme.detailsViewId}"]`).click();
  289. $(`${instance.displayModeElement}[data-id="${currentTheme.displayModeId}"]`).click();
  290. $(`${instance.backgroundImageElement}[data-id="${currentTheme.backgroundImageId}"]`).click();
  291. instance.currentUserTheme.ThemeId = currentTheme.themeId;
  292. instance.currentUserTheme.IsCompanyTheme = currentTheme.isCompanyTheme;
  293. });
  294. });
  295. });
  296. }
  297. saveCompanyTheme() {
  298. let instance = this;
  299. let postData = {
  300. LayoutId: instance.currentUserTheme.LayoutId,
  301. ThemeId: instance.currentUserTheme.ThemeId || 0,
  302. DetailsViewId: instance.currentUserTheme.DetailsViewId,
  303. DisplayModeId: instance.currentUserTheme.DisplayModeId,
  304. BackgroundImageId: instance.currentUserTheme.BackgroundImageId
  305. };
  306. const placeholder = $('._bizgaze_popup_container').last().find('.form-error-message').first().attr('id');
  307. if (!postData.LayoutId && !postData.DetailsViewId && !postData.DisplayModeId) {
  308. MessageHelper.Instance().showError('Select Theme.', placeholder);
  309. return;
  310. }
  311. if (!postData.LayoutId) {
  312. MessageHelper.Instance().showError('Select Preferred Layout in Theme.', placeholder);
  313. return;
  314. }
  315. else if (!postData.DetailsViewId) {
  316. MessageHelper.Instance().showError('Select Preferred Details View in Theme.', placeholder);
  317. return;
  318. }
  319. else if (!postData.DisplayModeId) {
  320. MessageHelper.Instance().showError('Select Theme Switcher.', placeholder);
  321. return;
  322. }
  323. $(".hdn_themeid").val(JSON.stringify(postData));
  324. $(".hdn_displaymodeid").val(instance.currentUserTheme.DisplayModeId);
  325. $(".biz-wrapper,.hk-wrapper").removeClass("biz-settings-toggle");
  326. }
  327. saveUserTheme() {
  328. let instance = this;
  329. let postData = {
  330. LayoutId: instance.currentUserTheme.LayoutId,
  331. ThemeId: instance.currentUserTheme.IsCompanyTheme ? 0 : instance.currentUserTheme.ThemeId,
  332. DetailsViewId: instance.currentUserTheme.DetailsViewId,
  333. DisplayModeId: instance.currentUserTheme.DisplayModeId,
  334. BackgroundImageId: instance.currentUserTheme.BackgroundImageId
  335. };
  336. Unibase.Platform.Layouts.Managers.ThemeLayoutManager.Instance().saveUserTheme(postData).then(function (response) {
  337. if (response.status == Unibase.Data.Status.Success) {
  338. MessageHelper.Instance().showSuccess(response.message, '');
  339. Unibase.Platform.Layouts.Components.LayoutBuilder.Instance().refrshLayout(response);
  340. }
  341. });
  342. }
  343. static Instance() {
  344. if (this.instance === undefined) {
  345. this.instance = new UserTheme();
  346. }
  347. return this.instance;
  348. }
  349. }
  350. Components.UserTheme = UserTheme;
  351. })(Components = Compact.Components || (Compact.Components = {}));
  352. })(Compact = Themes.Compact || (Themes.Compact = {}));
  353. })(Themes = Unibase.Themes || (Unibase.Themes = {}));
  354. })(Unibase || (Unibase = {}));