iwb.js 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356
  1. if (typeof jQuery === "undefined") {
  2. throw new Error("jQuery plugins need to be before this file");
  3. }
  4. var log = true, abp = abp || {};
  5. /*JQuery扩展*/
  6. $.extend({
  7. //表单赋值
  8. formDeserialize: function ($form, data) {
  9. //isSelect2 = isSelect2 === undefined;
  10. if (!data) {
  11. return;
  12. }
  13. var $input = $form.find("input");
  14. var $textarea = $form.find("textarea");
  15. var $select = $form.find("select");
  16. var $checkbox = $form.find("input[type='checkbox']");
  17. var $radio = $form.find("input[type='radio']");
  18. $.merge($input, $textarea);
  19. $input.each(function () {
  20. var $input = $form.find($(this));
  21. var name = $input.attr("name");
  22. if (data[name] !== "") {
  23. $input.val(data[name]);
  24. }
  25. });
  26. $select.each(function () {
  27. var $select = $form.find($(this));
  28. var name = $select.attr("name");
  29. if (typeof data[name] === "boolean") {
  30. data[name] = data[name] + "";
  31. }
  32. if (data[name] !== "") {
  33. $select.val(data[name]);
  34. //if (isSelect2) {
  35. // $select.val(data[name]).select2();
  36. //} else {
  37. //}
  38. }
  39. });
  40. $checkbox.each(function () {
  41. var input = $form.find($(this));
  42. //var name = input.attr("name").replace(/(\w)/, function (v) { return v.toUpperCase() });
  43. var name = input.attr("name");
  44. if (data[name] !== "") {
  45. //console.log(array[name]);
  46. //console.log("---");
  47. input.val(data[name] === "True" ||
  48. input.val(data[name]) === "1" ||
  49. input.val(data[name]) === "true");
  50. }
  51. });
  52. $radio.each(function () {
  53. var input = $form.find($(this));
  54. //var name = input.attr("name").replace(/(\w)/, function (v) { return v.toUpperCase() });
  55. var name = input.attr("name");
  56. if (data[name] !== "") {
  57. //console.log(array[name]);
  58. $("input[name='" + name + "'][value='" + data[name] + "']").prop("checked", true);
  59. $("input[name='" + name + "'][value!='" + data[name] + "']").prop("checked", false);
  60. }
  61. });
  62. },
  63. //将form表单元素的值序列化成对象
  64. formSerialize: function ($form) {
  65. var disableEle = $form.find("[disabled]");
  66. disableEle.each(function (i, e) {
  67. $(e).prop("disabled", false);
  68. });
  69. var data = {};
  70. $.each($form.serializeArray(),
  71. function () {
  72. if (data[this['name']]) {
  73. data[this['name']] = data[this['name']] + "," + this['value'];
  74. } else {
  75. data[this['name']] = this['value'];
  76. }
  77. });
  78. disableEle.each(function (i, e) {
  79. $(e).prop("disabled", true);
  80. });
  81. return data;
  82. },
  83. //表单验证
  84. formValidate: function ($form, opt) {
  85. var defaults = {
  86. noValid: false,
  87. form: "form",
  88. modal: "modal",
  89. errorPlacement: function (error, element) {
  90. element.parent().before(error);
  91. element.focus();
  92. },
  93. rules: {}
  94. };
  95. opt = opt || {};
  96. var options = $.extend({}, defaults, opt);
  97. var $modal = options.modal
  98. ? typeof (options.modal) === 'string'
  99. ? $('#' + options.modal)
  100. : $(options.modal)
  101. : null;
  102. $form = $form ? $form : options.form ? $(options.form) : $modal.find('form');
  103. $form.validate({
  104. errorPlacement: options.errorPlacement,
  105. rules: options.rules
  106. }).settings.ignore = ":disabled";
  107. if (!options.noValid) {
  108. return $form.valid();
  109. }
  110. return options.noValid;
  111. },
  112. formatterDate: function (fmt, date, isFix) {
  113. date = date || new Date();
  114. isFix = isFix === undefined ? true : isFix;
  115. var year = date.getFullYear();
  116. var month = date.getMonth() + 1;
  117. fmt = fmt.replace("yyyy", year);
  118. fmt = fmt.replace("yy", year % 100);
  119. fmt = fmt.replace("MM", fix(month));
  120. fmt = fmt.replace("dd", fix(date.getDate()));
  121. fmt = fmt.replace("HH", fix(date.getHours()));
  122. fmt = fmt.replace("mm", fix(date.getMinutes()));
  123. fmt = fmt.replace("ss", fix(date.getSeconds()));
  124. return fmt;
  125. function fix(n) {
  126. return isFix ? (n < 10 ? "0" + n : n) : n;
  127. }
  128. },
  129. blinkTitle:{
  130. start: function (msg) {
  131. msg = msg || abp.localization.iwbZero('NewNotificationRemind');
  132. this.title = document.title;
  133. this.messages = [msg];
  134. if (!this.action) {
  135. try {
  136. this.element = document.getElementsByTagName('title')[0];
  137. this.element.innerHTML = this.title;
  138. this.action = function (ttl) {
  139. this.element.innerHTML = ttl;
  140. };
  141. } catch (e) {
  142. this.action = function(ttl) {
  143. document.title = ttl;
  144. };
  145. delete this.element;
  146. }
  147. this.toggleTitle = function () {
  148. this.index = this.index === 0 ? 1 : 0;
  149. this.action('【' + this.messages[this.index] + '】'+this.title);
  150. };
  151. }
  152. var n = msg.length;
  153. var s = '';
  154. if (this.element) {
  155. var num = msg.match(/\w/g);
  156. if (num) {
  157. var n2 = num.length;
  158. n -= n2;
  159. while (n2 > 0) {
  160. s += " ";
  161. n2--;
  162. }
  163. }
  164. }
  165. while (n > 0) {
  166. s += ' ';
  167. n--;
  168. }
  169. this.messages.push(s);
  170. this.index = 0;
  171. //this.title = this.title.replace("【" + msg + "】", "").replace("【" + s + "】", "");
  172. var that = this;
  173. this.timer = setInterval(function () {
  174. that.toggleTitle();
  175. }, 500);
  176. },
  177. stop: function () {
  178. if (this.timer) {
  179. clearInterval(this.timer);
  180. var t = this.title ? this.title : document.title;
  181. this.action(t);
  182. delete this.timer;
  183. delete this.messages;
  184. }
  185. }
  186. } ,
  187. metPageCss: function (url, id) {
  188. id = id || 'dy-css';
  189. if ($('#' + id).length > 0) {
  190. return;
  191. }
  192. var link = document.createElement('link');
  193. link.type = 'text/css';
  194. link.rel = 'stylesheet';
  195. link.id = id;
  196. link.href = url + '?v=' + Math.floor(Math.random() * 100000);
  197. var flag = document.getElementById('flag');
  198. var head = document.getElementsByTagName('head')[0];
  199. if (flag) {
  200. head.insertBefore(link, flag.nextSibling);
  201. } else {
  202. head.appendChild(link);
  203. }
  204. },
  205. metPageJs: function (src, id) {
  206. id = id || 'dy-js';
  207. if ($('#' + id).length > 0) {
  208. return;
  209. }
  210. var script = document.createElement('script');
  211. script.id = id;
  212. script.type = 'text/javascript';
  213. script.charset = 'UTF-8';
  214. script.src = src + '?v=' + Math.floor(Math.random() * 100000);
  215. $('head').append(script);
  216. },
  217. loadScript: function(url, loadCallback, failCallback) {
  218. /* UrlStates enum */
  219. var urlStates = {
  220. LOADING: 'LOADING',
  221. LOADED: 'LOADED',
  222. FAILED: 'FAILED'
  223. };
  224. /* UrlInfo class */
  225. function UrlInfo() {
  226. this.state = urlStates.LOADING;
  227. this.loadCallbacks = [];
  228. this.failCallbacks = [];
  229. }
  230. UrlInfo.prototype.succeed = function () {
  231. this.state = urlStates.LOADED;
  232. for (var i = 0; i < this.loadCallbacks.length; i++) {
  233. this.loadCallbacks[i]();
  234. }
  235. };
  236. UrlInfo.prototype.failed = function () {
  237. this.state = urlStates.FAILED;
  238. for (var i = 0; i < this.failCallbacks.length; i++) {
  239. this.failCallbacks[i]();
  240. }
  241. };
  242. UrlInfo.prototype.handleCallbacks = function (loadCallback, failCallback) {
  243. switch (this.state) {
  244. case urlStates.LOADED:
  245. loadCallback && loadCallback();
  246. break;
  247. case urlStates.FAILED:
  248. failCallback && failCallback();
  249. break;
  250. case urlStates.LOADING:
  251. this.addCallbacks(loadCallback, failCallback);
  252. break;
  253. }
  254. };
  255. UrlInfo.prototype.addCallbacks = function (loadCallback, failCallback) {
  256. loadCallback && this.loadCallbacks.push(loadCallback);
  257. failCallback && this.failCallbacks.push(failCallback);
  258. };
  259. var urlInfos = {};
  260. var loadScript = function (url, loadCallback, failCallback) {
  261. var urlInfo = urlInfos[url];
  262. if (urlInfo) {
  263. urlInfo.handleCallbacks(loadCallback, failCallback);
  264. return;
  265. }
  266. urlInfos[url] = urlInfo = new UrlInfo();
  267. urlInfo.addCallbacks(loadCallback, failCallback);
  268. $.getScript(url).done(function (script, textStatus) {
  269. urlInfo.succeed();
  270. }).fail(function (jqxhr, settings, exception) {
  271. urlInfo.failed();
  272. });
  273. };
  274. loadScript(url, loadCallback, failCallback);
  275. }
  276. });
  277. /*AJAX*/
  278. $.extend({
  279. //ajax
  280. iwbAjax: function (url, opt) {
  281. this.defaults = {
  282. async: true,
  283. type: "Post",
  284. contentType: 'application/json; charset=UTF-8',
  285. //contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
  286. data: null,
  287. log: window.log,
  288. dataType: "json",
  289. isAlert: true,
  290. isValidate: true,
  291. isRefresh: true,//默认刷新表格
  292. success: null,
  293. error: null,
  294. table: undefined,
  295. modal: undefined,
  296. form: undefined,
  297. errorPlacement: function (error, element) {
  298. element.parent().before(error);
  299. element.focus();
  300. },
  301. rules: {},
  302. blockUI: true
  303. };
  304. if (!opt) {
  305. opt = url;
  306. url = opt.url;
  307. }
  308. var options = $.extend({}, this.defaults, opt);
  309. var $table = !options.table ? undefined : typeof options.table === 'string' ? $('#' + options.table) : $(options.table);
  310. var $modal = !options.modal ? undefined : typeof options.modal === 'string' ? $('#' + options.modal) : $(options.modal);
  311. var $form = !options.form ? ($modal? $modal.find("form"):undefined ): typeof options.form === 'string' ? $('#' + options.form) : $(options.form);
  312. var isValidated = true;
  313. if (options.isValidate && $form) {
  314. isValidated = $.formValidate($form);
  315. }
  316. console.error($form, isValidated)
  317. if (isValidated) {
  318. options.data = options.data ? (typeof options.data === 'function' ? options.data() : options.data) : $form ? $.formSerialize($form) : undefined;
  319. var guid = Math.floor(Math.random() * 10000);
  320. var log = options.log;
  321. if (log) {
  322. console.log('[' + guid + ']url:' + url, 'data:', options.data);
  323. }
  324. var success = options.success && typeof options.success === 'function'
  325. ? function (res) {
  326. if (log) { console.log('[' + guid + ']', res); }
  327. options.success(res);
  328. if (options.isRefresh && $table) {
  329. $table.iwbTable('refresh', true);
  330. }
  331. if ($modal) {
  332. $modal.iwbModal('hide');
  333. }
  334. }
  335. : function (res) {
  336. if (log) { console.log('[' + guid + ']', res); }
  337. if (options.isRefresh && $table) {
  338. $table.iwbTable('refresh', true);
  339. }
  340. if ($modal) {
  341. $modal.iwbModal('hide');
  342. }
  343. };
  344. var ajaxSuccess = options.isAlert ? function (res) { abp.message.success(abp.localization.iwbZero('OpSuccess')).done(success(res)); } : success;
  345. var data = typeof (options.data) === 'string' ? options.data : JSON.stringify(options.data);
  346. var ajaxOption = {
  347. url: url,
  348. async: options.async,
  349. type: options.type,
  350. contentType: options.contentType,
  351. data: data,
  352. dataType: options.dataType,
  353. success: ajaxSuccess,
  354. error: options.error,
  355. abpHandleError: options.isAlert,
  356. blockUI: options.blockUI
  357. };
  358. abp.ajax(ajaxOption);
  359. }
  360. }
  361. });
  362. $.extend({
  363. iwbAjax1: function (opt) {
  364. opt = $.extend({}, { isValidate: false }, opt);
  365. $.iwbAjax(opt);
  366. },
  367. iwbAjax2: function (opt) {
  368. opt = $.extend({}, { isAlert: false }, opt);
  369. $.iwbAjax(opt);
  370. },
  371. iwbAjax3: function (opt) {
  372. opt = $.extend({}, { isValidate: false, isAlert: false ,blockUI:false}, opt);
  373. $.iwbAjax(opt);
  374. },
  375. iwbAjax4: function (opt) {
  376. opt = $.extend({}, { isValidate: false, isAlert: false, isRefresh: false ,blockUI:false}, opt);
  377. $.iwbAjax(opt);
  378. },
  379. iwbGet: function (opt) {
  380. opt = $.extend({}, { type: 'get', modal: null, form: null }, opt);
  381. $.iwbAjax4(opt);
  382. }
  383. });
  384. /*Table*/
  385. (function ($, window, document, undefined) {
  386. //构造函数
  387. 'use strict';
  388. var abp = window.abp || {},
  389. searchList = [],
  390. isSearching,
  391. modalDefaults = {
  392. modal: 'modal',
  393. modaltitle: '',
  394. data: null,
  395. form: null,
  396. errorPlacement: function (error, element) {
  397. if (element.is('select')) {
  398. if (!element.next().next().hasClass('error')) {
  399. element.next().after(error);
  400. element.focus();
  401. }
  402. } else {
  403. element.after(error);
  404. element.focus();
  405. }
  406. },
  407. rules: {},
  408. readonly: '',
  409. disabled: '',
  410. select2: true,
  411. select2tree: false,
  412. url: '',
  413. savebtn: null,
  414. save: null,
  415. success: null,
  416. shownBefore: null,
  417. shownAfter: null,
  418. draggable: false,
  419. searchValidate: true
  420. };
  421. //modalOptions = {};
  422. var getSearchList = function ($that) {
  423. var o = $that.options;
  424. var $searchForm = (typeof (o.searchForm) === 'string' ? $('#' + o.searchForm) : $(o.searchForm));
  425. searchList = [];
  426. if (o.searchList && o.searchList.length > 0) {
  427. o.searchList.forEach(function (v) {
  428. if (v.KeyWords) {
  429. searchList.push(v);
  430. }
  431. });
  432. }
  433. if (!o.onlySearchList) {
  434. $searchForm.find('.KeyWords').each(function () {
  435. var $this = $(this), keyWords = $this.val();
  436. if (keyWords) {
  437. if ($this.hasClass('dataRange')) {
  438. try {
  439. var dates = keyWords.split(' - ');
  440. searchList.push({
  441. KeyWords: dates[0],
  442. KeyField: $this.data('field'),
  443. FieldType: $this.data('ftype'),
  444. ExpType: 4
  445. });
  446. if (dates.length===2) {
  447. var dateArr = dates[1].split(' ')[0].split('-');
  448. var date = new Date(dateArr[0], dateArr[1] - 1, dateArr[2], 0, 0, 0);
  449. var newDate = new Date(date.getTime() + 24 * 60 * 60 * 1000 - 1);
  450. keyWords = $.formatterDate('yyyy-MM-dd HH:mm:ss', newDate);
  451. searchList.push({ KeyWords: keyWords, KeyField: $this.data('field'), FieldType: $this.data('ftype'), ExpType: 5 });
  452. }
  453. } catch (e) {
  454. console.log(e);
  455. }
  456. } else {
  457. searchList.push({ KeyWords: keyWords, KeyField: $this.data('field'), FieldType: $this.data('ftype'), ExpType: $this.data('etype') });
  458. }
  459. }
  460. });
  461. }
  462. },
  463. queryParams = function (params, $that) {
  464. var o = $that.options;
  465. getSearchList($that);
  466. var $searchForm = (typeof (o.searchForm) === 'string' ? $('#' + o.searchForm) : $(o.searchForm));
  467. var $keyWord = $searchForm.find('#keyWords');
  468. if (o.onlySearchList) {
  469. return {
  470. MaxResultCount: params.limit,
  471. SkipCount: params.offset,
  472. //sort: params.sort, //排序列名
  473. //sortOrder: params.order, //排位命令(desc,asc)
  474. sorting: params.sort?params.sort+' '+params.order:'',
  475. SearchList: searchList
  476. };
  477. }
  478. return {
  479. MaxResultCount: params.limit,
  480. SkipCount: params.offset,
  481. sorting: params.sort?params.sort+' '+params.order:'',
  482. keyField: $keyWord.data('field'),
  483. fieldType: $keyWord.data('ftype'),
  484. expType: $keyWord.data('etype'),
  485. keyWords: $keyWord.val(),
  486. SearchList: searchList
  487. };
  488. },
  489. responseHandler = function (res) {
  490. if (res.success) {
  491. var data = JSON.parse('{"total":' +
  492. res.result.totalCount +
  493. ',"rows":' +
  494. JSON.stringify(res.result.items) +
  495. '}');
  496. console.log(data);
  497. return data;
  498. } else {
  499. console.log('Table load failed');
  500. if (res.error) {
  501. if (res.error.details) {
  502. return abp.message.error(res.error.details, res.error.message);
  503. } else {
  504. if (res.error.message && res.error.message.indexOf('登陆超时') >= 0) {
  505. return abp.message.error(res.error.message).done(function () {
  506. window.top.location.reload();
  507. });
  508. } else {
  509. return abp.message.error(res.error.message || abp.ajax.defaultError.message);
  510. }
  511. }
  512. }
  513. }
  514. return JSON.parse('{"total":0,"rows":[]}');
  515. },
  516. responseHandlerNoPage = function (res) {
  517. if (res.success) {
  518. var data = res.result;
  519. console.log(data);
  520. return data;
  521. } else {
  522. console.log('Table load failed');
  523. if (res.error) {
  524. if (res.error.details) {
  525. return abp.message.error(res.error.details, res.error.message);
  526. } else {
  527. if (res.error.message && res.error.message.indexOf('登陆超时') >= 0) {
  528. return abp.message.error(res.error.message).done(function () {
  529. window.top.location.reload();
  530. });
  531. } else {
  532. return abp.message.error(res.error.message || abp.ajax.defaultError.message);
  533. }
  534. }
  535. }
  536. }
  537. return JSON.parse('[]');
  538. },
  539. onAll = function (eName, eData, $that) {
  540. isSearching = false;
  541. var o = $that.options;
  542. var $table = (typeof (o.table) === 'string' ? $('#' + o.table) : $(o.table));
  543. $table.closest('.table-box').find('.tableTool .menu-btn[data-type^=\'btn\']')
  544. .prop('disabled', $table.bootstrapTable('getSelections').length !== 1);
  545. },
  546. onLoadSuccess = function (data, $that) {
  547. var o = $that.options;
  548. var $table = (typeof (o.table) === 'string' ? $('#' + o.table) : $(o.table));
  549. // $table.find('.bs-checkbox').find('input').addClass('filled-in').after('<label></label');
  550. },
  551. onPostBody = function (data, $that) {
  552. var o = $that.options;
  553. $(document);
  554. var $table = (typeof (o.table) === 'string' ? $('#' + o.table) : $(o.table));
  555. /* $table.find("td.bs-checkbox").each(function () {
  556. var input = $(this).find('input');
  557. var $label = $('<span class="iwb-checkbox"></span>');
  558. $label.append(input);
  559. $label.append('<span></span>');
  560. $(this).html($label);
  561. });*/
  562. $table.find(".bs-checkbox").find("input").addClass("filled-in").after("<label></label");
  563. $table.find("thead th.bs-checkbox").off("click.checkOnTable").on(
  564. "click.checkOnTable",
  565. function () {
  566. $(this).find("input").click();
  567. });
  568. isSearching = false;
  569. var $tableTool = o.tableTool
  570. ? typeof (o.tableTool) === 'string'
  571. ? $table.closest('.table-box').find('#' + o.tableTool)
  572. : $table.closest('.table-box').find(o.tableTool)
  573. : $table.closest('.table-box').find('.btn-toolbar');
  574. $tableTool.find('.menu-btn').off('click.menubtn').on('click.menubtn', function () {
  575. var funs = $that.getFuns();
  576. var type = $(this).data('type');
  577. var index = type.lastIndexOf('_');
  578. type = index > -1 ? type.substr(index + 1) : type;
  579. var url = $(this).data('url') || "";
  580. funs[type] ? funs[type].call(this, url) : funs["none"].call(this);
  581. });
  582. abp.ui.clearBusy();
  583. $table.find('tr th').each(function () { $(this).css('text-align', 'center') });
  584. $table.find('tr td.iwb-tips').each(function () {
  585. var text= $(this).text();
  586. $(this).tooltip({ 'title': text,'placement': 'bottom', 'container': 'body','delay':800 });
  587. });
  588. },
  589. getModal = function (url, opt, title, type, $that) {
  590. var o = $that.options;
  591. var modalOptions = $.extend({}, modalDefaults, opt);
  592. var $table = typeof o.table === 'string' ? $('#' + o.table) : $(o.table);
  593. var $tableTool = o.tableTool
  594. ? typeof o.tableTool === 'string'
  595. ? $table.closest('.table-box').find('#' + o.tableTool)
  596. : $table.closest('.table-box').find(o.tableTool)
  597. : $table.closest('.table-box').find('.btn-toolbar');
  598. modalOptions.modaltitle = title;
  599. modalOptions.draggable = $that.options.modalDrag;
  600. if (!opt) {
  601. opt = !url || typeof url === "string" ? {} : url;
  602. }
  603. if (opt.hasOwnProperty("url")) {
  604. modalOptions.url = opt.url;
  605. } else if (typeof url === "string") {
  606. modalOptions.url = url;
  607. } else {
  608. modalOptions.url = $tableTool.find('.menu-btn[data-type=' + type + ']').data('url');
  609. modalOptions.url = modalOptions.url
  610. ? modalOptions.url
  611. : $tableTool.find('.menu-btn[data-type=_' + type + ']').data('url');
  612. }
  613. modalOptions.modal = typeof $that.options.modal === 'string' ? $("#" + $that.options.modal) : $($that.options.modal);
  614. modalOptions.table = $table;
  615. //modalOptions.type = type.toLowerCase().indexOf('btnupdate') === 0 ? 'put' : 'post';
  616. modalOptions.type = 'post';
  617. return modalOptions;
  618. };
  619. var Table = function (ele, opt) {
  620. var $that = this;
  621. this.defaults = {
  622. url: undefined,
  623. table: undefined,
  624. tableTool: '',
  625. resetView: true,
  626. height: undefined,
  627. searchForm: 'search-form',
  628. searchList: [],
  629. onlySearchList: false,
  630. searchValidate: true,
  631. queryParams: function (p) { return queryParams(p, $that); },
  632. onAll: function (e, d) { onAll(e, d, $that); },
  633. onLoadSuccess: function (d) { onLoadSuccess(d, $that); },
  634. onPostBody: function (d) { onPostBody(d, $that); },
  635. isPage: true,
  636. lang: 'zh-CN',
  637. funs: undefined,
  638. modal: 'modal',
  639. form: 'form',
  640. modalDrag: true
  641. };
  642. $that.options = $.extend({}, this.defaults, opt || {});
  643. if (!$that.options.onAll) {
  644. $that.options.onAll = function (e, d) {
  645. onAll(e, d, $that);
  646. };
  647. }
  648. this.$ele = ele,
  649. this.loadTable();
  650. return this;
  651. };
  652. Table.prototype.loadTable = function () {
  653. var $that = this;
  654. $that.options.responseHandler = $that.options.responseHandler
  655. ? $that.options.responseHandler
  656. : $that.options.isPage
  657. ? responseHandler
  658. : responseHandlerNoPage;
  659. $.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales[$that.options.lang]);
  660. var o = $that.options;
  661. //searchList = o.searchList;
  662. getSearchList($that);
  663. var $table = (typeof (o.table) === 'string' ? $('#' + o.table) : $(o.table));
  664. $table.bootstrapTable($that.options);
  665. if (o.resetView) {
  666. var h = o.height ? o.height : $(window).height() - 150;
  667. $that.resetView(h);
  668. $(window).resize(function () {
  669. $that.resetView();
  670. });
  671. }
  672. return this;
  673. };
  674. Table.prototype.refresh = function (isForce) {
  675. var $that = this;
  676. abp.ui.setBusy();
  677. setTimeout(function () { abp.ui.clearBusy(); isSearching = false; }, 5 * 1000);
  678. if (isSearching) {
  679. return;
  680. }
  681. isSearching = true;
  682. //getSearchList($that);
  683. //if (!isForce && searchList.length <= 0) {
  684. // console.log("Search-Multi-None");
  685. // return;
  686. //}
  687. var o = $that.options;
  688. var $searchForm = (typeof (o.searchForm) === 'string' ? $('#' + o.searchForm) : $(o.searchForm));
  689. var isValidated = true;
  690. if (o.searchValidate && $searchForm && $searchForm.length > 0) {
  691. isValidated = $.formValidate($searchForm);
  692. }
  693. if (isValidated) {
  694. var $table = (typeof (o.table) === 'string' ? $('#' + o.table) : $(o.table));
  695. $table.bootstrapTable('refresh', { silent: true });
  696. console.log("Search");
  697. } else {
  698. console.log("Search_Validate_Faild");
  699. }
  700. };
  701. Table.prototype.resetView = function (height) {
  702. var $that = this;
  703. var o = $that.options;
  704. var $table = (typeof (o.table) === 'string' ? $('#' + o.table) : $(o.table));
  705. $table.bootstrapTable('resetView', { height: height });
  706. };
  707. Table.prototype.destroy = function () {
  708. var $that = this;
  709. var o = $that.options;
  710. var $table = (typeof (o.table) === 'string' ? $('#' + o.table) : $(o.table));
  711. $table.bootstrapTable('destroy', { silent: true });
  712. };
  713. Table.prototype.getFuns = function () {
  714. var $that = this;
  715. $that.options.funs = $that.options.funs ||
  716. {
  717. btnCreate: function (url) { $that.defaultCreate(url); },
  718. btnUpdate: function (url) { $that.defaultUpdate(url); },
  719. btnDelete: function (url) { $that.defaultDelete(url); },
  720. btnSearch: function () { $that.refresh(true); },
  721. none: function () { console.log("No type"); }
  722. };
  723. return $that.options.funs;
  724. };
  725. Table.prototype.addFuns = function (key, fun) {
  726. var $that = this;
  727. var funs = $that.getFuns();
  728. funs[key] = fun;
  729. $that.options.funs = funs;
  730. };
  731. Table.prototype.defaultCreate = function (url, opt) {
  732. var $that = this;
  733. console.log("Add");
  734. opt = opt || {};
  735. var modalOptions = getModal(url, opt, abp.localization.iwbZero('OpCreate'), 'btnCreate', $that);
  736. var $modal = typeof modalOptions.modal === 'string' ? $('#' + modalOptions.modal) : $(modalOptions.modal);
  737. $modal.iwbModal(modalOptions);
  738. };
  739. Table.prototype.defaultUpdate = function (url, opt, row) {
  740. var $that = this;
  741. console.log("Update");
  742. var o = $that.options;
  743. var $table = (typeof (o.table) === 'string' ? $('#' + o.table) : $(o.table));
  744. opt = opt || {};
  745. row = row || opt.row|| $table.bootstrapTable("getSelections")[0];
  746. if (row) {
  747. var modalOptions = getModal(url, opt, abp.localization.iwbZero('OpUpdate'), 'btnUpdate', $that);
  748. if (!modalOptions.data) {
  749. modalOptions.data = row;
  750. }
  751. var $modal = typeof (modalOptions.modal) === 'string' ? $('#' + modalOptions.modal) : $(modalOptions.modal);
  752. $modal.iwbModal(modalOptions);
  753. } else
  754. abp.message.warn(abp.localization.iwbZero('SelectRecordOperation'));
  755. };
  756. Table.prototype.defaultDelete = function (url, opt,row) {
  757. console.log("Delete");
  758. var $that = this;
  759. var o = $that.options;
  760. var $table = (typeof (o.table) === 'string' ? $('#' + o.table) : $(o.table));
  761. opt = opt || {};
  762. row = row || opt.row || $table.bootstrapTable("getSelections")[0];
  763. if (row) {
  764. var data = opt.data || { id: row.id };
  765. abp.message.confirm(abp.localization.iwbZero('DeleteConfirmContent'),
  766. abp.localization.iwbZero('DeleteConfirm'),
  767. function (isConfirmed) {
  768. if (isConfirmed) {
  769. $.iwbAjax({ table: $table,url: url + '?id=' + data.id, data: data, type: 'post', isValidate: false });
  770. }
  771. });
  772. } else
  773. abp.message.warn(abp.localization.iwbZero('SelectRecordOperation'));
  774. };
  775. Table.prototype.setSearchList = function (obj) {
  776. var $that = this;
  777. var o = $that.options;
  778. o.searchList = obj;
  779. };
  780. Table.prototype.getSelections = function () {
  781. var $that = this;
  782. var o = $that.options;
  783. var $table = (typeof (o.table) === 'string' ? $('#' + o.table) : $(o.table));
  784. return $table.bootstrapTable("getSelections");
  785. }
  786. var allowedMethods = [
  787. 'loadTable',
  788. 'refresh',
  789. 'getFuns',
  790. 'defaultCreate',
  791. 'defaultUpdate',
  792. 'defaultDelete',
  793. 'resetView',
  794. 'destroy',
  795. 'setSearchList',
  796. 'getSelections'
  797. ];
  798. $.fn.iwbTable = function (option) {
  799. var value,
  800. args = Array.prototype.slice.call(arguments, 1);
  801. this.each(function () {
  802. var $this = $(this);
  803. var data = $this.data('iwb.table'),
  804. options = $.extend({}, $this.data(),
  805. typeof option === 'object' && option);
  806. if (typeof option === 'string') {
  807. if ($.inArray(option, allowedMethods) < 0) {
  808. throw new Error("Unknown method: " + option);
  809. }
  810. if (!data) {
  811. return;
  812. }
  813. value = data[option].apply(data, args);
  814. if (option === 'destroy') {
  815. $this.removeData('iwb.table');
  816. $this.removeData('iwbtable.init');
  817. return;
  818. }
  819. }
  820. if ($this.data('iwbtable.init')) {
  821. return;
  822. }
  823. $this.data('iwbtable.init', true);
  824. if (!data) {
  825. data = new Table(this, options);
  826. $this.data('iwb.table', data);
  827. }
  828. });
  829. return typeof value === 'undefined' ? this : value;
  830. };
  831. })(jQuery, window, document);
  832. /*Modal*/
  833. (function ($, window, document, undefined) {
  834. 'use strict';
  835. var Modal = function (ele, opt) {
  836. this.$ele = ele,
  837. this.defaults = {
  838. modal: ele,
  839. modaltitle: '',
  840. data: null,
  841. form: null,
  842. table: undefined,
  843. errorPlacement: function (error, element) {
  844. element.parent().before(error);
  845. //if (element.is('select')) {
  846. // if (!element.next().next().hasClass('error')) {
  847. // element.next().after(error);
  848. // element.focus();
  849. // }
  850. //} else {
  851. // element.parent().before(error);
  852. // element.focus();
  853. //}
  854. },
  855. rules: {},
  856. readonly: '',
  857. disabled: '',
  858. select2: true,
  859. select2tree: false,
  860. url: '',
  861. type:'post',
  862. savebtn: null,
  863. save: null,
  864. success: null,
  865. shownBefore: null,
  866. shownAfter: null,
  867. isRefresh:true,
  868. draggable: true,
  869. backdrop: 'static',
  870. keyboard: true,
  871. kindeditorOption: {},
  872. content:undefined,
  873. abp: window.abp
  874. },
  875. this.options = $.extend({}, this.defaults, opt);
  876. this.draggable();
  877. };
  878. //var abp = window.abp || {};
  879. Modal.prototype.getModal = function () {
  880. var $that = this;
  881. var $modal = typeof ($that.options.modal) === 'string' ? $('#' + $that.options.modal) : $($that.options.modal);
  882. return $modal;
  883. };
  884. Modal.prototype.open = function () {
  885. var $that = this;
  886. var $modal = $that.getModal();
  887. $modal.off('show.bs.modal').on('show.bs.modal',
  888. function () {
  889. $that.showBefore();
  890. $that.init();
  891. $that.setData();
  892. $that.setSelect2();
  893. $that.initKindeditor();
  894. $that.verticalCenter();
  895. $that.bindSave();
  896. $.formValidate($modal.find('form'), { noValid: true });
  897. $that.showAfter();
  898. });
  899. $that.show2();
  900. };
  901. Modal.prototype.show = function () {
  902. var $that = this;
  903. var $modal = $that.getModal();
  904. $modal.off('show.bs.modal').on('show.bs.modal',
  905. function () {
  906. $that.showBefore();
  907. $that.setData();
  908. $that.setSelect2();
  909. $that.initKindeditor();
  910. $that.verticalCenter();
  911. $.formValidate($modal.find('form'), { noValid: true });
  912. $that.showAfter();
  913. });
  914. $that.show2();
  915. };
  916. Modal.prototype.show2 = function () {
  917. var $that = this, o = $that.options;
  918. var $modal = $that.getModal();
  919. $modal.modal( {backdrop: o.backdrop, keyboard: o.keyboard });
  920. $modal.modal( 'show');
  921. $that.verticalCenter();
  922. };
  923. Modal.prototype.create = function() {
  924. var $that = this,o=$that.options;
  925. if (!o.modalId) {
  926. o.modalId = 'Modal_' + (Math.floor((Math.random() * 1000000))) + new Date().getTime();
  927. }
  928. if (o.modalSize === null) {
  929. o.modalSize = "";
  930. }
  931. else if (o.modalSize) {
  932. o.modalSize = o.modalSize;
  933. } else {
  934. o.modalSize = 'modal-lg';
  935. }
  936. var createContainer = function(modalId, modalSize) {
  937. abp.ui.setBusy($("body"));
  938. $that.removeContainer(modalId);
  939. var containerId = modalId + 'Container';
  940. return $('<div id="' + containerId + '"></div>')
  941. .append(
  942. '<div id="' + modalId + '" class="modal fade">' +
  943. ' <div class="modal-dialog ' + modalSize + '">' +
  944. ' <div class="modal-content"></div>' +
  945. ' </div>' +
  946. '</div>'
  947. ).appendTo('body');
  948. };
  949. var show = function() {
  950. $('#'+o.modalId).off('show.bs.modal').on('show.bs.modal',function () {
  951. $that.showBefore();
  952. $that.setSelect2();
  953. $that.bindSave();
  954. $.formValidate($('#'+o.modalId).find('form'), { noValid: true });
  955. $that.showAfter();
  956. });
  957. $that.show2();
  958. abp.ui.clearBusy($("body"));
  959. };
  960. var $modalContent=createContainer(o.modalId, o.modalSize).find('.modal-content');
  961. if (o.viewUrl) {
  962. $modalContent.load(o.viewUrl, o.args, function (response, status, xhr) {
  963. if (status === "error") {
  964. abp.message.warn(abp.localization.abpWeb('InternalServerError'));
  965. return;
  966. }
  967. if (o.scriptUrl) {
  968. $.loadScript(o.scriptUrl, function () {
  969. show();
  970. });
  971. } else {
  972. show();
  973. }
  974. });
  975. } else if (o.content) {
  976. $modalContent.append(o.content);
  977. show();
  978. } else {
  979. return;
  980. }
  981. };
  982. Modal.prototype.hide = function () {
  983. var $that = this, o = $that.options;
  984. var $modal = $that.getModal();
  985. if (o.modalId) {
  986. $that.removeContainer(o.modalId);
  987. }
  988. return $modal.modal('hide');
  989. };
  990. Modal.prototype.removeContainer = function(modalId) {
  991. var containerId = modalId + 'Container';
  992. var containerSelector = '#' + containerId;
  993. var $container = $(containerSelector);
  994. if ($container.length) {
  995. $container.remove();
  996. }
  997. };
  998. Modal.prototype.showBefore = function () {
  999. var $that = this;
  1000. if ($that.options.shownBefore && typeof ($that.options.shownBefore) === 'function') {
  1001. $that.options.shownBefore($that);
  1002. }
  1003. };
  1004. Modal.prototype.showAfter = function () {
  1005. var $that = this;
  1006. if ($that.options.shownAfter && typeof ($that.options.shownAfter) === 'function') {
  1007. $that.options.shownAfter($that);
  1008. }
  1009. };
  1010. Modal.prototype.init = function () {
  1011. var $that = this;
  1012. var $modal = $that.getModal();
  1013. $modal.find('input,select,textarea').val('').removeClass('error valid');
  1014. $modal.find('input:not(.disabled),select:not(.disabled),textarea:not(.disabled)').prop('disabled', false);
  1015. $modal.find('input:not(.readonly),select:not(.readonly),textarea:not(.readonly)').prop('readonly', false);
  1016. $modal.find('label.error').remove();
  1017. $modal.find('.modal-title-span').html($that.options.modaltitle);
  1018. $that.setReadonly();
  1019. $that.setDisabled();
  1020. $that.cleanFile();
  1021. $modal.find('input:not(:disabled,[type=\'hidden\'],[readonly=\'readonly\']):first').focus();
  1022. };
  1023. Modal.prototype.setReadonly = function () {
  1024. var $that = this;
  1025. var $modal = $that.getModal();
  1026. if (!$that.options.readonly)
  1027. return;
  1028. var readonly = $that.options.readonly.split(',');
  1029. for (var i = 0; i < readonly.length; i++) {
  1030. if (readonly[i]) {
  1031. $modal.find('#' + readonly[i]).prop('readonly', true);
  1032. }
  1033. }
  1034. };
  1035. Modal.prototype.setDisabled = function () {
  1036. var $that = this;
  1037. var $modal = $that.getModal();
  1038. if (!$that.options.disabled)
  1039. return;
  1040. var disabled = $that.options.disabled.split(',');
  1041. for (var i = 0; i < disabled.length; i++) {
  1042. if (disabled[i]) {
  1043. $modal.find('#' + disabled[i]).prop('disabled', true);
  1044. }
  1045. }
  1046. };
  1047. Modal.prototype.setData = function () {
  1048. var $that = this;
  1049. var $modal = $that.getModal();
  1050. var $form = $that.options.form ? $($that.options.form) : $modal.find('form');
  1051. $.formDeserialize($form, $that.options.data);
  1052. };
  1053. Modal.prototype.setSelect2 = function () {
  1054. var $that = this;
  1055. var $modal = $that.getModal();
  1056. if ($that.options.select2) {
  1057. $modal.find("select").select2();
  1058. $modal.find('select').off("change.ff").on("change.ff",
  1059. function () {
  1060. $(this).focus();
  1061. $(this).next(".error").remove();
  1062. $(this).blur();
  1063. });
  1064. }
  1065. if ($that.options.select2tree) {
  1066. var tree = $that.options.select2tree.split(',');
  1067. for (var i = 0; i < tree.length; i++) {
  1068. $modal.find('#' + tree[i]).select2tree();
  1069. }
  1070. }
  1071. };
  1072. Modal.prototype.initKindeditor = function () {
  1073. var $that = this;
  1074. var $modal = $that.getModal();
  1075. $modal.find('textarea.kindeditor').each(function (i, v) {
  1076. if ($(v).length && $.fn.iwbKindeditor) {
  1077. var val = $(v).val();
  1078. if ($(v).data("iwb.kindEditor")) {
  1079. $(v).iwbKindeditor('remove');
  1080. }
  1081. var option = $that.options.kindeditorOption || {};
  1082. $(v).iwbKindeditor(option);
  1083. window.editor[$(v).attr('id')].html(val);
  1084. }
  1085. });
  1086. };
  1087. Modal.prototype.cleanFile = function () {
  1088. var $that = this;
  1089. var $modal = $that.getModal();
  1090. $modal.find('input[type="file"]').each(function (i, v) {
  1091. $(v).iwbFileUpload('cleanFile');
  1092. });
  1093. };
  1094. Modal.prototype.bindSave = function () {
  1095. var $that = this;
  1096. var $modal = $that.getModal();
  1097. if ($that.options.url) {
  1098. var $saveBtn = $that.options.savebtn
  1099. ? $($that.options.savebtn)
  1100. : $modal.find('.save-btn').length > 0
  1101. ? $modal.find('.save-btn')
  1102. : $modal.find('.save').length > 0
  1103. ? $modal.find('.save')
  1104. : $modal.find('#save');
  1105. var opt = $that.getSaveOptions();
  1106. if ($that.options.save && typeof ($that.options.save) === "function") {
  1107. $saveBtn.off('click.save').on('click.save',function () {$that.options.save(opt);});
  1108. } else {
  1109. $saveBtn.off('click.save').on('click.save',function () {$.iwbAjax($that.options.url, opt);});
  1110. }
  1111. $modal.find('.modal-body').keydown(function(e) {
  1112. if (e.which === 13) {
  1113. if (e.target.tagName.toLocaleLowerCase() === "textarea") {
  1114. e.stopPropagation();
  1115. } else {
  1116. e.preventDefault();
  1117. var opt = $that.getSaveOptions();
  1118. if ($that.options.save && typeof $that.options.save === "function") {
  1119. $that.options.save(opt);
  1120. } else {
  1121. $.iwbAjax($that.options.url, opt);
  1122. }
  1123. }
  1124. }
  1125. });
  1126. }
  1127. };
  1128. Modal.prototype.getSaveOptions = function () {
  1129. var $that = this;
  1130. var $modal = $that.getModal();
  1131. var $form = $that.options.form ? $($that.options.form) : $modal.find('form');
  1132. return {
  1133. url: $that.options.url,
  1134. type: $that.options.type,
  1135. success: $that.options.success,
  1136. form: $form,
  1137. data:$that.options.data,
  1138. table: $that.options.table,
  1139. modal: $that.options.modal,
  1140. blockUI: $modal.find('.modal-dialog'),
  1141. isRefresh: $that.options.isRefresh
  1142. };
  1143. };
  1144. Modal.prototype.verticalCenter = function () {
  1145. var $that = this;
  1146. var $modal = $that.getModal();
  1147. $modal.css('display', 'block');
  1148. var topHeight = $(window).height() - $modal.find('.modal-dialog').height() - 150;
  1149. if (topHeight < 30) {
  1150. topHeight = 30;
  1151. }
  1152. $modal.find('.modal-dialog').animate({ 'marginTop': topHeight / 2 + "px" });
  1153. };
  1154. Modal.prototype.draggable = function () {
  1155. var $that = this;
  1156. var $modal = $that.getModal();
  1157. if ($that.options.draggable) {
  1158. //console.log('draggable');
  1159. $('.modal-header').css('cursor', 'move');
  1160. /** 拖拽模态框*/
  1161. var dragModal = {
  1162. mouseStartPoint: { 'left': 0, 'top': 0 },
  1163. mouseEndPoint: { 'left': 0, 'top': 0 },
  1164. mouseDragDown: false,
  1165. basePoint: { 'left': 0, 'top': 0 },
  1166. moveTarget: null,
  1167. topleng: 0
  1168. };
  1169. $modal.off('mousedown.drag').on('mousedown.drag',
  1170. '.modal-header',
  1171. function (e) {
  1172. //webkit内核和火狐禁止文字被选中
  1173. $('body').addClass('drag-select');
  1174. //ie浏览器禁止文字选中
  1175. document.body.onselectstart = document.body.ondrag = function () {
  1176. return false;
  1177. };
  1178. if ($(e.target).hasClass('close')) //点关闭按钮不能移动对话框
  1179. return;
  1180. dragModal.mouseDragDown = true;
  1181. dragModal.moveTargetHeader = $(this);
  1182. dragModal.moveTarget = $(this).closest('.modal-content');
  1183. dragModal.mouseStartPoint = { 'left': e.clientX, 'top': e.pageY };
  1184. dragModal.basePoint = dragModal.moveTarget.offset();
  1185. dragModal.topLeng = e.pageY - e.clientY;
  1186. });
  1187. $modal.off('mouseup.drag').on('mouseup.drag',
  1188. function () {
  1189. dragModal.mouseDragDown = false;
  1190. dragModal.moveTarget = undefined;
  1191. dragModal.mouseStartPoint = { 'left': 0, 'top': 0 };
  1192. dragModal.basePoint = { 'left': 0, 'top': 0 };
  1193. });
  1194. $modal.off('mousemove.drag').on('mousemove.drag',
  1195. function (e) {
  1196. if (!dragModal.mouseDragDown || dragModal.moveTarget === undefined) return;
  1197. var mousX = e.clientX;
  1198. var mousY = e.pageY;
  1199. if (mousX < 0) mousX = 0;
  1200. if (mousY < 0) mousY = 25;
  1201. dragModal.mouseEndPoint = { 'left': mousX, 'top': mousY };
  1202. var width = dragModal.moveTarget.width();
  1203. var height = dragModal.moveTargetHeader.height();
  1204. var clientWidth = document.body.clientWidth;
  1205. var clientHeight = document.body.clientHeight;
  1206. if (dragModal.mouseEndPoint.left < dragModal.mouseStartPoint.left - dragModal.basePoint.left) {
  1207. dragModal.mouseEndPoint.left = 0;
  1208. } else if (dragModal.mouseEndPoint.left >=
  1209. clientWidth - width + dragModal.mouseStartPoint.left - dragModal.basePoint.left) {
  1210. dragModal.mouseEndPoint.left = clientWidth - width - 38;
  1211. } else {
  1212. dragModal.mouseEndPoint.left =
  1213. dragModal.mouseEndPoint.left -
  1214. (dragModal.mouseStartPoint.left - dragModal.basePoint.left); //移动修正,更平滑
  1215. }
  1216. if (dragModal.mouseEndPoint.top - (dragModal.mouseStartPoint.top - dragModal.basePoint.top) <
  1217. dragModal.topLeng) {
  1218. dragModal.mouseEndPoint.top = dragModal.topLeng;
  1219. } else if (dragModal.mouseEndPoint.top - dragModal.topLeng >
  1220. clientHeight - height + dragModal.mouseStartPoint.top - dragModal.basePoint.top) {
  1221. dragModal.mouseEndPoint.top = clientHeight - height - 38 + dragModal.topLeng;
  1222. } else {
  1223. dragModal.mouseEndPoint.top = dragModal.mouseEndPoint.top -
  1224. (dragModal.mouseStartPoint.top - dragModal.basePoint.top);
  1225. }
  1226. dragModal.moveTarget.offset(dragModal.mouseEndPoint);
  1227. });
  1228. $(document).on('hidden.bs.modal',
  1229. '.modal',
  1230. function () {
  1231. $('.modal-content').css({ 'top': 0, 'left': 0 });
  1232. $('body').removeClass('drag-select');
  1233. document.body.onselectstart = document.body.ondrag = null;
  1234. });
  1235. } else {
  1236. $('.modal-header').css('cursor', 'default');
  1237. }
  1238. };
  1239. var allowedMethods = [
  1240. 'open',
  1241. 'show',
  1242. 'show2',
  1243. 'hide'
  1244. ];
  1245. $.fn.iwbModal = function (option) {
  1246. var value,
  1247. args = Array.prototype.slice.call(arguments, 1);
  1248. this.each(function () {
  1249. var modal = new Modal(this, option);
  1250. if (typeof option === 'string') {
  1251. if ($.inArray(option, allowedMethods) < 0) {
  1252. throw new Error("Unknown method: " + option);
  1253. }
  1254. value = modal[option].apply(modal, args);
  1255. } else {
  1256. modal.open();
  1257. }
  1258. });
  1259. return typeof value === 'undefined' ? this : value;
  1260. };
  1261. })(jQuery, window, document);
  1262. /*FileUpload*/
  1263. (function ($, window, document, undefined) {
  1264. 'use strict';
  1265. var abp = window.abp || {};
  1266. var File = function (ele, opt) {
  1267. this.$ele = ele,
  1268. this.defaults = {
  1269. file: ele,
  1270. maxSize: 2,
  1271. isImage: true,
  1272. targetInfo: undefined,
  1273. targetName: "fileName",
  1274. targetExt: "fileExt",
  1275. callback: undefined,
  1276. abp: window.abp
  1277. },
  1278. this.options = $.extend({}, this.defaults, opt || {});
  1279. //var $that = this;
  1280. //$that.show();
  1281. };
  1282. File.prototype.getFile = function () {
  1283. var $that = this;
  1284. var $file = typeof ($that.options.file) === 'string' ? $('#' + $that.options.file) : $($that.options.file);
  1285. return $file;
  1286. };
  1287. File.prototype.show = function () {
  1288. var $that = this;
  1289. var $file = $that.getFile();
  1290. $file.off('change.file.check').on('change.file.check', function () {
  1291. $that.fileCheck($that);
  1292. });
  1293. $file.closest('.iwb-file ').removeClass("file-success").removeClass("file-error");
  1294. //return $file[0].click();
  1295. };
  1296. File.prototype.fileCheck = function ($that) {
  1297. var $file = $that.getFile();
  1298. if ($that.checkSize()) {
  1299. var fileName = $file.val().split("\\").pop();
  1300. $file.closest('.iwb-file ').addClass("file-success").find("label").text(fileName);
  1301. var file = document.getElementById($file.attr("id")).files[0];
  1302. $that.readFile(file);
  1303. if ($that.options.targetName && $that.options.targetName !== undefined) {
  1304. var name = fileName.substring(0, fileName.lastIndexOf("."));
  1305. if (!$that.options.targetName)
  1306. return;
  1307. var targetName = $that.options.targetName.split(',');
  1308. for (var i = 0; i < targetName.length; i++) {
  1309. $('#' + targetName[i]).val(name);
  1310. }
  1311. }
  1312. if ($that.options.targetExt && $that.options.targetExt !== undefined) {
  1313. var ext = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length);
  1314. if (!$that.options.targetExt)
  1315. return;
  1316. var targetExt = $that.options.targetExt.split(',');
  1317. for (var j = 0; j < targetExt.length; j++) {
  1318. $('#' + targetExt[j]).val(ext);
  1319. }
  1320. }
  1321. var callback = $that.options.callback;
  1322. if (callback && typeof (callback) === "function") {
  1323. callback(fileName, file);
  1324. }
  1325. } else {
  1326. var target = $that.options.targetInfo ? $that.options.targetInfo : $file.attr('id').replace('_file', '');
  1327. $('#' + target).closest('.iwb-file ').addClass("file-error").find("label").text(abp.localization.iwbZero('SelectFile'));
  1328. }
  1329. };
  1330. File.prototype.checkSize = function () {
  1331. var $that = this;
  1332. var $file = $that.getFile();
  1333. var maxsize = $that.options.maxSize * 1024 * 1024;
  1334. //var errMsg = "上传的附件文件不能超过" + $that.options.maxSize + "M。";
  1335. //var tipMsg = "您的浏览器暂不支持计算上传文件的大小,确保上传文件不要超过" + $that.options.maxSize + "M,建议使用IE、FireFox、Chrome浏览器。";
  1336. var errMsg = abp.localization.iwbZero('FileUploadErrorMsg', $that.options.maxSize );
  1337. var tipMsg = abp.localization.iwbZero('FileUploadTipMsg', $that.options.maxSize);
  1338. var browserCfg = {};
  1339. var ua = window.navigator.userAgent;
  1340. if (ua.indexOf("MSIE") >= 1) {
  1341. browserCfg.ie = true;
  1342. } else if (ua.indexOf("Firefox") >= 1) {
  1343. browserCfg.firefox = true;
  1344. } else if (ua.indexOf("Chrome") >= 1) {
  1345. browserCfg.chrome = true;
  1346. }
  1347. try {
  1348. var objFile = document.getElementById($file.attr("id"));
  1349. if (objFile.value === "") {
  1350. //layer.alert("请先选择上传文件", { icon: 7, title: "提示信息" });
  1351. return false;
  1352. }
  1353. var filesize;
  1354. if (browserCfg.firefox || browserCfg.chrome) {
  1355. filesize = objFile.files[0].size;
  1356. } else if (browserCfg.ie) {
  1357. var objImg = document.createElement("img");
  1358. objImg.id = "tempImg";
  1359. objImg.style.display = "none";
  1360. document.body.appendChild(objImg);
  1361. objImg.dynsrc = objFile.value;
  1362. filesize = objImg.fileSize;
  1363. } else {
  1364. $that.cleanFile();
  1365. abp.message.warn(tipMsg);
  1366. return false;
  1367. }
  1368. if (filesize === -1) {
  1369. $that.cleanFile();
  1370. abp.message.warn(tipMsg);
  1371. return false;
  1372. } else if (filesize > maxsize) {
  1373. $that.cleanFile();
  1374. abp.message.warn(errMsg);
  1375. return false;
  1376. } else {
  1377. return true;
  1378. }
  1379. } catch (e) {
  1380. $that.cleanFile();
  1381. abp.message.error(e);
  1382. return false;
  1383. }
  1384. };
  1385. File.prototype.readFile = function (file) {
  1386. //判断是否是图片类型
  1387. //console.log(file.type);
  1388. if (!file) {
  1389. return;
  1390. }
  1391. var $that = this;
  1392. var $file = $that.getFile();
  1393. if ($that.options.isImage && !/image\/\w+/.test(file.type)) {
  1394. abp.message.warn(abp.localization.iwbZero('FileUploadOnlyImage'));
  1395. return;
  1396. }
  1397. var reader = new FileReader();
  1398. reader.readAsDataURL(file);
  1399. reader.onload = function () {
  1400. var fileinfo = this.result.substring(this.result.indexOf(',') + 1);
  1401. console.log(fileinfo);
  1402. var target = $that.options.targetInfo ? $that.options.targetInfo : $file.attr('id').replace('_file', '');
  1403. $('#' + target).val(fileinfo);
  1404. };
  1405. };
  1406. File.prototype.cleanFile = function () {
  1407. var $that = this;
  1408. var $file = $that.getFile();
  1409. $file.closest('.custom-file ').removeClass("file-success").removeClass("file-error").find("label").text(abp.localization.iwbZero('SelectFile'));
  1410. $file.after($file.clone().val(""));
  1411. $file.remove();
  1412. };
  1413. var allowedMethods = [
  1414. 'show',
  1415. 'readFile',
  1416. 'cleanFile',
  1417. 'fileCheck',
  1418. 'checkSize'
  1419. ];
  1420. $.fn.iwbFileUpload = function (option) {
  1421. var value,
  1422. args = Array.prototype.slice.call(arguments, 1);
  1423. this.each(function () {
  1424. var $this = $(this);
  1425. var data = $this.data('iwb.FileUpload');
  1426. if (!data) {
  1427. data = new File(this, option);
  1428. $this.data('iwb.FileUpload', data);
  1429. }
  1430. if (typeof option === 'string') {
  1431. if ($.inArray(option, allowedMethods) < 0) {
  1432. throw new Error("Unknown method: " + option);
  1433. }
  1434. value = data[option].apply(data, args);
  1435. } else {
  1436. data.show();
  1437. }
  1438. });
  1439. return typeof value === 'undefined' ? this : value;
  1440. };
  1441. })(jQuery, window, document);
  1442. /*FileOpenShow*/
  1443. (function ($, window, document, undefined) {
  1444. 'use strict';
  1445. var File = function (ele, opt) {
  1446. this.$ele = ele,
  1447. this.defaults = {
  1448. url: undefined,
  1449. type: 'img'
  1450. },
  1451. this.options = $.extend({}, this.defaults, opt);
  1452. if ($(this.$ele).data('type')) {
  1453. this.options.type = $(this.$ele).data('type');
  1454. }
  1455. if (!this.options.url) {
  1456. this.options.url = $(this.$ele).data('url');
  1457. }
  1458. if (this.options.url && this.options.url.indexOf("/") !== 0) {
  1459. this.options.url = "/" + this.options.url;
  1460. }
  1461. };
  1462. //var abp = window.abp || {};
  1463. File.prototype.show = function () {
  1464. var $that = this;
  1465. switch ($that.options.type) {
  1466. case 'img':
  1467. case 'image':
  1468. this.showImage();
  1469. break;
  1470. case 'office':
  1471. this.showOffice();
  1472. break;
  1473. default:
  1474. this.showFile();
  1475. return;
  1476. }
  1477. };
  1478. File.prototype.showImage = function () {
  1479. var $that = this;
  1480. $.metPageCss('/Content/Libs/viewer/viewer.min.css', "dy-css-viewer");
  1481. $.metPageJs('/Content/Libs/viewer/viewer.min.js', "dy-js-viewer");
  1482. if ($("#Img-Modal").length > 0) {
  1483. $("#Img-Modal").remove();
  1484. }
  1485. $("body").append(' <ul id="Img-Modal" style="display:none"><li><img src="' +
  1486. $that.options.url +
  1487. '" data-original="' +
  1488. $that.options.url +
  1489. '" alt="Picture" /></li></ul>');
  1490. var $image = $('#Img-Modal');
  1491. var options = {
  1492. // inline: true,
  1493. url: 'data-original',
  1494. button: true,
  1495. navbar: false,
  1496. title: false,
  1497. toolbar: false,
  1498. ready: function (e) {
  1499. console.log(e.type);
  1500. }
  1501. };
  1502. $image.on({
  1503. show: function (e) {
  1504. console.log(e.type);
  1505. },
  1506. hidden: function(e) {
  1507. $image.viewer('destroy');
  1508. $image.remove();
  1509. }
  1510. }).viewer(options);
  1511. $image.viewer("show");
  1512. $image.css("display", "none");
  1513. };
  1514. File.prototype.showOffice = function () {
  1515. var $that = this;
  1516. var url = 'http://ow365.cn/?i=17314&furl=http://' + window.location.host + $that.options.url;
  1517. $that.showFile(url);
  1518. };
  1519. File.prototype.showFile = function (url) {
  1520. var $that = this;
  1521. url = url || $that.options.url;
  1522. if ($('#File-Modal').length <= 0) {
  1523. $('body').append(
  1524. '<section><div class="modal fade" id="File-Modal" role="dialog" tabindex="-1" aria-hidden="true"><div class="modal-dialog modal-dialog-centered" role="document" style="min-width: calc(100% - 600px);"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true"><span aria-hidden="true">&times;</span></button><h4 class="modal-title">文件预览</h4></div><div class="modal-body" style=" overflow: hide"></div><div class="modal-footer" style="text-align: center;"><button type="button" class="btn btn-success waves-effect" data-dismiss="modal" style="min-width: 100px;background: #F0985D;border: 1px solid #DDDDDD;">关闭窗口</button><button id="download" type="button" class="btn btn-success waves-effect" style="min-width: 100px;background-color: #678ceb;border: 1px solid #678ceb;border: 1px solid #DDDDDD;">下载文件</button></div></div></div></div></section>');
  1525. }
  1526. $('#File-Modal').find('.modal-body')
  1527. .html('<iframe src="' + url + '" width="100%"; style="min-height: calc(100vh - 200px);" frameborder="0"></iframe>');
  1528. $(document).off('click.download', '#File-Modal #download').on('click.download', '#File-Modal #download',
  1529. function () { $that.download(url)});
  1530. $('#File-Modal').iwbModal('show2');
  1531. };
  1532. File.prototype.download = function (url) {
  1533. var $that = this;
  1534. url = url || $that.options.url;
  1535. if ($('#tempLink-fd').length>0) {
  1536. $('#tempLink-fd').remove();
  1537. }
  1538. $('body').append('<a id="tempLink-fd" href="' + url + '" style="display:none"></a>');
  1539. $('#tempLink-fd')[0].click();
  1540. $('#tempLink-fd').remove();
  1541. };
  1542. var allowedMethods = [
  1543. 'show',
  1544. 'download'
  1545. ];
  1546. $.fn.iwbFileShow = function (option) {
  1547. var value,
  1548. args = Array.prototype.slice.call(arguments, 1);
  1549. this.each(function () {
  1550. var $this = $(this);
  1551. var data = $this.data('iwb.FileShow');
  1552. if (!data || typeof option !== 'string') {
  1553. data = new File(this, option);
  1554. $this.data('iwb.FileShow', data);
  1555. }
  1556. if (typeof option === 'string') {
  1557. if ($.inArray(option, allowedMethods) < 0) {
  1558. throw new Error("Unknown method: " + option);
  1559. }
  1560. value = data[option].apply(data, args);
  1561. } else {
  1562. data.show();
  1563. }
  1564. });
  1565. return typeof value === 'undefined' ? this : value;
  1566. };
  1567. })(jQuery, window, document);
  1568. /*TreeView*/
  1569. (function ($, window, document, undefined) {
  1570. 'use strict';
  1571. var TreeView = function (ele, opt) {
  1572. var that = this;
  1573. var tempId = '';
  1574. var onNodeSelected = function (e, data, that) {
  1575. var o = that.options;
  1576. if (!data || !data[o.selectFiledName]) {
  1577. return;
  1578. }
  1579. var $input = (typeof (o.selectFiledInput) === 'string' ? $('#' + o.selectFiledInput) : $(o.selectFiledInput));
  1580. tempId = data[o.selectFiledName];
  1581. $input.val(tempId);
  1582. var $table = (typeof (o.table) === 'string' ? $('#' + o.table) : $(o.table));
  1583. $table.iwbTable('refresh', true);
  1584. };
  1585. var onNodeUnselected = function (e, data, that) {
  1586. var o = that.options;
  1587. var $input = (typeof (o.selectFiledInput) === 'string' ? $('#' + o.selectFiledInput) : $(o.selectFiledInput));
  1588. $input.val('');
  1589. var $table = (typeof (o.table) === 'string' ? $('#' + o.table) : $(o.table));
  1590. $table.iwbTable('refresh', true);
  1591. };
  1592. this.$ele = ele,
  1593. this.defaults = {
  1594. url: undefined,
  1595. data: undefined,
  1596. levels: 2,
  1597. emptyIcon: "iconfont icon-delete",
  1598. collapseIcon: 'iconfont icon-delete ',
  1599. expandIcon: 'iconfont icon-add',
  1600. selectedBackColor: '#563d7c',
  1601. onNodeSelected: function (e, d) {
  1602. onNodeSelected(e, d, that);
  1603. },
  1604. onNodeUnselected: function (e, d) {
  1605. onNodeUnselected(e, d, that);
  1606. },
  1607. table: 'table',
  1608. selectFiledName: 'id',
  1609. selectFiledInput: 'keyWords'
  1610. },
  1611. this.options = $.extend({}, this.defaults, opt);
  1612. };
  1613. //var abp = window.abp || {};
  1614. TreeView.prototype.init = function () {
  1615. var that = this, o = that.options;
  1616. $.metPageCss('/Content/Libs/bootstrap-treeview/bootstrap-treeview.min.css', "dy-css-treeview");
  1617. $.metPageJs('/Content/Libs/bootstrap-treeview/bootstrap-treeview.min.js', "dy-js-treeview");
  1618. if (o.data) {
  1619. that.loadTree();
  1620. } else if (o.url) {
  1621. that.postData();
  1622. }
  1623. };
  1624. TreeView.prototype.loadTree = function (data) {
  1625. var that = this, o = that.options;
  1626. var option = $.extend({}, o);
  1627. if (data) {
  1628. option.data = data;
  1629. }
  1630. $(that.$ele).treeview(option);
  1631. };
  1632. TreeView.prototype.postData = function (url) {
  1633. var that = this, o = that.options;
  1634. url = url || o.url;
  1635. $.iwbAjax({
  1636. url: window.appUrl + url,
  1637. isAlert: false,
  1638. isValidate: false,
  1639. isRefresh: false,
  1640. success: function (res) {
  1641. if (res) {
  1642. that.loadTree(res);
  1643. }
  1644. }
  1645. });
  1646. };
  1647. var allowedMethods = [
  1648. 'init'
  1649. ];
  1650. $.fn.iwbTreeView = function (option) {
  1651. var value,
  1652. args = Array.prototype.slice.call(arguments, 1);
  1653. this.each(function () {
  1654. var $this = $(this);
  1655. var data = $this.data('iwb.TreeView');
  1656. if (!data) {
  1657. data = new TreeView(this, option);
  1658. $this.data('iwb.TreeView', data);
  1659. data.init();
  1660. }
  1661. if (typeof option === 'string') {
  1662. if ($.inArray(option, allowedMethods) < 0) {
  1663. throw new Error("Unknown method: " + option);
  1664. }
  1665. value = data[option].apply(data, args);
  1666. }
  1667. });
  1668. return typeof value === 'undefined' ? this : value;
  1669. };
  1670. })(jQuery, window, document);
  1671. /*DateTime*/
  1672. (function ($, window, document, undefined) {
  1673. 'use strict';
  1674. var DateTime = function (ele, opt) {
  1675. this.$ele = ele,
  1676. this.defaults = {
  1677. language: 'zh-CN',
  1678. format: "yyyy-mm-dd", //yyyy-mm-ddThh:ii:ssZ
  1679. autoclose: true, //当选择一个日期之后是否立即关闭此日期时间选择器。
  1680. startView: 2, //日期时间选择器打开之后首先显示的视图。 可接受的值:0 or 'hour' \ 1 or 'day' \2 or 'month' (the default )\3 or 'year' \4 or 'decade' for the 10-year overview.
  1681. minView: 2, //日期时间选择器所能够提供的最精确的时间选择视图。
  1682. maxView: 4, //日期时间选择器最高能展示的选择范围视图。
  1683. todayBtn: true,
  1684. weekStart: 0, //一周从哪一天开始。0(星期日)到6(星期六)
  1685. startDate: '2015-01-01', //开始时间
  1686. endDate: null, //结束时间,
  1687. forceParse: true, //强制解析
  1688. minuteStep: 10, //分钟视图中分钟间隔
  1689. twoDateId: undefined,//双日期外部Id(默认找里面的 .startTime和.endTime)
  1690. startId: undefined,//开始日期Id,不填就是本身
  1691. endId: undefined,//结束日期Id
  1692. isAutoSetDate: true,//双日期自动填写另一个日期
  1693. startEndInterval: 30,//双日期自动填写间隔(天)
  1694. defaultDate: undefined//默认日期时间
  1695. },
  1696. this.options = $.extend({}, this.defaults, opt);
  1697. };
  1698. //var abp = window.abp || {};
  1699. DateTime.prototype.init = function () {
  1700. var that = this;//, o = that.options;
  1701. $.metPageCss('/Content/Libs/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css', "dy-css-dateTime");
  1702. //$.metPageCss('/Content/Plugins/bootstrap-datetimepicker/css/bootstrap-datetimepicker-wr.css', "dy-css-dateTime-self");
  1703. $.metPageJs('/Content/Libs/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js', "dy-js-dateTime");
  1704. $.metPageJs('/Content/Libs/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js', "dy-js-dateTime-zhCN");
  1705. };
  1706. DateTime.prototype.date = function () {
  1707. var that = this, o = that.options;
  1708. o.format = "yyyy-mm-dd";
  1709. o.startView = 2;
  1710. o.minView = 2;
  1711. that.load();
  1712. };
  1713. DateTime.prototype.dateTime = function () {
  1714. var that = this, o = that.options;
  1715. o.format = "yyyy-mm-dd hh:ii";
  1716. o.startView = 2;
  1717. o.minView = 1;
  1718. that.load();
  1719. };
  1720. DateTime.prototype.dateSecond = function () {
  1721. var that = this, o = that.options;
  1722. o.format = "yyyy-mm-dd hh:ii:ss";
  1723. o.startView = 2;
  1724. o.minView = 0;
  1725. that.load();
  1726. };
  1727. DateTime.prototype.twoDate = function () {
  1728. var that = this, o = that.options;
  1729. var $start, $end;
  1730. if (o.twoDateId) {
  1731. $start = $('#' + o.twoDateId).find('.startTime');
  1732. $end = $('#' + o.twoDateId).find('.endTime');
  1733. } else {
  1734. $start = $('#' + o.startId);
  1735. $end = $('#' + o.endId);
  1736. }
  1737. $start = $start.length > 0 ? $start : $(that.$ele);
  1738. if ($end.length <= 0) {
  1739. $end = $start.parent().find('.endTime');
  1740. if ($end.length <= 0) {
  1741. throw new Error("Unknown EndDate Selector");
  1742. }
  1743. }
  1744. $start.datetimepicker('remove');
  1745. $start.datetimepicker(o).on('show',
  1746. function (event) {
  1747. event.preventDefault();
  1748. event.stopPropagation();
  1749. }).on('hide',
  1750. function (event) {
  1751. event.preventDefault();
  1752. event.stopPropagation();
  1753. }).on("changeDate",
  1754. function (e) {
  1755. //console.log(e);
  1756. //console.log(e.date.valueOf());
  1757. $end.datetimepicker('setStartDate', e.date);
  1758. if (o.isAutoSetDate && o.startEndInterval && o.startEndInterval > 0) {
  1759. $end.datetimepicker('setDate',
  1760. new Date(e.date.valueOf() + 1000 * 60 * 60 * 24 * o.startEndInterval));
  1761. }
  1762. });
  1763. $end.datetimepicker('remove');
  1764. $end.datetimepicker(o).on('show',
  1765. function (event) {
  1766. event.preventDefault();
  1767. event.stopPropagation();
  1768. }).on('hide',
  1769. function (event) {
  1770. event.preventDefault();
  1771. event.stopPropagation();
  1772. }).on("changeDate",
  1773. function (e) {
  1774. //console.log(e);
  1775. //console.log(e.date.valueOf());
  1776. $start.datetimepicker('setEndDate', e.date);
  1777. if (o.isAutoSetDate && o.startEndInterval && o.startEndInterval > 0) {
  1778. $start.datetimepicker('setDate', new Date(e.date.valueOf() - 1000 * 60 * 60 * 24 * o.startEndInterval));
  1779. }
  1780. });
  1781. if (o.isAutoSetDate) {
  1782. var eDate = o.defaultDate ? o.defaultDate : new Date();
  1783. $end.datetimepicker("setDate", eDate);
  1784. $start.datetimepicker("setDate",
  1785. new Date(eDate.valueOf() - 1000 * 60 * 60 * 24 * (o.startEndInterval ? o.startEndInterval : 30)));
  1786. }
  1787. };
  1788. DateTime.prototype.load = function () {
  1789. var that = this, o = that.options;
  1790. $(that.$ele).datetimepicker('remove');
  1791. $(that.$ele).datetimepicker(o).on('show', function (event) {
  1792. event.preventDefault();
  1793. event.stopPropagation();
  1794. }).on('hide', function (event) {
  1795. event.preventDefault();
  1796. event.stopPropagation();
  1797. });
  1798. };
  1799. //var allowedMethods = [
  1800. // 'date',
  1801. // 'dateTime',
  1802. // 'dateSecond',
  1803. // 'twoDate'
  1804. //];
  1805. //$.fn.iwbDate2 = function (option) {
  1806. // var value,
  1807. // args = Array.prototype.slice.call(arguments, 1);
  1808. // this.each(function () {
  1809. // var $this = $(this);
  1810. // var data = $this.data('iwb.dateTime');
  1811. // if (!data) {
  1812. // data = new DateTime(this, option ? option : {});
  1813. // $this.data('iwb.dateTime', data);
  1814. // data.init();
  1815. // }
  1816. // if (typeof option === 'string') {
  1817. // if ($.inArray(option, allowedMethods) < 0) {
  1818. // throw new Error("Unknown method: " + option);
  1819. // }
  1820. // value = data[option].apply(data, args);
  1821. // } else if (option && option.method && typeof option.method === 'string') {
  1822. // if ($.inArray(option.method, allowedMethods) < 0) {
  1823. // throw new Error("Unknown method: " + option.method);
  1824. // }
  1825. // value = data[option.method].apply(data, args);
  1826. // }
  1827. // else {
  1828. // if (!option && $this.hasClass('iwb-date')) {
  1829. // data.date();
  1830. // } else if (!option && ($this.hasClass('iwb-date-time') || $this.hasClass('iwb-dateTime'))) {
  1831. // data.dateTime();
  1832. // } else if (!option && ($this.hasClass('iwb-date-second') || $this.hasClass('iwb-dateSecond'))) {
  1833. // data.dateSecond();
  1834. // } else if (!option && ($this.hasClass('startTime') || $this.hasClass('iwb-date-two') || $this.hasClass('iwb-twoDate'))) {
  1835. // data.twoDate();
  1836. // } else {
  1837. // data.load();
  1838. // }
  1839. // }
  1840. // });
  1841. // return typeof value === 'undefined' ? this : value;
  1842. //};
  1843. //$.fn.iwbTwoDate2 = function (option) {
  1844. // this.each(function () {
  1845. // var $this = $(this);
  1846. // var data = $this.data('iwb.dateTime');
  1847. // if (!data) {
  1848. // data = new DateTime(this, option);
  1849. // $this.data('iwb.dateTime', data);
  1850. // data.init();
  1851. // data.twoDate();
  1852. // }
  1853. // });
  1854. // return this;
  1855. //};
  1856. //$('.iwb-date-time').iwbDate();
  1857. //$('.iwb-date').iwbDate();
  1858. })(jQuery, window, document);
  1859. /*DateTime*/
  1860. (function ($, window, document, undefined) {
  1861. 'use strict';
  1862. var DateTime = function(ele, opt) {
  1863. this.$ele = ele,
  1864. this.defaults = {
  1865. language: 'zh-CN',
  1866. singleDatePicker: true,
  1867. dayStep:false,
  1868. opens: "center",
  1869. drops: "down",
  1870. format: "YYYY-MM-DD", //YYYY-MM-DD HH:MM:SS
  1871. showEvent:undefined,
  1872. showCalendarEvent:undefined,
  1873. hideEvent:undefined,
  1874. hideCalendarEvent:undefined,
  1875. applyEvent:undefined,
  1876. cancelEvent:undefined,
  1877. minDate: '2015-01-01',
  1878. maxDate: false,
  1879. showWeekNumbers: false,
  1880. showISOWeekNumbers: false,
  1881. timePicker: false,
  1882. timePicker24Hour: true,
  1883. timePickerIncrement: 5,
  1884. timePickerSeconds: false,
  1885. linkedCalendars: true,
  1886. showCustomRangeLabel: false,
  1887. alwaysShowCalendars: true,
  1888. autoApply: true,
  1889. autoUpdateInput: true,
  1890. buttonClasses: "btn btn-sm",
  1891. applyButtonClasses: "btn-success",
  1892. cancelClass: "btn-default",
  1893. startDate: undefined, //开始时间
  1894. endDate: undefined, //结束时间,
  1895. maxSpan: undefined,
  1896. locale: undefined,
  1897. ranges: undefined,
  1898. hasRange: false
  1899. },
  1900. this.options = $.extend({}, this.defaults, opt);
  1901. };
  1902. var dateOpt = {};
  1903. var timeSelect2 = function() {
  1904. $('.daterangepicker .calendar-time > select').select2();
  1905. }
  1906. //var abp = window.abp || {};
  1907. DateTime.prototype.init = function () {
  1908. var that = this; var o = that.options;
  1909. $.metPageCss('/Content/Plugins/bootstrap-daterangepicker/daterangepicker.css', "dy-css-daterangepicker");
  1910. $.metPageJs('/Content/Plugins/bootstrap-daterangepicker/moment-with-locales.min.js', "dy-js-daterangepicker.moment");
  1911. $.metPageJs('/Content/Plugins/bootstrap-daterangepicker/daterangepicker.js', "dy-js-daterangepicker");
  1912. var lang = o.language.toLowerCase();
  1913. if (lang === 'zh-hans') {
  1914. lang = 'zh-cn';
  1915. }
  1916. moment.locale(lang);
  1917. var localeName = {
  1918. applyLabel: 'Apply',
  1919. cancelLabel: 'Cancel',
  1920. fromLabel: "",
  1921. toLabel: "",
  1922. customRangeLabel: 'Custom Range',
  1923. daysOfWeek: moment.weekdaysMin(),
  1924. monthNames: moment.monthsShort()
  1925. },
  1926. ranges = {
  1927. 'Today': [moment(), moment()],
  1928. 'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
  1929. 'Last 7 Days': [moment().subtract(6, 'days'), moment()],
  1930. 'Last 30 Days': [moment().subtract(29, 'days'), moment()],
  1931. 'This Month': [moment().startOf('month'), moment().endOf('month')],
  1932. 'Last Month': [
  1933. moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')
  1934. ]
  1935. };
  1936. //if (o.language.toLowerCase() === 'zh-cn' || o.language.toLowerCase() === 'zh-hans') {
  1937. // localeName = {
  1938. // applyLabel: "确定",
  1939. // cancelLabel: "清空",
  1940. // fromLabel: "起始时间",
  1941. // toLabel: "结束时间'",
  1942. // customRangeLabel: "自定义",
  1943. // weekLabel: "W",
  1944. // daysOfWeek: ["日", "一", "二", "三", "四", "五", "六"],
  1945. // monthNames: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
  1946. // };
  1947. // ranges = {
  1948. // '今日': [moment(), moment()],
  1949. // '昨日': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
  1950. // '最近 7 日': [moment().subtract(6, 'days'), moment()],
  1951. // '最近 30 最近': [moment().subtract(29, 'days'), moment()],
  1952. // '上个月': [moment().startOf('month'), moment().endOf('month')],
  1953. // '本月': [
  1954. // moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')
  1955. // ]
  1956. // };
  1957. //}
  1958. dateOpt = {
  1959. format: o.format, //YYYY-MM-DD HH:MM:SS
  1960. opens: o.opens,
  1961. startDate:o.startDate?o.startDate:false,
  1962. endDate:o.endDate?o.endDate:false,
  1963. singleDatePicker: o.singleDatePicker,
  1964. drops: o.drops,
  1965. minDate: o.minDate,
  1966. maxDate: o.maxDate,
  1967. showCustomRangeLabel: o.showCustomRangeLabel ? o.hasRange : o.showCustomRangeLabel,
  1968. linkedCalendars: o.linkedCalendars,
  1969. showWeekNumbers: o.showWeekNumbers,
  1970. showISOWeekNumbers: o.showISOWeekNumbers,
  1971. timePicker: o.timePicker,
  1972. timePicker24Hour: o.timePicker24Hour,
  1973. timePickerIncrement: o.timePickerIncrement,
  1974. timePickerSeconds: o.timePickerSeconds,
  1975. buttonClasses: o.buttonClasses,
  1976. applyButtonClasses: o.applyButtonClasses,
  1977. cancelClass: o.cancelClass,
  1978. autoApply: o.autoApply,
  1979. autoUpdateInput: o.autoUpdateInput,
  1980. alwaysShowCalendars: o.alwaysShowCalendars,
  1981. maxSpan: o.maxSpan ? o.maxSpan : o.dayStep ? {
  1982. days: o.dayStep
  1983. } : false,
  1984. locale: o.locale ? o.locale: {
  1985. direction: 'ltr',
  1986. format: o.format,
  1987. separator: " - ", //
  1988. applyLabel: localeName.applyLabel,
  1989. cancelLabel: localeName.cancelLabel,
  1990. fromLabel: localeName.fromLabel,
  1991. toLabel: localeName.toLabel,
  1992. customRangeLabel: localeName.customRangeLabel,
  1993. weekLabel: localeName.weekLabel,
  1994. daysOfWeek: localeName.daysOfWeek,
  1995. monthNames: localeName.monthNames,
  1996. firstDay: 1
  1997. },
  1998. ranges: !o.hasRange ? false : o.ranges ? o.ranges : ranges
  1999. };
  2000. };
  2001. DateTime.prototype.date = function () {
  2002. var that = this, o = that.options;
  2003. var opt = {locale: {}};
  2004. opt.locale.format = "YYYY-MM-DD";
  2005. that.load(opt);
  2006. };
  2007. DateTime.prototype.dateTime = function () {
  2008. var that = this//, o = that.options;
  2009. var opt = {locale: {}};
  2010. opt.locale.format = "YYYY-MM-DD HH:mm";
  2011. opt.timePicker = true;
  2012. that.load(opt);
  2013. };
  2014. DateTime.prototype.dateSecond = function () {
  2015. var that = this//, o = that.options;
  2016. var opt = {locale: {}};
  2017. opt.locale.format = "YYYY-MM-DD HH:mm:SS";
  2018. opt.timePicker = true;
  2019. opt.timePickerSeconds = true;
  2020. that.load(opt);
  2021. };
  2022. DateTime.prototype.dataRange = function () {
  2023. var that = this, o = that.options;
  2024. var opt = {locale: {}};
  2025. opt.singleDatePicker = false;
  2026. that.load(opt);
  2027. };
  2028. DateTime.prototype.dataRangeTime = function () {
  2029. var that = this, o = that.options;
  2030. var opt = {locale: {}};
  2031. opt.locale.format = "YYYY-MM-DD HH:mm";
  2032. opt.timePicker = true;
  2033. opt.singleDatePicker = false;
  2034. that.load(opt);
  2035. };
  2036. DateTime.prototype.dataRangeSecond = function () {
  2037. var that = this, o = that.options;
  2038. var opt = {locale: {}};
  2039. opt.locale.format = "YYYY-MM-DD HH:mm:SS";
  2040. opt.singleDatePicker = false;
  2041. opt.timePicker = true;
  2042. opt.timePickerSeconds = true;
  2043. that.load(opt);
  2044. };
  2045. DateTime.prototype.load = function (opt) {
  2046. var that = this, o = that.options;
  2047. var option = $.extend({}, dateOpt, opt || {});
  2048. $(that.$ele).daterangepicker(option, function (start, end, label) {
  2049. console.log('Data-Change: ' + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD') + ' ( Range: ' + label + ')');
  2050. });
  2051. var cancelEvent = o.cancelEvent && o.cancelEvent.isFunction() ? o.cancelEvent : function () { $(that.$ele).val('')}
  2052. $(that.$ele).on('cancel.daterangepicker', cancelEvent);
  2053. if (o.applyEvent && o.applyEvent.isFunction()) {
  2054. $(that.$ele).on('apply.daterangepicker', o.applyEvent);
  2055. }
  2056. $(that.$ele).on('show.daterangepicker', function () {
  2057. //timeSelect2();
  2058. if (o.showEvent && o.showEvent.isFunction()) {
  2059. o.showEvent();
  2060. }
  2061. });
  2062. if (o.hideEvent && o.hideEvent.isFunction()) {
  2063. $(that.$ele).on('hide.daterangepicker', o.hideEvent);
  2064. }
  2065. if (o.showCalendarEvent && o.showCalendarEvent.isFunction()) {
  2066. $(that.$ele).on('showCalendar.daterangepicker', o.showCalendarEvent);
  2067. }
  2068. if (o.hideCalendarEvent && o.hideCalendarEvent.isFunction()) {
  2069. $(that.$ele).on('hideCalendar.daterangepicker', o.hideCalendarEvent);
  2070. }
  2071. $(that.$ele).val('');
  2072. };
  2073. DateTime.prototype.setStartDate = function (data) {
  2074. var that = this, o = that.options;
  2075. $(that.$ele).data('daterangepicker').setStartDate(data);
  2076. };
  2077. DateTime.prototype.setEndDate = function (data) {
  2078. var that = this, o = that.options;
  2079. $(that.$ele).data('daterangepicker').setEndDate(data);
  2080. };
  2081. var allowedMethods = [
  2082. 'date',
  2083. 'dateTime',
  2084. 'dateSecond',
  2085. 'dataRange',
  2086. 'dataRangeTime',
  2087. 'dataRangeSecond',
  2088. 'setStartDate',
  2089. 'setEndDate'
  2090. ];
  2091. $.fn.iwbDate = function (option) {
  2092. var value,
  2093. args = Array.prototype.slice.call(arguments, 1);
  2094. this.each(function () {
  2095. var $this = $(this);
  2096. var data = $this.data('iwb.date');
  2097. if (!data) {
  2098. data = new DateTime(this, option ? option : {});
  2099. $this.data('iwb.date', data);
  2100. data.init();
  2101. }
  2102. if (typeof option === 'string') {
  2103. if ($.inArray(option, allowedMethods) < 0) {
  2104. throw new Error("Unknown method: " + option);
  2105. }
  2106. value = data[option].apply(data, args);
  2107. } else if (option && option.method && typeof option.method === 'string') {
  2108. if ($.inArray(option.method, allowedMethods) < 0) {
  2109. throw new Error("Unknown method: " + option.method);
  2110. }
  2111. value = data[option.method].apply(data, args);
  2112. }
  2113. else {
  2114. if (!option && $this.hasClass('iwb-date')) {
  2115. data.date();
  2116. } else if ((!option || !option.method) && ($this.hasClass('iwb-date-time') || $this.hasClass('iwb-dateTime'))) {
  2117. data.dateTime();
  2118. } else if ((!option || !option.method) && ($this.hasClass('iwb-date-second') || $this.hasClass('iwb-dateSecond'))) {
  2119. data.dateSecond();
  2120. } else if ((!option || !option.method) && ($this.hasClass('iwb-date-range') || $this.hasClass('iwb-range-date'))) {
  2121. data.dataRange();
  2122. } else if ((!option || !option.method)&& ($this.hasClass('iwb-date-range-time') || $this.hasClass('iwb-range-dateTime'))) {
  2123. data.dataRangeTime();
  2124. } else if ((!option || !option.method) && ($this.hasClass('iwb-date-range-second') || $this.hasClass('iwb-range-dateSecond'))) {
  2125. data.dataRangeSecond();
  2126. } else {
  2127. data.load();
  2128. }
  2129. }
  2130. });
  2131. return typeof value === 'undefined' ? this : value;
  2132. };
  2133. $.fn.iwbDateRange = function (option) {
  2134. var value,
  2135. args = Array.prototype.slice.call(arguments, 1);
  2136. this.each(function () {
  2137. var $this = $(this);
  2138. var data = $this.data('iwb.rangeDate');
  2139. if (!data) {
  2140. data = new DateTime(this, option);
  2141. $this.data('iwb.rangeDate', data);
  2142. data.init();
  2143. data.dataRange();
  2144. }
  2145. if (typeof option === 'string') {
  2146. if ($.inArray(option, allowedMethods) < 0) {
  2147. throw new Error("Unknown method: " + option);
  2148. }
  2149. value = data[option].apply(data, args);
  2150. }
  2151. });
  2152. return typeof value === 'undefined' ? this : value;
  2153. };
  2154. $('.iwb-date-time').iwbDate();
  2155. $('.iwb-date').iwbDate();
  2156. })(jQuery, window, document);
  2157. /*Kindeditor*/
  2158. (function ($, window, document, undefined) {
  2159. 'use strict';
  2160. window.editor = {};
  2161. var Kindeditor = function (ele, opt) {
  2162. this.$ele = ele,
  2163. this.defaults = {
  2164. isModal: true,
  2165. tools: 'simpleTools',
  2166. resizeMode: 1,
  2167. width: '100%',
  2168. height: '300px',
  2169. bodyClass: 'article-content',
  2170. urlType: '',
  2171. uploadJson: '/system/KindEditorUploadFile',
  2172. filterMode: false,
  2173. allowFileManager: false,
  2174. langType: 'zh-CN',
  2175. cssData: 'html,body {background: none}.article-content, .article-content table td, .article-content table th {line-height: 1.3846153846; font-size: 13px;}.article-content .table-auto {width: auto!important; max-width: 100%;}',
  2176. placeholder: '请输入...',
  2177. placeholderStyle: { fontSize: '13px', color: '#888' },
  2178. pasteImage: { postUrl: '/system/KindEditorUploadFile', placeholder: "\u53ef\u4ee5\u5728\u7f16\u8f91\u5668\u76f4\u63a5\u8d34\u56fe\u3002" },
  2179. syncAfterBlur: true,
  2180. afterChange: function () { this.sync(); },
  2181. afterBlur: function () { this.sync(); },
  2182. spellcheck: false
  2183. },
  2184. this.options = $.extend({}, this.defaults, opt);
  2185. };
  2186. var bugTools =
  2187. ['formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', '|',
  2188. 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist', 'insertunorderedlist', '|',
  2189. 'emoticons', 'image', 'code', 'link', '|', 'removeformat', 'undo', 'redo', 'fullscreen', 'source', 'about'];
  2190. var simpleTools =
  2191. ['formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', '|',
  2192. 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist', 'insertunorderedlist', '|',
  2193. 'emoticons', 'image', 'code', 'link', 'table', '|', 'removeformat', 'undo', 'redo', 'fullscreen', 'source', 'about'];
  2194. var fullTools =
  2195. ['formatblock', 'fontname', 'fontsize', 'lineheight', '|', 'forecolor', 'hilitecolor', '|', 'bold', 'italic', 'underline', 'strikethrough', '|',
  2196. 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', '|',
  2197. 'insertorderedlist', 'insertunorderedlist', '|',
  2198. 'emoticons', 'image', 'insertfile', 'hr', '|', 'link', 'unlink', '/',
  2199. 'undo', 'redo', '|', 'selectall', 'cut', 'copy', 'paste', '|', 'plainpaste', 'wordpaste', '|', 'removeformat', 'clearhtml', 'quickformat', '|',
  2200. 'indent', 'outdent', 'subscript', 'superscript', '|',
  2201. 'table', 'code', '|', 'pagebreak', 'anchor', '|',
  2202. 'fullscreen', 'source', 'preview', 'about'];
  2203. var editorToolsMap = { fullTools: fullTools, simpleTools: simpleTools, bugTools: bugTools };
  2204. //var abp = window.abp || {};
  2205. Kindeditor.prototype.init = function (options) {
  2206. var that = this, o = that.options;
  2207. options = options || {};
  2208. $.metPageCss('/Content/Libs/kindeditor/themes/default/default.css', "dy-css-kindeditor");
  2209. $.metPageJs('/Content/Libs/kindeditor/kindeditor-all-min.js', "dy-js-kindeditor");
  2210. $.metPageJs('/Content/Libs/kindeditor/lang/zh-CN.js', "dy-js-kindeditor-zh-CN");
  2211. that.setKindeditor(options);
  2212. };
  2213. Kindeditor.prototype.setKindeditor = function (options) {
  2214. var that = this, o = that.options;
  2215. var $editor = $(that.$ele);
  2216. var editorId = $editor.attr('id');
  2217. options = options || {};
  2218. options = $.extend({}, o, $editor.data(), options);
  2219. if (editorId === undefined) {
  2220. editorId = 'kindeditor-' + Math.floor(Math.random() * 10000000);
  2221. $editor.attr('id', editorId);
  2222. }
  2223. var editorTool = editorToolsMap[o.tools] || simpleTools;
  2224. /* Remove fullscreen in modal. */
  2225. if (o.isModal) {
  2226. var newEditorTool = new Array();
  2227. var i;
  2228. for (i in editorTool) {
  2229. if (editorTool.hasOwnProperty(i)) {
  2230. if (editorTool[i] !== 'fullscreen') newEditorTool.push(editorTool[i]);
  2231. }
  2232. }
  2233. editorTool = newEditorTool;
  2234. }
  2235. $.extend(options,
  2236. {
  2237. items: editorTool,
  2238. placeholder: $editor.attr('placeholder') || options.placeholder || ''
  2239. });
  2240. try {
  2241. $editor.length && window.KindEditor && window.KindEditor.remove(editorId);
  2242. var editor = window.KindEditor.create('#' + editorId, options);
  2243. window.editor['#'] = window.editor[editorId] = editor;
  2244. return editor;
  2245. } catch (e) {
  2246. console.log('kindEditor', e);
  2247. return false;
  2248. }
  2249. };
  2250. Kindeditor.prototype.remove = function () {
  2251. var that = this, o = that.options;
  2252. var $editor = $(that.$ele);
  2253. var editorId = $editor.attr('id');
  2254. if (editorId && window.KindEditor) {
  2255. window.KindEditor.remove(editorId);
  2256. $editor.data('iwb.kindEditor', undefined);
  2257. }
  2258. };
  2259. var allowedMethods = [
  2260. 'init',
  2261. 'remove',
  2262. 'setKindeditor'
  2263. ];
  2264. $.fn.iwbKindeditor = function (option) {
  2265. var value,
  2266. args = Array.prototype.slice.call(arguments, 1);
  2267. this.each(function () {
  2268. var $this = $(this);
  2269. var data = $this.data('iwb.kindEditor');
  2270. if (!data) {
  2271. data = new Kindeditor(this, option);
  2272. $this.data('iwb.kindEditor', data);
  2273. data.init();
  2274. }
  2275. if (typeof option === 'string') {
  2276. if ($.inArray(option, allowedMethods) < 0) {
  2277. throw new Error("Unknown method: " + option);
  2278. }
  2279. value = data[option].apply(data, args);
  2280. }
  2281. });
  2282. return typeof value === 'undefined' ? this : value;
  2283. };
  2284. })(jQuery, window, document);