iwb.js 93 KB

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