iwb.js 124 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238
  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] && 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. var val = data[name];
  34. $select.val(val);
  35. if ($select.hasClass('ajax-select')) {
  36. window.ChangAjaxSelectValue($select, val);
  37. }
  38. }
  39. });
  40. $checkbox.each(function () {
  41. var input = $form.find($(this));
  42. var name = input.attr("name");
  43. if (data[name] !== "") {
  44. //console.log(array[name]);
  45. input.val(data[name] === "True" ||
  46. input.val(data[name]) === "1" ||
  47. input.val(data[name]) === "true");
  48. }
  49. });
  50. $radio.each(function () {
  51. var input = $form.find($(this));
  52. var name = input.attr("name");
  53. if (data[name] !== "") {
  54. //console.log(array[name]);
  55. $("input[name='" + name + "'][value='" + data[name] + "']").prop("checked", true);
  56. $("input[name='" + name + "'][value!='" + data[name] + "']").prop("checked", false);
  57. }
  58. });
  59. },
  60. //将form表单元素的值序列化成对象
  61. formSerialize: function ($form) {
  62. var disableEle = $form.find("[disabled]");
  63. disableEle.each(function (i, e) {
  64. $(e).prop("disabled", false);
  65. });
  66. var data = {};
  67. $.each($form.serializeArray(),
  68. function () {
  69. if (data[this['name']]) {
  70. data[this['name']] = data[this['name']] + "," + this['value'];
  71. } else {
  72. data[this['name']] = this['value'];
  73. }
  74. });
  75. disableEle.each(function (i, e) {
  76. $(e).prop("disabled", true);
  77. });
  78. return data;
  79. },
  80. //表单验证
  81. formValidate: function ($form, opt) {
  82. var defaults = {
  83. noValid: false,
  84. form: "form",
  85. modal: "modal",
  86. errorPlacement: function (error, element) {
  87. if (element.parent().parent().find('label.error').length === 0) {
  88. element.parent().after(error);
  89. }
  90. var $tab = element.closest('.form-auto-tab');
  91. if ($tab && $tab.length) {
  92. $("#" + $tab.data("tabid")).tab("show");
  93. }
  94. element.focus();
  95. },
  96. rules: {}
  97. };
  98. opt = opt || {};
  99. var options = $.extend({}, defaults, opt);
  100. var $modal = options.modal
  101. ? typeof (options.modal) === 'string'
  102. ? $('#' + options.modal)
  103. : $(options.modal)
  104. : null;
  105. $form = $form ? $form : options.form ? $(options.form) : $modal.find('form');
  106. $form.validate({
  107. errorPlacement: options.errorPlacement,
  108. rules: options.rules,
  109. ignore: ".ignore .iwb-wang-editor"
  110. });
  111. //.settings.ignore = ":disabled";
  112. if (!options.noValid) {
  113. var valid = $form.valid();
  114. console.log("FormValidate", $form.attr('id'), valid);
  115. return valid;
  116. }
  117. return options.noValid;
  118. },
  119. formatterDate: function (fmt, date, isFix) {
  120. date = date || new Date();
  121. isFix = isFix === undefined ? true : isFix;
  122. var year = date.getFullYear();
  123. var month = date.getMonth() + 1;
  124. fmt = fmt.replace("yyyy", year);
  125. fmt = fmt.replace("yy", year % 100);
  126. fmt = fmt.replace("MM", fix(month));
  127. fmt = fmt.replace("dd", fix(date.getDate()));
  128. fmt = fmt.replace("HH", fix(date.getHours()));
  129. fmt = fmt.replace("mm", fix(date.getMinutes()));
  130. fmt = fmt.replace("ss", fix(date.getSeconds()));
  131. return fmt;
  132. function fix(n) {
  133. return isFix ? (n < 10 ? "0" + n : n) : n;
  134. }
  135. },
  136. blinkTitle: {
  137. start: function (msg) {
  138. msg = msg || abp.localization.iwbZero('NewNotificationRemind');
  139. this.title = document.title;
  140. this.messages = [msg];
  141. if (!this.action) {
  142. try {
  143. this.element = document.getElementsByTagName('title')[0];
  144. this.element.innerHTML = this.title;
  145. this.action = function (ttl) {
  146. this.element.innerHTML = ttl;
  147. };
  148. } catch (e) {
  149. this.action = function (ttl) {
  150. document.title = ttl;
  151. };
  152. delete this.element;
  153. }
  154. this.toggleTitle = function () {
  155. this.index = this.index === 0 ? 1 : 0;
  156. this.action('【' + this.messages[this.index] + '】' + this.title);
  157. };
  158. }
  159. var n = msg.length;
  160. var s = '';
  161. if (this.element) {
  162. var num = msg.match(/\w/g);
  163. if (num) {
  164. var n2 = num.length;
  165. n -= n2;
  166. while (n2 > 0) {
  167. s += " ";
  168. n2--;
  169. }
  170. }
  171. }
  172. while (n > 0) {
  173. s += ' ';
  174. n--;
  175. }
  176. this.messages.push(s);
  177. this.index = 0;
  178. //this.title = this.title.replace("【" + msg + "】", "").replace("【" + s + "】", "");
  179. var that = this;
  180. this.timer = setInterval(function () {
  181. that.toggleTitle();
  182. }, 500);
  183. },
  184. stop: function () {
  185. if (this.timer) {
  186. clearInterval(this.timer);
  187. var t = this.title ? this.title : document.title;
  188. this.action(t);
  189. delete this.timer;
  190. delete this.messages;
  191. }
  192. }
  193. },
  194. metPageCss: function (url, id) {
  195. id = id || 'dy-css';
  196. if ($('#' + id).length > 0) {
  197. return;
  198. }
  199. var link = document.createElement('link');
  200. link.type = 'text/css';
  201. link.rel = 'stylesheet';
  202. link.id = id;
  203. link.href = url + '?v=' + Math.floor(Math.random() * 100000);
  204. var flag = document.getElementById('flag');
  205. var head = document.getElementsByTagName('head')[0];
  206. if (flag) {
  207. head.insertBefore(link, flag.nextSibling);
  208. } else {
  209. head.appendChild(link);
  210. }
  211. },
  212. metPageJs: function (src, id) {
  213. id = id || 'dy-js';
  214. if ($('#' + id).length > 0) {
  215. return;
  216. }
  217. var script = document.createElement('script');
  218. script.id = id;
  219. script.type = 'text/javascript';
  220. script.charset = 'UTF-8';
  221. script.src = src + '?v=' + Math.floor(Math.random() * 100000);
  222. $('head').append(script);
  223. },
  224. loadScript: function (url, loadCallback, failCallback) {
  225. /* UrlStates enum */
  226. var urlStates = {
  227. LOADING: 'LOADING',
  228. LOADED: 'LOADED',
  229. FAILED: 'FAILED'
  230. };
  231. /* UrlInfo class */
  232. function UrlInfo() {
  233. this.state = urlStates.LOADING;
  234. this.loadCallbacks = [];
  235. this.failCallbacks = [];
  236. }
  237. UrlInfo.prototype.succeed = function () {
  238. this.state = urlStates.LOADED;
  239. for (var i = 0; i < this.loadCallbacks.length; i++) {
  240. this.loadCallbacks[i]();
  241. }
  242. };
  243. UrlInfo.prototype.failed = function () {
  244. this.state = urlStates.FAILED;
  245. for (var i = 0; i < this.failCallbacks.length; i++) {
  246. this.failCallbacks[i]();
  247. }
  248. };
  249. UrlInfo.prototype.handleCallbacks = function (loadCallback, failCallback) {
  250. switch (this.state) {
  251. case urlStates.LOADED:
  252. loadCallback && loadCallback();
  253. break;
  254. case urlStates.FAILED:
  255. failCallback && failCallback();
  256. break;
  257. case urlStates.LOADING:
  258. this.addCallbacks(loadCallback, failCallback);
  259. break;
  260. }
  261. };
  262. UrlInfo.prototype.addCallbacks = function (loadCallback, failCallback) {
  263. loadCallback && this.loadCallbacks.push(loadCallback);
  264. failCallback && this.failCallbacks.push(failCallback);
  265. };
  266. var urlInfos = {};
  267. var loadScript = function (url, loadCallback, failCallback) {
  268. var urlInfo = urlInfos[url];
  269. if (urlInfo) {
  270. urlInfo.handleCallbacks(loadCallback, failCallback);
  271. return;
  272. }
  273. urlInfos[url] = urlInfo = new UrlInfo();
  274. urlInfo.addCallbacks(loadCallback, failCallback);
  275. $.getScript(url).done(function (script, textStatus) {
  276. urlInfo.succeed();
  277. }).fail(function (jqxhr, settings, exception) {
  278. urlInfo.failed();
  279. });
  280. };
  281. loadScript(url, loadCallback, failCallback);
  282. },
  283. //jsonTree 转成 array
  284. Json2Array: function (data, opts) {
  285. var defaults = {
  286. id: 'id',
  287. parentId: 'parentId',
  288. children: 'children'
  289. };
  290. var opt = $.extend({}, defaults, opts || {});
  291. var Json2ArrayChild = function (data, dataArray) {
  292. var newData = $.extend([], data);
  293. var children = data[opt.children];
  294. delete newData[opt.children];
  295. dataArray.push(newData);
  296. if (children && children.length > 0) {
  297. children.forEach(function (v) {
  298. Json2ArrayChild(v, dataArray);
  299. });
  300. }
  301. }
  302. var dataArray = [];
  303. var children = data[opt.children];
  304. var newData = $.extend([], data);
  305. delete newData[opt.children];
  306. dataArray.push(newData);
  307. if (children && children.length > 0) {
  308. children.forEach(function (v) {
  309. Json2ArrayChild(v, dataArray);
  310. });
  311. }
  312. return dataArray;
  313. },
  314. //array 转成 JsonTree
  315. Array2Json: function (dataArray, opts) {
  316. var defaults = {
  317. root: '',
  318. id: 'id',
  319. parentId: 'parentId',
  320. children: 'children'
  321. };
  322. var opt = $.extend({}, defaults, opts || {});
  323. var Json2DataChild = function (parentId, dataArray) {
  324. var children = dataArray.filter(function (v) {
  325. return v[opt.parentId] === parentId;
  326. });
  327. if (children && children.length > 0) {
  328. children.forEach(function (v) {
  329. v[opt.children] = Json2DataChild(v[opt.id], dataArray);
  330. });
  331. }
  332. return children;
  333. }
  334. var index = dataArray.findIndex(function (v) {
  335. return v[opt.parentId] === opt.root;
  336. });
  337. var dataJson = dataArray[index];
  338. dataJson[opt.children] = Json2DataChild(dataJson.id, dataArray);
  339. return dataJson;
  340. }
  341. });
  342. /*AJAX*/
  343. $.extend({
  344. //ajax
  345. iwbAjax: function (url, opt) {
  346. this.defaults = {
  347. async: true,
  348. type: "Post",
  349. contentType: 'application/json; charset=UTF-8',
  350. //contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
  351. data: null,
  352. dataFun: null,
  353. log: window.log,
  354. dataType: "json",
  355. isAlert: true,
  356. successAlert: false,
  357. isValidate: true,
  358. isRefresh: true,//默认刷新表格
  359. success: null,
  360. error: null,
  361. table: undefined,
  362. modal: undefined,
  363. form: undefined,
  364. errorPlacement: function (error, element) {
  365. element.parent().before(error);
  366. element.focus();
  367. },
  368. rules: {},
  369. blockUI: true
  370. };
  371. if (!opt) {
  372. opt = url;
  373. url = opt.url;
  374. }
  375. var options = $.extend({}, this.defaults, opt);
  376. var $table = !options.table ? undefined : typeof options.table === 'string' ? $('#' + options.table) : $(options.table);
  377. var $modal = !options.modal ? undefined : typeof options.modal === 'string' ? $('#' + options.modal) : $(options.modal);
  378. var $form = !options.form ? ($modal ? $modal.find("form") : undefined) : typeof options.form === 'string' ? $('#' + options.form) : $(options.form);
  379. var isValidated = true;
  380. if (options.isValidate && $form) {
  381. isValidated = $.formValidate($form);
  382. }
  383. if (isValidated) {
  384. if (options.dataFun !== null && typeof options.dataFun === 'function') {
  385. options.data = options.dataFun();
  386. } else {
  387. options.data = options.data ? (typeof options.data === 'function' ? options.data() : options.data) : $form ? $.formSerialize($form) : undefined;
  388. }
  389. var guid = Math.floor(Math.random() * 10000);
  390. var log = options.log;
  391. if (log) {
  392. console.log('[' + guid + ']url:' + url, 'data:', options.data);
  393. }
  394. var success = options.success && typeof options.success === 'function'
  395. ? function (res) {
  396. if (log) { console.log('[' + guid + ']', res); }
  397. options.success(res);
  398. if (options.isRefresh && $table) {
  399. $table.iwbTable('refresh', true);
  400. }
  401. if ($modal) {
  402. $modal.iwbModal('hide');
  403. }
  404. }
  405. : function (res) {
  406. if (log) { console.log('[' + guid + ']', res); }
  407. if (options.isRefresh && $table) {
  408. $table.iwbTable('refresh', true);
  409. }
  410. if ($modal) {
  411. $modal.iwbModal('hide');
  412. }
  413. };
  414. var ajaxSuccess = options.isAlert || options.successAlert ? function (res) { abp.message.success(abp.localization.iwbZero('OpSuccess')).done(success(res)); } : success;
  415. var data = typeof (options.data) === 'string' ? options.data : JSON.stringify(options.data);
  416. var ajaxOption = {
  417. url: url,
  418. async: options.async,
  419. type: options.type,
  420. contentType: options.contentType,
  421. data: data,
  422. dataType: options.dataType,
  423. success: ajaxSuccess,
  424. error: options.error,
  425. abpHandleError: options.isAlert,
  426. blockUI: options.blockUI
  427. };
  428. abp.ajax(ajaxOption);
  429. }
  430. }
  431. });
  432. $.extend({
  433. iwbAjax1: function (opt) {
  434. opt = $.extend({}, { isValidate: false }, opt);
  435. $.iwbAjax(opt);
  436. },
  437. iwbAjax2: function (opt) {
  438. opt = $.extend({}, { isAlert: false }, opt);
  439. $.iwbAjax(opt);
  440. },
  441. iwbAjax3: function (opt) {
  442. opt = $.extend({}, { isValidate: false, isAlert: false, blockUI: true }, opt);
  443. $.iwbAjax(opt);
  444. },
  445. iwbAjax4: function (opt) {
  446. opt = $.extend({}, { isValidate: false, isAlert: false, isRefresh: false, blockUI: true }, opt);
  447. $.iwbAjax(opt);
  448. },
  449. iwbAjax41: function (opt) {
  450. opt = $.extend({}, { isValidate: false, isAlert: false, isRefresh: false, blockUI: false }, opt);
  451. $.iwbAjax(opt);
  452. },
  453. iwbAjax5: function (opt) {
  454. opt = $.extend({}, { isValidate: false, isAlert: false, successAlert: true, isRefresh: false, blockUI: true }, opt);
  455. $.iwbAjax(opt);
  456. },
  457. iwbGet: function (opt) {
  458. opt = $.extend({}, { type: 'get', modal: null, form: null }, opt);
  459. $.iwbAjax4(opt);
  460. }
  461. });
  462. /*Table*/
  463. (function ($, window, document, undefined) {
  464. //构造函数
  465. 'use strict';
  466. var abp = window.abp || {},
  467. selectionRows = [],
  468. searchList = [],
  469. isSearching,
  470. modalDefaults = {
  471. modal: 'modal',
  472. modaltitle: '',
  473. data: null,
  474. form: null,
  475. errorPlacement: function (error, element) {
  476. if (element.is('select')) {
  477. if (!element.next().next().hasClass('error')) {
  478. element.next().after(error);
  479. element.focus();
  480. }
  481. } else {
  482. element.after(error);
  483. element.focus();
  484. }
  485. },
  486. rules: {},
  487. readonly: '',
  488. disabled: '',
  489. select2: true,
  490. select2tree: false,
  491. url: '',
  492. savebtn: null,
  493. save: null,
  494. success: null,
  495. shownBefore: null,
  496. shownAfter: null,
  497. draggable: false,
  498. searchValidate: true
  499. };
  500. //modalOptions = {};
  501. var getSearchList = function ($that) {
  502. var o = $that.options;
  503. var $searchForm = (typeof (o.searchForm) === 'string' ? $('#' + o.searchForm) : $(o.searchForm));
  504. searchList = [];
  505. if (o.searchFun && typeof o.searchFun === "function") {
  506. o.searchFun(searchList);
  507. }
  508. if (o.searchList && o.searchList.length > 0) {
  509. o.searchList.forEach(function (v) {
  510. if (v.KeyWords) {
  511. searchList.push(v);
  512. }
  513. });
  514. }
  515. if (!o.onlySearchList) {
  516. $searchForm.find('.KeyWords').each(function () {
  517. var $this = $(this), keyWords = $this.val();
  518. if (keyWords) {
  519. if ($this.hasClass('dataRange')) {
  520. try {
  521. var dates = keyWords.split(' - ');
  522. searchList.push({
  523. KeyWords: dates[0],
  524. KeyField: $this.data('field'),
  525. FieldType: $this.data('ftype'),
  526. ExpType: 4
  527. });
  528. if (dates.length === 2) {
  529. var dateArr = dates[1].split(' ')[0].split('-');
  530. var date = new Date(dateArr[0], dateArr[1] - 1, dateArr[2], 0, 0, 0);
  531. var newDate = new Date(date.getTime() + 24 * 60 * 60 * 1000 - 1);
  532. keyWords = $.formatterDate('yyyy-MM-dd HH:mm:ss', newDate);
  533. searchList.push({
  534. KeyWords: keyWords,
  535. KeyField: $this.data('field'),
  536. FieldType: $this.data('ftype'),
  537. ExpType: 5
  538. });
  539. }
  540. } catch (e) {
  541. console.log(e);
  542. }
  543. } else {
  544. searchList.push({
  545. KeyWords: keyWords,
  546. KeyField: $this.data('field'),
  547. FieldType: $this.data('ftype'),
  548. ExpType: $this.data('etype')
  549. });
  550. }
  551. }
  552. });
  553. }
  554. };
  555. var queryParams = function (params, $that) {
  556. var o = $that.options;
  557. getSearchList($that);
  558. var $searchForm = (typeof (o.searchForm) === 'string' ? $('#' + o.searchForm) : $(o.searchForm));
  559. var $keyWord = $searchForm.find('#keyWords');
  560. if (o.onlySearchList) {
  561. return {
  562. MaxResultCount: params.limit,
  563. SkipCount: params.offset,
  564. //sort: params.sort, //排序列名
  565. //sortOrder: params.order, //排位命令(desc,asc)
  566. sorting: params.sort ? params.sort + ' ' + params.order : '',
  567. SearchList: searchList
  568. };
  569. }
  570. return {
  571. MaxResultCount: params.limit,
  572. SkipCount: params.offset,
  573. sorting: params.sort ? params.sort + ' ' + params.order : '',
  574. keyField: $keyWord.data('field'),
  575. fieldType: $keyWord.data('ftype'),
  576. expType: $keyWord.data('etype'),
  577. keyWords: $keyWord.val(),
  578. SearchList: searchList
  579. };
  580. };
  581. var responseHandler = function (res) {
  582. if (res.success) {
  583. var data = JSON.parse('{"total":' +
  584. res.result.totalCount +
  585. ',"rows":' +
  586. JSON.stringify(res.result.items) +
  587. '}');
  588. if (selectionRows.length > 0) {
  589. data.rows.forEach(function (row) {
  590. row.state = selectionRows.findIndex(function (v) {
  591. return v.id === row.id;
  592. }) !== -1;
  593. });
  594. }
  595. console.log(data);
  596. return data;
  597. } else {
  598. console.log('Table load failed');
  599. if (res.error) {
  600. if (res.error.details) {
  601. return abp.message.error(res.error.details, res.error.message);
  602. } else {
  603. if (res.error.message && res.error.message.indexOf('登陆超时') >= 0) {
  604. return abp.message.error(res.error.message).done(function () {
  605. window.top.location.reload();
  606. });
  607. } else {
  608. return abp.message.error(res.error.message || abp.ajax.defaultError.message);
  609. }
  610. }
  611. }
  612. }
  613. return JSON.parse('{"total":0,"rows":[]}');
  614. };
  615. var responseHandlerNoPage = function (res) {
  616. if (res.success) {
  617. var data = res.result;
  618. console.log(data);
  619. return data;
  620. } else {
  621. console.log('Table load failed');
  622. if (res.error) {
  623. if (res.error.details) {
  624. return abp.message.error(res.error.details, res.error.message);
  625. } else {
  626. if (res.error.message && res.error.message.indexOf('登陆超时') >= 0) {
  627. return abp.message.error(res.error.message).done(function () {
  628. window.top.location.reload();
  629. });
  630. } else {
  631. return abp.message.error(res.error.message || abp.ajax.defaultError.message);
  632. }
  633. }
  634. }
  635. }
  636. return JSON.parse('[]');
  637. };
  638. var onAll = function (eName, eData, $that) {
  639. isSearching = false;
  640. var o = $that.options;
  641. var $table = (typeof (o.table) === 'string' ? $('#' + o.table) : $(o.table));
  642. $table.closest('.table-box').find('.tableTool .menu-btn[data-type^=\'btn\']')
  643. .prop('disabled', $table.bootstrapTable('getSelections').length !== 1);
  644. };
  645. var onLoadSuccess = function (data, $that) {
  646. //var o = $that.options;
  647. //var $table = (typeof (o.table) === 'string' ? $('#' + o.table) : $(o.table));
  648. // $table.find('.bs-checkbox').find('input').addClass('filled-in').after('<label></label');
  649. };
  650. //var isResetView = true;
  651. var onPostBody = function (data, $that) {
  652. var o = $that.options;
  653. $(document);
  654. var $table = (typeof (o.table) === 'string' ? $('#' + o.table) : $(o.table));
  655. $table.find("td.bs-checkbox").each(function () {
  656. var input = $(this).find('input');
  657. var $label = $('<span class="iwb-checkbox"></span>');
  658. $label.append(input);
  659. $label.append('<span></span>');
  660. $(this).html($label);
  661. });
  662. isSearching = false;
  663. var $tableTool = o.tableTool
  664. ? typeof (o.tableTool) === 'string'
  665. ? $table.closest('.table-box').find('#' + o.tableTool)
  666. : $table.closest('.table-box').find(o.tableTool)
  667. : $table.closest('.table-box').find('.btn-toolbar');
  668. $tableTool.find('.menu-btn').off('click.menubtn').on('click.menubtn',
  669. function () {
  670. var funs = $that.getFuns();
  671. var type = $(this).data('type');
  672. var index = type.lastIndexOf('_');
  673. type = index > -1 ? type.substr(index + 1) : type;
  674. var url = $(this).data('url') || "";
  675. funs[type] ? funs[type].call(this, url) : funs["none"].call(this);
  676. });
  677. abp.ui.clearBusy();
  678. $table.find('tr th').each(function () { $(this).css('text-align', 'center') });
  679. $table.find('tr td.iwb-tips').each(function () {
  680. var text = $(this).text();
  681. $(this).tooltip({ 'title': text, 'placement': 'bottom', 'container': 'body', 'delay': 800 });
  682. });
  683. //if (isResetView) {
  684. // isResetView = false;
  685. // $table.bootstrapTable('resetView');
  686. //}
  687. };
  688. var getModal = function (url, opt, title, type, $that) {
  689. var o = $that.options;
  690. var modalOptions = $.extend({}, modalDefaults, opt);
  691. var $table = typeof o.table === 'string' ? $('#' + o.table) : $(o.table);
  692. var $tableTool = o.tableTool
  693. ? typeof o.tableTool === 'string'
  694. ? $table.closest('.table-box').find('#' + o.tableTool)
  695. : $table.closest('.table-box').find(o.tableTool)
  696. : $table.closest('.table-box').find('.btn-toolbar');
  697. modalOptions.modaltitle = title;
  698. modalOptions.draggable = $that.options.modalDrag;
  699. if (!opt) {
  700. opt = !url || typeof url === "string" ? {} : url;
  701. }
  702. if (opt.hasOwnProperty("url")) {
  703. modalOptions.url = opt.url;
  704. } else if (typeof url === "string") {
  705. modalOptions.url = url;
  706. } else {
  707. modalOptions.url = $tableTool.find('.menu-btn[data-type=' + type + ']').data('url');
  708. modalOptions.url = modalOptions.url
  709. ? modalOptions.url
  710. : $tableTool.find('.menu-btn[data-type=_' + type + ']').data('url');
  711. }
  712. modalOptions.modal =
  713. typeof $that.options.modal === 'string' ? $("#" + $that.options.modal) : $($that.options.modal);
  714. modalOptions.table = $table;
  715. //modalOptions.type = type.toLowerCase().indexOf('btnupdate') === 0 ? 'put' : 'post';
  716. modalOptions.type = 'post';
  717. modalOptions = $.extend({}, modalOptions, opt);
  718. return modalOptions;
  719. };
  720. //选中事件操作数组
  721. var union = function (array, rows) {
  722. rows.forEach(function (row) {
  723. var index = selectionRows.findIndex(function (v) {
  724. return v.id === row.id;
  725. });
  726. if (index === -1) {
  727. array[array.length] = row;
  728. }
  729. });
  730. return array;
  731. };
  732. //取消选中事件操作数组
  733. var difference = function (array, rows) {
  734. rows.forEach(function (row) {
  735. var index = selectionRows.findIndex(function (v) {
  736. return v.id === row.id;
  737. });
  738. if (index !== -1) {
  739. array.splice(index, 1);
  740. }
  741. });
  742. return array;
  743. };
  744. var Table = function (ele, opt) {
  745. var $that = this;
  746. this.defaults = {
  747. url: undefined,
  748. table: undefined,
  749. tableTool: '',
  750. resetView: true,
  751. height: undefined,
  752. searchForm: 'search-form',
  753. searchList: [],
  754. searchFun: null,
  755. onlySearchList: false,
  756. searchValidate: true,
  757. queryParams: function (p) { return queryParams(p, $that); },
  758. onAll: function (e, d) { onAll(e, d, $that); },
  759. onLoadSuccess: function (d) { onLoadSuccess(d, $that); },
  760. onPostBody: function (d) { onPostBody(d, $that); },
  761. isPage: true,
  762. lang: 'zh-CN',
  763. funs: undefined,
  764. modal: 'modal',
  765. form: 'form',
  766. modalDrag: true,
  767. multipleSelect: false//多选保存分页数据
  768. };
  769. $that.options = $.extend({}, this.defaults, opt || {});
  770. if (!$that.options.onAll) {
  771. $that.options.onAll = function (e, d) {
  772. onAll(e, d, $that);
  773. };
  774. }
  775. this.$ele = ele,
  776. this.loadTable();
  777. return this;
  778. };
  779. Table.prototype.loadTable = function () {
  780. var $that = this;
  781. $that.options.maintainMetaData = $that.options.multipleSelect;
  782. $that.options.responseHandler = $that.options.responseHandler
  783. ? $that.options.responseHandler
  784. : $that.options.isPage
  785. ? responseHandler
  786. : responseHandlerNoPage;
  787. $.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales[$that.options.lang]);
  788. var o = $that.options;
  789. //searchList = o.searchList;
  790. getSearchList($that);
  791. var $table = (typeof (o.table) === 'string' ? $('#' + o.table) : $(o.table));
  792. $table.bootstrapTable($that.options);
  793. if (o.resetView) {
  794. var h = o.height ? o.height : $(window).height() - 150;
  795. $that.resetView(h);
  796. $(window).resize(function () {
  797. $that.resetView();
  798. });
  799. }
  800. if (o.multipleSelect) {
  801. selectionRows = [];
  802. var _ = { "union": union, "difference": difference };
  803. //绑定选中事件、取消事件、全部选中、全部取消
  804. $table.on('check.bs.table check-all.bs.table uncheck.bs.table uncheck-all.bs.table', function (e, rows) {
  805. rows = $.map(!$.isArray(rows) ? [rows] : rows, function (row) {
  806. return row;
  807. });
  808. var func = $.inArray(e.type, ['check', 'check-all']) > -1 ? 'union' : 'difference';
  809. selectionRows = _[func](selectionRows, rows);
  810. });
  811. }
  812. return this;
  813. };
  814. Table.prototype.refresh = function (isForce) {
  815. var $that = this;
  816. abp.ui.setBusy();
  817. setTimeout(function () { abp.ui.clearBusy(); isSearching = false; }, 5 * 1000);
  818. if (isSearching) {
  819. return;
  820. }
  821. isSearching = true;
  822. //getSearchList($that);
  823. //if (!isForce && searchList.length <= 0) {
  824. // console.log("Search-Multi-None");
  825. // return;
  826. //}
  827. var o = $that.options;
  828. var $searchForm = (typeof (o.searchForm) === 'string' ? $('#' + o.searchForm) : $(o.searchForm));
  829. var isValidated = true;
  830. if (o.searchValidate && $searchForm && $searchForm.length > 0) {
  831. isValidated = $.formValidate($searchForm);
  832. }
  833. if (isValidated) {
  834. var $table = (typeof (o.table) === 'string' ? $('#' + o.table) : $(o.table));
  835. selectionRows = [];
  836. $table.bootstrapTable('refresh', { silent: true });
  837. console.log("Search");
  838. } else {
  839. console.log("Search_Validate_Faild");
  840. }
  841. };
  842. Table.prototype.resetView = function (height) {
  843. var $that = this;
  844. var o = $that.options;
  845. var $table = (typeof (o.table) === 'string' ? $('#' + o.table) : $(o.table));
  846. $table.bootstrapTable('resetView', { height: height });
  847. };
  848. Table.prototype.destroy = function () {
  849. var $that = this;
  850. var o = $that.options;
  851. var $table = (typeof (o.table) === 'string' ? $('#' + o.table) : $(o.table));
  852. $table.bootstrapTable('destroy', { silent: true });
  853. };
  854. Table.prototype.getFuns = function () {
  855. var $that = this;
  856. $that.options.funs = $that.options.funs ||
  857. {
  858. btnCreate: function (url) { $that.defaultCreate(url); },
  859. btnUpdate: function (url) { $that.defaultUpdate(url); },
  860. btnDelete: function (url) { $that.defaultDelete(url); },
  861. btnSearch: function () { $that.refresh(true); },
  862. none: function () { console.log("No type"); }
  863. };
  864. return $that.options.funs;
  865. };
  866. Table.prototype.addFuns = function (key, fun) {
  867. var $that = this;
  868. var funs = $that.getFuns();
  869. funs[key] = fun;
  870. $that.options.funs = funs;
  871. };
  872. Table.prototype.defaultCreate = function (url, opt) {
  873. var $that = this;
  874. console.log("Add");
  875. opt = opt || {};
  876. var modalOptions = getModal(url, opt, abp.localization.iwbZero('OpCreate'), 'btnCreate', $that);
  877. var $modal = typeof modalOptions.modal === 'string' ? $('#' + modalOptions.modal) : $(modalOptions.modal);
  878. $modal.iwbModal(modalOptions);
  879. };
  880. Table.prototype.defaultUpdate = function (url, opt, row) {
  881. var $that = this;
  882. console.log("Update");
  883. var o = $that.options;
  884. var $table = (typeof (o.table) === 'string' ? $('#' + o.table) : $(o.table));
  885. opt = opt || {};
  886. row = row || opt.row || $table.bootstrapTable("getSelections")[0];
  887. if (row) {
  888. var modalOptions = getModal(url, opt, abp.localization.iwbZero('OpUpdate'), 'btnUpdate', $that);
  889. if (!modalOptions.data) {
  890. modalOptions.data = row;
  891. }
  892. var $modal = typeof (modalOptions.modal) === 'string' ? $('#' + modalOptions.modal) : $(modalOptions.modal);
  893. $modal.iwbModal(modalOptions);
  894. } else
  895. abp.message.warn(abp.localization.iwbZero('SelectRecordOperation'));
  896. };
  897. Table.prototype.defaultDelete = function (url, opt, row) {
  898. console.log("Delete");
  899. var $that = this;
  900. var o = $that.options;
  901. var $table = (typeof (o.table) === 'string' ? $('#' + o.table) : $(o.table));
  902. opt = opt || {};
  903. row = row || opt.row || $table.bootstrapTable("getSelections")[0];
  904. if (row) {
  905. var data = opt.data || { id: row.id };
  906. abp.message.confirm(abp.localization.iwbZero('DeleteConfirmContent'),
  907. abp.localization.iwbZero('DeleteConfirm'),
  908. function (isConfirmed) {
  909. if (isConfirmed) {
  910. $.iwbAjax({ table: $table, url: url + '?id=' + data.id, data: data, type: 'post', isValidate: false });
  911. }
  912. });
  913. } else
  914. abp.message.warn(abp.localization.iwbZero('SelectRecordOperation'));
  915. };
  916. Table.prototype.setSearchList = function (obj) {
  917. var $that = this;
  918. var o = $that.options;
  919. o.searchList = obj;
  920. };
  921. Table.prototype.getSelections = function () {
  922. var $that = this;
  923. var o = $that.options;
  924. if (o.multipleSelect) {
  925. return selectionRows;
  926. }
  927. var $table = (typeof (o.table) === 'string' ? $('#' + o.table) : $(o.table));
  928. return $table.bootstrapTable("getSelections");
  929. }
  930. Table.prototype.getAllSelections = function () {
  931. var $that = this;
  932. var o = $that.options;
  933. if (o.multipleSelect) {
  934. return selectionRows;
  935. }
  936. var $table = (typeof (o.table) === 'string' ? $('#' + o.table) : $(o.table));
  937. return $table.bootstrapTable("getAllSelections");
  938. }
  939. var allowedMethods = [
  940. 'loadTable',
  941. 'refresh',
  942. 'getFuns',
  943. 'defaultCreate',
  944. 'defaultUpdate',
  945. 'defaultDelete',
  946. 'resetView',
  947. 'destroy',
  948. 'setSearchList',
  949. 'getSelections',
  950. 'getAllSelections',
  951. ];
  952. $.fn.iwbTable = function (option) {
  953. var value,
  954. args = Array.prototype.slice.call(arguments, 1);
  955. this.each(function () {
  956. var $this = $(this);
  957. var data = $this.data('iwb.table'),
  958. options = $.extend({}, $this.data(),
  959. typeof option === 'object' && option);
  960. if (typeof option === 'string') {
  961. if ($.inArray(option, allowedMethods) < 0) {
  962. throw new Error("Unknown method: " + option);
  963. }
  964. if (!data) {
  965. return;
  966. }
  967. value = data[option].apply(data, args);
  968. if (option === 'destroy') {
  969. $this.removeData('iwb.table');
  970. $this.removeData('iwbtable.init');
  971. return;
  972. }
  973. }
  974. if ($this.data('iwbtable.init')) {
  975. return;
  976. }
  977. $this.data('iwbtable.init', true);
  978. if (!data) {
  979. data = new Table(this, options);
  980. $this.data('iwb.table', data);
  981. }
  982. });
  983. return typeof value === 'undefined' ? this : value;
  984. };
  985. })(jQuery, window, document);
  986. /*Modal*/
  987. (function ($, window, document, undefined) {
  988. 'use strict';
  989. var Modal = function (ele, opt) {
  990. this.$ele = ele,
  991. this.defaults = {
  992. modal: ele,
  993. modaltitle: '',
  994. data: null,
  995. dataFun: undefined,
  996. form: null,
  997. table: undefined,
  998. errorPlacement: function (error, element) {
  999. element.parent().before(error);
  1000. //if (element.is('select')) {
  1001. // if (!element.next().next().hasClass('error')) {
  1002. // element.next().after(error);
  1003. // element.focus();
  1004. // }
  1005. //} else {
  1006. // element.parent().before(error);
  1007. // element.focus();
  1008. //}
  1009. },
  1010. rules: {},
  1011. readonly: '',
  1012. disabled: '',
  1013. notClear: '',
  1014. select2: true,
  1015. select2tree: false,
  1016. url: '',
  1017. type: 'post',
  1018. savebtn: null,
  1019. save: null,
  1020. success: null,
  1021. shownBefore: null,
  1022. shownAfter: null,
  1023. isRefresh: true,
  1024. draggable: true,
  1025. backdrop: 'static',
  1026. keyboard: true,
  1027. kindeditorOption: {},
  1028. content: undefined,
  1029. ajaxSelect: true,
  1030. abp: window.abp
  1031. },
  1032. this.options = $.extend({}, this.defaults, opt);
  1033. this.draggable();
  1034. };
  1035. var select2Opt = window.select2DefaultOption || {};
  1036. //var abp = window.abp || {};
  1037. Modal.prototype.getModal = function () {
  1038. var $that = this;
  1039. var $modal = $that.options.modalId
  1040. ? $('#' + $that.options.modalId)
  1041. : typeof ($that.options.modal) === 'string'
  1042. ? $('#' + $that.options.modal)
  1043. : $($that.options.modal);
  1044. return $modal;
  1045. };
  1046. Modal.prototype.open = function () {
  1047. var $that = this;
  1048. var $modal = $that.getModal();
  1049. $modal.off('show.bs.modal.open').on('show.bs.modal.open',
  1050. function () {
  1051. $that.showBefore();
  1052. $that.init();
  1053. $that.initWangEditor();
  1054. $that.setData();
  1055. $that.setSelect2();
  1056. $that.initKindeditor();
  1057. $that.setWangEditorData();
  1058. $that.verticalCenter();
  1059. $that.bindSave();
  1060. $.formValidate($modal.find('form'), { noValid: true });
  1061. $that.showAfter();
  1062. });
  1063. $that.show2();
  1064. };
  1065. Modal.prototype.show = function () {
  1066. var $that = this;
  1067. var $modal = $that.getModal();
  1068. $modal.off('show.bs.modal.open').on('show.bs.modal.open',
  1069. function () {
  1070. $that.showBefore();
  1071. $that.initWangEditor();
  1072. $that.setData();
  1073. $that.setSelect2();
  1074. $that.initKindeditor();
  1075. $that.setWangEditorData();
  1076. $that.verticalCenter();
  1077. $.formValidate($modal.find('form'), { noValid: true });
  1078. $that.showAfter();
  1079. });
  1080. $that.show2();
  1081. };
  1082. Modal.prototype.show2 = function ($modal) {
  1083. var $that = this, o = $that.options;
  1084. $modal = $modal || $that.getModal();
  1085. $modal.modal({ backdrop: o.backdrop, keyboard: o.keyboard });
  1086. $modal.modal('show');
  1087. //$that.verticalCenter();
  1088. };
  1089. Modal.prototype.create = function (opts) {
  1090. var $that = this, o = $that.options = $.extend({}, $that.options, opts);
  1091. if (!o.modalId) {
  1092. if (o.modal) {
  1093. o.modalId = typeof (o.modal) === 'string' ? o.modal : $(o.modal).attr('id');
  1094. } else {
  1095. o.modalId = 'Modal_' + (Math.floor((Math.random() * 1000000))) + new Date().getTime();
  1096. }
  1097. }
  1098. if (o.modalSize === null) {
  1099. o.modalSize = "";
  1100. }
  1101. else if (!o.modalSize) {
  1102. o.modalSize = 'modal-lg';
  1103. }
  1104. if (o.width) {
  1105. o.widthStr = 'max-width:' + o.width + 'px';
  1106. }
  1107. var createContainer = function (modalId, modalSize, width) {
  1108. abp.ui.setBusy($("body"));
  1109. $that.removeContainer(modalId);
  1110. var containerId = modalId + 'Container';
  1111. return $('<div id="' + containerId + '" tabindex="-1"></div>')
  1112. .append(
  1113. '<div id="' + modalId + '" class="modal fade">' +
  1114. ' <div class="modal-dialog modal-dialog-centered ' + modalSize + '" style="' + width + '">' +
  1115. ' <div class="modal-content"></div>' +
  1116. ' </div>' +
  1117. '</div>'
  1118. ).appendTo('body');
  1119. };
  1120. var show = function () {
  1121. $('#' + o.modalId).off('show.bs.modal').on('show.bs.modal', function () {
  1122. $that.showBefore();
  1123. if (o.data) {
  1124. $that.setData();
  1125. }
  1126. $that.setSelect2();
  1127. $that.bindSave();
  1128. $.formValidate($('#' + o.modalId).find('form'), { noValid: true });
  1129. $that.showAfter();
  1130. });
  1131. $that.show2();
  1132. //$('#' + o.modalId).modal({ backdrop: o.backdrop, keyboard: o.keyboard }).modal('show');
  1133. abp.ui.clearBusy($("body"));
  1134. };
  1135. var $modalContent = createContainer(o.modalId, o.modalSize, o.widthStr).find('.modal-content');
  1136. if (o.viewUrl) {
  1137. $modalContent.load(o.viewUrl, o.args, function (response, status, xhr) {
  1138. if (status === "error") {
  1139. abp.message.warn(abp.localization.abpWeb('InternalServerError'));
  1140. return;
  1141. }
  1142. if (o.scriptUrl) {
  1143. $.loadScript(o.scriptUrl, function () {
  1144. show();
  1145. });
  1146. } else {
  1147. show();
  1148. }
  1149. });
  1150. } else if (o.content) {
  1151. $modalContent.append(o.content);
  1152. show();
  1153. } else if (o.modalBody) {
  1154. var modalHeader = o.modalHeader
  1155. ? modalHeader
  1156. : '<div class="modal-header"><h4 class="modal-title"><span class="modal-title-span">' +
  1157. (o.modaltitle ? o.modaltitle : "") +
  1158. '</span></h4><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button></div>';
  1159. var modalFooter = o.modalFooter
  1160. ? modalFooter
  1161. : '<div class="modal-footer" style="text-align: center;"><button type="button" class="btn btn-sm btn-outline-iwb waves-effect" data-dismiss="modal" style="min-width:100px;">取消</button><button type="button" class="btn btn-iwb btn-sm save-btn waves-effect" style="min-width:100px;">保存</button></div>';
  1162. $modalContent.append(modalHeader);
  1163. $modalContent.append(o.modalBody);
  1164. $modalContent.append(modalFooter);
  1165. show();
  1166. } else {
  1167. abp.ui.clearBusy($("body"));
  1168. return;
  1169. }
  1170. };
  1171. Modal.prototype.hide = function () {
  1172. var $that = this, o = $that.options;
  1173. var $modal = $that.getModal();
  1174. if (o.modalId) {
  1175. $that.removeContainer(o.modalId);
  1176. }
  1177. return $modal.modal('hide');
  1178. };
  1179. Modal.prototype.removeContainer = function (modalId) {
  1180. var containerId = modalId + 'Container';
  1181. var containerSelector = '#' + containerId;
  1182. var $container = $(containerSelector);
  1183. if ($container.length) {
  1184. $container.remove();
  1185. }
  1186. };
  1187. Modal.prototype.showBefore = function () {
  1188. var $that = this;
  1189. if ($that.options.shownBefore && typeof ($that.options.shownBefore) === 'function') {
  1190. $that.options.shownBefore($that);
  1191. }
  1192. };
  1193. Modal.prototype.showAfter = function () {
  1194. var $that = this;
  1195. if ($that.options.shownAfter && typeof ($that.options.shownAfter) === 'function') {
  1196. $that.options.shownAfter($that);
  1197. }
  1198. };
  1199. Modal.prototype.init = function () {
  1200. var $that = this;
  1201. var $modal = $that.getModal();
  1202. $that.clearOldVal();
  1203. $modal.find('input,select,textarea').removeClass('error valid not-clear');
  1204. $modal.find('input:not(.disabled),select:not(.disabled),textarea:not(.disabled)').prop('disabled', false);
  1205. $modal.find('input:not(.readonly),select:not(.readonly),textarea:not(.readonly)').prop('readonly', false);
  1206. $modal.find('label.error').remove();
  1207. $modal.find('.modal-title-span').html($that.options.modaltitle);
  1208. $that.setReadonly();
  1209. $that.setDisabled();
  1210. $that.cleanFile();
  1211. $modal.find('input:not(:disabled,[type=\'hidden\'],[readonly=\'readonly\']):first').focus();
  1212. };
  1213. Modal.prototype.clearOldVal = function () {
  1214. var $that = this;
  1215. var $modal = $that.getModal();
  1216. if ($that.options.notClear) {
  1217. var notClear = $that.options.notClear.split(',');
  1218. for (var i = 0; i < notClear.length; i++) {
  1219. if (notClear[i]) {
  1220. $modal.find('#' + notClear[i]).addClass('not-clear');
  1221. }
  1222. }
  1223. }
  1224. $modal.find('input:not(.not-clear),select:not(.not-clear),textarea:not(.not-clear)').val('');
  1225. };
  1226. Modal.prototype.setReadonly = function () {
  1227. var $that = this;
  1228. var $modal = $that.getModal();
  1229. if (!$that.options.readonly)
  1230. return;
  1231. var readonly = $that.options.readonly.split(',');
  1232. for (var i = 0; i < readonly.length; i++) {
  1233. if (readonly[i]) {
  1234. $modal.find('#' + readonly[i]).prop('readonly', true);
  1235. }
  1236. }
  1237. };
  1238. Modal.prototype.setDisabled = function () {
  1239. var $that = this;
  1240. var $modal = $that.getModal();
  1241. if (!$that.options.disabled)
  1242. return;
  1243. var disabled = $that.options.disabled.split(',');
  1244. for (var i = 0; i < disabled.length; i++) {
  1245. if (disabled[i]) {
  1246. $modal.find('#' + disabled[i]).prop('disabled', true);
  1247. }
  1248. }
  1249. };
  1250. Modal.prototype.setData = function () {
  1251. var $that = this;
  1252. var $modal = $that.getModal();
  1253. var $form = $that.options.form ? $($that.options.form) : $modal.find('form');
  1254. $('.ajax-select').addClass("set-value");
  1255. $.formDeserialize($form, $that.options.data);
  1256. };
  1257. Modal.prototype.setSelect2 = function () {
  1258. var $that = this;
  1259. var $modal = $that.getModal();
  1260. if ($that.options.select2) {
  1261. $modal.find("select").trigger('change');
  1262. $modal.find('select').off("change.ff").on("change.ff",
  1263. function () {
  1264. $(this).focus();
  1265. $(this).next(".error").remove();
  1266. $(this).blur();
  1267. });
  1268. }
  1269. if ($that.options.select2tree) {
  1270. var tree = $that.options.select2tree.split(',');
  1271. for (var i = 0; i < tree.length; i++) {
  1272. $modal.find('#' + tree[i]).select2tree();
  1273. }
  1274. }
  1275. };
  1276. Modal.prototype.initKindeditor = function () {
  1277. var $that = this;
  1278. var $modal = $that.getModal();
  1279. $modal.find('textarea.kindeditor').each(function (i, v) {
  1280. if ($(v).length && $.fn.iwbKindeditor) {
  1281. var val = $(v).val();
  1282. if ($(v).data("iwb.kindEditor")) {
  1283. $(v).iwbKindeditor('remove');
  1284. }
  1285. var option = $that.options.kindeditorOption || {};
  1286. $(v).iwbKindeditor(option);
  1287. window.editor_K[$(v).attr('id')].html(val);
  1288. }
  1289. });
  1290. };
  1291. Modal.prototype.initWangEditor = function () {
  1292. var $that = this;
  1293. var $modal = $that.getModal();
  1294. $modal.find('div.iwb-wang-editor').each(function (i, v) {
  1295. if ($(v).length && $.fn.iwbWangEditor) {
  1296. if (!$(v).data("iwb.WangEditor")) {
  1297. var option = $that.options.wangEditorOption || {};
  1298. $(v).iwbWangEditor(option);
  1299. }
  1300. }
  1301. });
  1302. };
  1303. Modal.prototype.setWangEditorData = function () {
  1304. var $that = this;
  1305. var $modal = $that.getModal();
  1306. $modal.find('div.iwb-wang-editor').each(function (i, v) {
  1307. if ($(v).length && $.fn.iwbWangEditor) {
  1308. if ($(v).data("iwb.WangEditor")) {
  1309. var val = $('#' + $(v).data('id')).val();
  1310. $(v).iwbWangEditor('setContent', val);
  1311. }
  1312. }
  1313. });
  1314. };
  1315. Modal.prototype.cleanFile = function () {
  1316. var $that = this;
  1317. var $modal = $that.getModal();
  1318. $modal.find('input[type="file"]').each(function (i, v) {
  1319. $(v).iwbFileUpload('cleanFile');
  1320. });
  1321. };
  1322. Modal.prototype.bindSave = function () {
  1323. var $that = this;
  1324. var $modal = $that.getModal();
  1325. var $saveBtn = $that.options.savebtn
  1326. ? $($that.options.savebtn)
  1327. : $modal.find('.save-btn').length > 0
  1328. ? $modal.find('.save-btn')
  1329. : $modal.find('.save').length > 0
  1330. ? $modal.find('.save')
  1331. : $modal.find('#save');
  1332. var opt = $that.getSaveOptions(), ajaxSelectFun;
  1333. if ($that.options.ajaxSelect) {
  1334. ajaxSelectFun = function () {
  1335. $modal.find('select.ajax-select').each(function () {
  1336. var $this = $(this);
  1337. var tKey = $this.data('table-key'),
  1338. cKey = $this.data('column-key'),
  1339. val = $this.val(),
  1340. name = $this.find("option[value='" + val + "']").text(), ran = Math.floor(Math.random() * 9999);
  1341. console.log('AjaxSelect[{4}]:{0}-{1}-{2}-{3}'.format(tKey, cKey, val, name, ran));
  1342. $.iwbAjax41({
  1343. url: abp.appUrl + "Query/AddAcInfo",
  1344. data: {
  1345. TableKey: tKey,
  1346. ColumnKey: cKey,
  1347. ValueKey: val,
  1348. NameKey: name
  1349. },
  1350. success: function (r) {
  1351. console.log('AjaxSelect[{0}]:Success'.format(ran));
  1352. }
  1353. });
  1354. });
  1355. }
  1356. }
  1357. var save = null;
  1358. if ($that.options.save && typeof ($that.options.save) === "function") {
  1359. save = function () { $that.options.save(opt); };
  1360. } else if ($that.options.url) {
  1361. save = function () { $.iwbAjax($that.options.url, opt); };
  1362. }
  1363. var saveFun =
  1364. function () {
  1365. if (save && $.isFunction(save)) {
  1366. save();
  1367. }
  1368. if (ajaxSelectFun && $.isFunction(ajaxSelectFun)) {
  1369. ajaxSelectFun();
  1370. }
  1371. }
  1372. $saveBtn.off('click.save').on('click.save', saveFun);
  1373. $modal.find('.modal-body input').keydown(function (e) {
  1374. if (e.which === 13) {
  1375. if (e.target.tagName.toLocaleLowerCase() === "textarea") {
  1376. e.stopPropagation();
  1377. } else {
  1378. e.preventDefault();
  1379. saveFun.call(this);
  1380. }
  1381. }
  1382. });
  1383. //var opt = $that.getSaveOptions();
  1384. //if ($that.options.save && typeof $that.options.save === "function") {
  1385. // $that.options.save(opt);
  1386. //} else {
  1387. // $.iwbAjax($that.options.url, opt);
  1388. //}
  1389. };
  1390. Modal.prototype.getSaveOptions = function () {
  1391. var $that = this;
  1392. var $modal = $that.getModal();
  1393. var $form = $that.options.form ? $($that.options.form) : $modal.find('form');
  1394. return {
  1395. url: $that.options.url,
  1396. type: $that.options.type,
  1397. success: $that.options.success,
  1398. form: $form,
  1399. data: null,
  1400. dataFun: $that.options.dataFun,
  1401. table: $that.options.table,
  1402. modal: $that.options.modal,
  1403. blockUI: $modal.find('.modal-content'),
  1404. isRefresh: $that.options.isRefresh
  1405. };
  1406. };
  1407. Modal.prototype.verticalCenter = function () {
  1408. var $that = this;
  1409. var $modal = $that.getModal();
  1410. $modal.css('display', 'block');
  1411. var topHeight = $(window).height() - $modal.find('.modal-dialog').height() - 150;
  1412. if (topHeight < 30) {
  1413. topHeight = 30;
  1414. }
  1415. $modal.find('.modal-dialog').animate({ 'marginTop': topHeight / 2 + "px" });
  1416. };
  1417. Modal.prototype.draggable = function () {
  1418. var $that = this;
  1419. var $modal = $that.getModal();
  1420. if ($that.options.draggable) {
  1421. //console.log('draggable');
  1422. $('.modal-header').css('cursor', 'move');
  1423. /** 拖拽模态框*/
  1424. var dragModal = {
  1425. mouseStartPoint: { 'left': 0, 'top': 0 },
  1426. mouseEndPoint: { 'left': 0, 'top': 0 },
  1427. mouseDragDown: false,
  1428. basePoint: { 'left': 0, 'top': 0 },
  1429. moveTarget: null,
  1430. topleng: 0
  1431. };
  1432. $modal.off('mousedown.drag').on('mousedown.drag',
  1433. '.modal-header',
  1434. function (e) {
  1435. //webkit内核和火狐禁止文字被选中
  1436. $('body').addClass('drag-select');
  1437. //ie浏览器禁止文字选中
  1438. document.body.onselectstart = document.body.ondrag = function () {
  1439. return false;
  1440. };
  1441. if ($(e.target).hasClass('close')) //点关闭按钮不能移动对话框
  1442. return;
  1443. dragModal.mouseDragDown = true;
  1444. dragModal.moveTargetHeader = $(this);
  1445. dragModal.moveTarget = $(this).closest('.modal-content');
  1446. dragModal.mouseStartPoint = { 'left': e.clientX, 'top': e.pageY };
  1447. dragModal.basePoint = dragModal.moveTarget.offset();
  1448. dragModal.topLeng = e.pageY - e.clientY;
  1449. });
  1450. $modal.off('mouseup.drag').on('mouseup.drag',
  1451. function () {
  1452. dragModal.mouseDragDown = false;
  1453. dragModal.moveTarget = undefined;
  1454. dragModal.mouseStartPoint = { 'left': 0, 'top': 0 };
  1455. dragModal.basePoint = { 'left': 0, 'top': 0 };
  1456. });
  1457. $modal.off('mousemove.drag').on('mousemove.drag',
  1458. function (e) {
  1459. if (!dragModal.mouseDragDown || dragModal.moveTarget === undefined) return;
  1460. var mousX = e.clientX;
  1461. var mousY = e.pageY;
  1462. if (mousX < 0) mousX = 0;
  1463. if (mousY < 0) mousY = 25;
  1464. dragModal.mouseEndPoint = { 'left': mousX, 'top': mousY };
  1465. var width = dragModal.moveTarget.width();
  1466. var height = dragModal.moveTargetHeader.height();
  1467. var clientWidth = document.body.clientWidth;
  1468. var clientHeight = document.body.clientHeight;
  1469. if (dragModal.mouseEndPoint.left < dragModal.mouseStartPoint.left - dragModal.basePoint.left) {
  1470. dragModal.mouseEndPoint.left = 0;
  1471. } else if (dragModal.mouseEndPoint.left >=
  1472. clientWidth - width + dragModal.mouseStartPoint.left - dragModal.basePoint.left) {
  1473. dragModal.mouseEndPoint.left = clientWidth - width - 38;
  1474. } else {
  1475. dragModal.mouseEndPoint.left =
  1476. dragModal.mouseEndPoint.left -
  1477. (dragModal.mouseStartPoint.left - dragModal.basePoint.left); //移动修正,更平滑
  1478. }
  1479. if (dragModal.mouseEndPoint.top - (dragModal.mouseStartPoint.top - dragModal.basePoint.top) <
  1480. dragModal.topLeng) {
  1481. dragModal.mouseEndPoint.top = dragModal.topLeng;
  1482. } else if (dragModal.mouseEndPoint.top - dragModal.topLeng >
  1483. clientHeight - height + dragModal.mouseStartPoint.top - dragModal.basePoint.top) {
  1484. dragModal.mouseEndPoint.top = clientHeight - height - 38 + dragModal.topLeng;
  1485. } else {
  1486. dragModal.mouseEndPoint.top = dragModal.mouseEndPoint.top -
  1487. (dragModal.mouseStartPoint.top - dragModal.basePoint.top);
  1488. }
  1489. dragModal.moveTarget.offset(dragModal.mouseEndPoint);
  1490. });
  1491. $(document).on('hidden.bs.modal',
  1492. '.modal',
  1493. function () {
  1494. $('.modal-content').css({ 'top': 0, 'left': 0 });
  1495. $('body').removeClass('drag-select');
  1496. document.body.onselectstart = document.body.ondrag = null;
  1497. });
  1498. } else {
  1499. $('.modal-header').css('cursor', 'default');
  1500. }
  1501. };
  1502. var allowedMethods = [
  1503. 'open',
  1504. 'show',
  1505. 'show2',
  1506. 'hide',
  1507. 'create'
  1508. ];
  1509. $.fn.iwbModal = function (option) {
  1510. var value,
  1511. args = Array.prototype.slice.call(arguments, 1);
  1512. this.each(function () {
  1513. var modal = new Modal(this, option);
  1514. if (typeof option === 'string') {
  1515. if ($.inArray(option, allowedMethods) < 0) {
  1516. throw new Error("Unknown method: " + option);
  1517. }
  1518. value = modal[option].apply(modal, args);
  1519. } else {
  1520. modal.open();
  1521. }
  1522. });
  1523. return typeof value === 'undefined' ? this : value;
  1524. };
  1525. })(jQuery, window, document);
  1526. /*FileUpload*/
  1527. (function ($, window, document, undefined) {
  1528. 'use strict';
  1529. var abp = window.abp || {};
  1530. var File = function (ele, opt) {
  1531. this.$ele = ele,
  1532. this.defaults = {
  1533. file: ele,
  1534. maxSize: 2,
  1535. isImage: true,
  1536. targetInfo: undefined,
  1537. targetName: "fileName",
  1538. targetExt: "fileExt",
  1539. callback: undefined,
  1540. abp: window.abp
  1541. },
  1542. this.options = $.extend({}, this.defaults, opt || {});
  1543. //var $that = this;
  1544. //$that.show();
  1545. };
  1546. File.prototype.getFile = function () {
  1547. var $that = this;
  1548. var $file = typeof ($that.options.file) === 'string' ? $('#' + $that.options.file) : $($that.options.file);
  1549. return $file;
  1550. };
  1551. File.prototype.show = function () {
  1552. var $that = this;
  1553. var $file = $that.getFile();
  1554. $file.off('change.file.check').on('change.file.check', function () {
  1555. $that.fileCheck($that);
  1556. });
  1557. $file.closest('.iwb-file ').removeClass("file-success").removeClass("file-error");
  1558. //return $file[0].click();
  1559. };
  1560. File.prototype.fileCheck = function ($that) {
  1561. var $file = $that.getFile();
  1562. if ($that.checkSize()) {
  1563. var fileName = $file.val().split("\\").pop();
  1564. $file.closest('.iwb-file ').addClass("file-success").find("label").text(fileName);
  1565. var file = document.getElementById($file.attr("id")).files[0];
  1566. $that.readFile(file);
  1567. if ($that.options.targetName && $that.options.targetName !== undefined) {
  1568. var name = fileName.substring(0, fileName.lastIndexOf("."));
  1569. if (!$that.options.targetName)
  1570. return;
  1571. var targetName = $that.options.targetName.split(',');
  1572. for (var i = 0; i < targetName.length; i++) {
  1573. $('#' + targetName[i]).val(name);
  1574. }
  1575. }
  1576. if ($that.options.targetExt && $that.options.targetExt !== undefined) {
  1577. var ext = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length);
  1578. if (!$that.options.targetExt)
  1579. return;
  1580. var targetExt = $that.options.targetExt.split(',');
  1581. for (var j = 0; j < targetExt.length; j++) {
  1582. $('#' + targetExt[j]).val(ext);
  1583. }
  1584. }
  1585. var callback = $that.options.callback;
  1586. if (callback && typeof (callback) === "function") {
  1587. callback(fileName, file);
  1588. }
  1589. } else {
  1590. var target = $that.options.targetInfo ? $that.options.targetInfo : $file.attr('id').replace('_file', '');
  1591. $('#' + target).closest('.iwb-file ').addClass("file-error").find("label").text(abp.localization.iwbZero('SelectFile'));
  1592. }
  1593. };
  1594. File.prototype.checkSize = function () {
  1595. var $that = this;
  1596. var $file = $that.getFile();
  1597. var maxsize = $that.options.maxSize * 1024 * 1024;
  1598. //var errMsg = "上传的附件文件不能超过" + $that.options.maxSize + "M。";
  1599. //var tipMsg = "您的浏览器暂不支持计算上传文件的大小,确保上传文件不要超过" + $that.options.maxSize + "M,建议使用IE、FireFox、Chrome浏览器。";
  1600. var errMsg = abp.localization.iwbZero('FileUploadErrorMsg', $that.options.maxSize);
  1601. var tipMsg = abp.localization.iwbZero('FileUploadTipMsg', $that.options.maxSize);
  1602. var browserCfg = {};
  1603. var ua = window.navigator.userAgent;
  1604. if (ua.indexOf("MSIE") >= 1) {
  1605. browserCfg.ie = true;
  1606. } else if (ua.indexOf("Firefox") >= 1) {
  1607. browserCfg.firefox = true;
  1608. } else if (ua.indexOf("Chrome") >= 1) {
  1609. browserCfg.chrome = true;
  1610. }
  1611. try {
  1612. var objFile = document.getElementById($file.attr("id"));
  1613. if (objFile.value === "") {
  1614. //layer.alert("请先选择上传文件", { icon: 7, title: "提示信息" });
  1615. return false;
  1616. }
  1617. var filesize;
  1618. if (browserCfg.firefox || browserCfg.chrome) {
  1619. filesize = objFile.files[0].size;
  1620. } else if (browserCfg.ie) {
  1621. var objImg = document.createElement("img");
  1622. objImg.id = "tempImg";
  1623. objImg.style.display = "none";
  1624. document.body.appendChild(objImg);
  1625. objImg.dynsrc = objFile.value;
  1626. filesize = objImg.fileSize;
  1627. } else {
  1628. $that.cleanFile();
  1629. abp.message.warn(tipMsg);
  1630. return false;
  1631. }
  1632. if (filesize === -1) {
  1633. $that.cleanFile();
  1634. abp.message.warn(tipMsg);
  1635. return false;
  1636. } else if (filesize > maxsize) {
  1637. $that.cleanFile();
  1638. abp.message.warn(errMsg);
  1639. return false;
  1640. } else {
  1641. return true;
  1642. }
  1643. } catch (e) {
  1644. $that.cleanFile();
  1645. abp.message.error(e);
  1646. return false;
  1647. }
  1648. };
  1649. File.prototype.readFile = function (file) {
  1650. //判断是否是图片类型
  1651. //console.log(file.type);
  1652. if (!file) {
  1653. return;
  1654. }
  1655. var $that = this;
  1656. var $file = $that.getFile();
  1657. if ($that.options.isImage && !/image\/\w+/.test(file.type)) {
  1658. abp.message.warn(abp.localization.iwbZero('FileUploadOnlyImage'));
  1659. return;
  1660. }
  1661. var reader = new FileReader();
  1662. reader.readAsDataURL(file);
  1663. reader.onload = function () {
  1664. var fileinfo = this.result.substring(this.result.indexOf(',') + 1);
  1665. console.log(fileinfo);
  1666. var target = $that.options.targetInfo ? $that.options.targetInfo : $file.attr('id').replace('_file', '');
  1667. $('#' + target).val(fileinfo);
  1668. };
  1669. };
  1670. File.prototype.cleanFile = function () {
  1671. var $that = this;
  1672. var $file = $that.getFile();
  1673. $file.closest('.iwb-file ').removeClass("file-success").removeClass("file-error").find("label").text(abp.localization.iwbZero('SelectFile'));
  1674. $file.closest('.iwb-file ').find('input').val('');
  1675. $file.after($file.clone().val(""));
  1676. $file.remove();
  1677. };
  1678. var allowedMethods = [
  1679. 'show',
  1680. 'readFile',
  1681. 'cleanFile',
  1682. 'fileCheck',
  1683. 'checkSize'
  1684. ];
  1685. $.fn.iwbFileUpload = function (option) {
  1686. var value,
  1687. args = Array.prototype.slice.call(arguments, 1);
  1688. this.each(function () {
  1689. var $this = $(this);
  1690. var data = $this.data('iwb.FileUpload');
  1691. if (!data) {
  1692. data = new File(this, option);
  1693. $this.data('iwb.FileUpload', data);
  1694. }
  1695. if (typeof option === 'string') {
  1696. if ($.inArray(option, allowedMethods) < 0) {
  1697. throw new Error("Unknown method: " + option);
  1698. }
  1699. value = data[option].apply(data, args);
  1700. } else {
  1701. data.show();
  1702. }
  1703. });
  1704. return typeof value === 'undefined' ? this : value;
  1705. };
  1706. })(jQuery, window, document);
  1707. /*FileOpenShow*/
  1708. (function ($, window, document, undefined) {
  1709. 'use strict';
  1710. var File = function (ele, opt) {
  1711. this.$ele = ele,
  1712. this.defaults = {
  1713. url: undefined,
  1714. type: 'img'
  1715. },
  1716. this.options = $.extend({}, this.defaults, opt);
  1717. if ($(this.$ele).data('type')) {
  1718. this.options.type = $(this.$ele).data('type');
  1719. }
  1720. if (!this.options.url) {
  1721. this.options.url = $(this.$ele).data('url');
  1722. }
  1723. if (this.options.url && this.options.url.indexOf("/") !== 0) {
  1724. this.options.url = "/" + this.options.url;
  1725. }
  1726. };
  1727. //var abp = window.abp || {};
  1728. File.prototype.show = function () {
  1729. var $that = this;
  1730. switch ($that.options.type) {
  1731. case 'img':
  1732. case 'image':
  1733. this.showImage();
  1734. break;
  1735. case 'office':
  1736. this.showOffice();
  1737. break;
  1738. default:
  1739. this.showFile();
  1740. return;
  1741. }
  1742. };
  1743. File.prototype.showImage = function () {
  1744. var $that = this;
  1745. $.metPageCss('/Content/Libs/viewer/viewer.min.css', "dy-css-viewer");
  1746. $.metPageJs('/Content/Libs/viewer/viewer.min.js', "dy-js-viewer");
  1747. if ($("#Img-Modal").length > 0) {
  1748. $("#Img-Modal").remove();
  1749. }
  1750. $("body").append(' <ul id="Img-Modal" style="display:none"><li><img src="' +
  1751. $that.options.url +
  1752. '" data-original="' +
  1753. $that.options.url +
  1754. '" alt="Picture" /></li></ul>');
  1755. var $image = $('#Img-Modal');
  1756. var options = {
  1757. // inline: true,
  1758. url: 'data-original',
  1759. button: true,
  1760. navbar: false,
  1761. title: false,
  1762. toolbar: false,
  1763. ready: function (e) {
  1764. console.log(e.type);
  1765. }
  1766. };
  1767. $image.on({
  1768. show: function (e) {
  1769. console.log(e.type);
  1770. },
  1771. hidden: function (e) {
  1772. $image.viewer('destroy');
  1773. $image.remove();
  1774. }
  1775. }).viewer(options);
  1776. $image.viewer("show");
  1777. $image.css("display", "none");
  1778. };
  1779. File.prototype.showOffice = function () {
  1780. var $that = this;
  1781. var url = 'http://ow365.cn/?i=17314&furl=http://' + window.location.host + $that.options.url;
  1782. $that.showFile(url);
  1783. };
  1784. File.prototype.showFile = function (url) {
  1785. var $that = this;
  1786. url = url || $that.options.url;
  1787. if ($('#File-Modal').length <= 0) {
  1788. $('body').append(
  1789. '<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>');
  1790. }
  1791. $('#File-Modal').find('.modal-body')
  1792. .html('<iframe src="' + url + '" width="100%"; style="min-height: calc(100vh - 200px);" frameborder="0"></iframe>');
  1793. $(document).off('click.download', '#File-Modal #download').on('click.download', '#File-Modal #download',
  1794. function () { $that.download(url) });
  1795. $('#File-Modal').iwbModal('show2');
  1796. };
  1797. File.prototype.download = function (url) {
  1798. var $that = this;
  1799. url = url || $that.options.url;
  1800. if ($('#tempLink-fd').length > 0) {
  1801. $('#tempLink-fd').remove();
  1802. }
  1803. $('body').append('<a id="tempLink-fd" href="' + url + '" style="display:none"></a>');
  1804. $('#tempLink-fd')[0].click();
  1805. $('#tempLink-fd').remove();
  1806. };
  1807. var allowedMethods = [
  1808. 'show',
  1809. 'download'
  1810. ];
  1811. $.fn.iwbFileShow = function (option) {
  1812. var value,
  1813. args = Array.prototype.slice.call(arguments, 1);
  1814. this.each(function () {
  1815. var $this = $(this);
  1816. var data = $this.data('iwb.FileShow');
  1817. if (!data || typeof option !== 'string') {
  1818. data = new File(this, option);
  1819. $this.data('iwb.FileShow', data);
  1820. }
  1821. if (typeof option === 'string') {
  1822. if ($.inArray(option, allowedMethods) < 0) {
  1823. throw new Error("Unknown method: " + option);
  1824. }
  1825. value = data[option].apply(data, args);
  1826. } else {
  1827. data.show();
  1828. }
  1829. });
  1830. return typeof value === 'undefined' ? this : value;
  1831. };
  1832. })(jQuery, window, document);
  1833. /*TreeView*/
  1834. (function ($, window, document, undefined) {
  1835. 'use strict';
  1836. var TreeView = function (ele, opt) {
  1837. var that = this;
  1838. var tempId = '';
  1839. var onNodeSelected = function (e, data, that) {
  1840. var o = that.options;
  1841. if (!data || !data[o.selectFiledName]) {
  1842. return;
  1843. }
  1844. var $input = (typeof (o.selectFiledInput) === 'string' ? $('#' + o.selectFiledInput) : $(o.selectFiledInput));
  1845. tempId = data[o.selectFiledName];
  1846. $input.val(tempId);
  1847. var $table = (typeof (o.table) === 'string' ? $('#' + o.table) : $(o.table));
  1848. $table.iwbTable('refresh', true);
  1849. };
  1850. var onNodeUnselected = function (e, data, that) {
  1851. var o = that.options;
  1852. var $input = (typeof (o.selectFiledInput) === 'string' ? $('#' + o.selectFiledInput) : $(o.selectFiledInput));
  1853. $input.val('');
  1854. var $table = (typeof (o.table) === 'string' ? $('#' + o.table) : $(o.table));
  1855. $table.iwbTable('refresh', true);
  1856. };
  1857. this.$ele = ele,
  1858. this.defaults = {
  1859. url: undefined,
  1860. data: undefined,
  1861. levels: 2,
  1862. emptyIcon: "iconfont icon-delete",
  1863. collapseIcon: 'iconfont icon-delete ',
  1864. expandIcon: 'iconfont icon-add',
  1865. selectedBackColor: '#563d7c',
  1866. onNodeSelected: function (e, d) {
  1867. onNodeSelected(e, d, that);
  1868. },
  1869. onNodeUnselected: function (e, d) {
  1870. onNodeUnselected(e, d, that);
  1871. },
  1872. table: 'table',
  1873. selectFiledName: 'id',
  1874. selectFiledInput: 'keyWords'
  1875. },
  1876. this.options = $.extend({}, this.defaults, opt);
  1877. };
  1878. //var abp = window.abp || {};
  1879. TreeView.prototype.init = function () {
  1880. var that = this, o = that.options;
  1881. $.metPageCss('/Content/Libs/bootstrap-treeview/bootstrap-treeview.min.css', "dy-css-treeview");
  1882. $.metPageJs('/Content/Libs/bootstrap-treeview/bootstrap-treeview.min.js', "dy-js-treeview");
  1883. if (o.data) {
  1884. that.loadTree();
  1885. } else if (o.url) {
  1886. that.postData();
  1887. }
  1888. };
  1889. TreeView.prototype.loadTree = function (data) {
  1890. var that = this, o = that.options;
  1891. var option = $.extend({}, o);
  1892. if (data) {
  1893. option.data = data;
  1894. }
  1895. $(that.$ele).treeview(option);
  1896. };
  1897. TreeView.prototype.postData = function (url) {
  1898. var that = this, o = that.options;
  1899. url = url || o.url;
  1900. $.iwbAjax({
  1901. url: window.appUrl + url,
  1902. isAlert: false,
  1903. isValidate: false,
  1904. isRefresh: false,
  1905. success: function (res) {
  1906. if (res) {
  1907. that.loadTree(res);
  1908. }
  1909. }
  1910. });
  1911. };
  1912. var allowedMethods = [
  1913. 'init'
  1914. ];
  1915. $.fn.iwbTreeView = function (option) {
  1916. var value,
  1917. args = Array.prototype.slice.call(arguments, 1);
  1918. this.each(function () {
  1919. var $this = $(this);
  1920. var data = $this.data('iwb.TreeView');
  1921. if (!data) {
  1922. data = new TreeView(this, option);
  1923. $this.data('iwb.TreeView', data);
  1924. data.init();
  1925. }
  1926. if (typeof option === 'string') {
  1927. if ($.inArray(option, allowedMethods) < 0) {
  1928. throw new Error("Unknown method: " + option);
  1929. }
  1930. value = data[option].apply(data, args);
  1931. }
  1932. });
  1933. return typeof value === 'undefined' ? this : value;
  1934. };
  1935. })(jQuery, window, document);
  1936. /*DateTime*/
  1937. (function ($, window, document, undefined) {
  1938. 'use strict';
  1939. var DateTime = function (ele, opt) {
  1940. this.$ele = ele,
  1941. this.defaults = {
  1942. language: 'zh-CN',
  1943. singleDatePicker: true,
  1944. dayStep: false,
  1945. opens: "center",
  1946. drops: "down",
  1947. format: "YYYY-MM-DD", //YYYY-MM-DD HH:MM:SS
  1948. showEvent: undefined,
  1949. showCalendarEvent: undefined,
  1950. hideEvent: undefined,
  1951. hideCalendarEvent: undefined,
  1952. applyEvent: undefined,
  1953. cancelEvent: undefined,
  1954. minDate: '2015-01-01',
  1955. maxDate: false,
  1956. showWeekNumbers: false,
  1957. showISOWeekNumbers: false,
  1958. timePicker: false,
  1959. timePicker24Hour: true,
  1960. timePickerIncrement: 5,
  1961. timePickerSeconds: false,
  1962. linkedCalendars: true,
  1963. showCustomRangeLabel: false,
  1964. alwaysShowCalendars: true,
  1965. autoApply: true,
  1966. autoUpdateInput: true,
  1967. buttonClasses: "btn btn-sm",
  1968. applyButtonClasses: "btn-success",
  1969. cancelClass: "btn-default",
  1970. startDate: undefined, //开始时间
  1971. endDate: undefined, //结束时间,
  1972. maxSpan: undefined,
  1973. locale: undefined,
  1974. ranges: undefined,
  1975. hasRange: false
  1976. },
  1977. this.options = $.extend({}, this.defaults, opt);
  1978. };
  1979. var dateOpt = {};
  1980. //var timeSelect2 = function () {
  1981. // $('.daterangepicker .calendar-time > select').select2();
  1982. //}
  1983. //var abp = window.abp || {};
  1984. DateTime.prototype.init = function () {
  1985. var that = this; var o = that.options;
  1986. $.metPageCss('/Content/Libs/bootstrap-daterangepicker/daterangepicker.css', "dy-css-daterangepicker");
  1987. $.metPageJs('/Content/Libs/bootstrap-daterangepicker/daterangepicker.js', "dy-js-daterangepicker");
  1988. var lang = o.language.toLowerCase();
  1989. if (lang === 'zh-hans') {
  1990. lang = 'zh-cn';
  1991. }
  1992. moment.locale(lang);
  1993. var localeName = {
  1994. applyLabel: 'Apply',
  1995. cancelLabel: 'Cancel',
  1996. fromLabel: "",
  1997. toLabel: "",
  1998. customRangeLabel: 'Custom Range',
  1999. daysOfWeek: moment.weekdaysMin(),
  2000. monthNames: moment.monthsShort()
  2001. },
  2002. ranges = {
  2003. 'Today': [moment(), moment()],
  2004. 'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
  2005. 'Last 7 Days': [moment().subtract(6, 'days'), moment()],
  2006. 'Last 30 Days': [moment().subtract(29, 'days'), moment()],
  2007. 'This Month': [moment().startOf('month'), moment().endOf('month')],
  2008. 'Last Month': [
  2009. moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')
  2010. ]
  2011. };
  2012. dateOpt = {
  2013. format: o.format, //YYYY-MM-DD HH:MM:SS
  2014. opens: o.opens,
  2015. startDate: o.startDate ? o.startDate : false,
  2016. endDate: o.endDate ? o.endDate : false,
  2017. singleDatePicker: o.singleDatePicker,
  2018. drops: o.drops,
  2019. minDate: o.minDate,
  2020. maxDate: o.maxDate,
  2021. showCustomRangeLabel: o.showCustomRangeLabel ? o.hasRange : o.showCustomRangeLabel,
  2022. linkedCalendars: o.linkedCalendars,
  2023. showWeekNumbers: o.showWeekNumbers,
  2024. showISOWeekNumbers: o.showISOWeekNumbers,
  2025. timePicker: o.timePicker,
  2026. timePicker24Hour: o.timePicker24Hour,
  2027. timePickerIncrement: o.timePickerIncrement,
  2028. timePickerSeconds: o.timePickerSeconds,
  2029. buttonClasses: o.buttonClasses,
  2030. applyButtonClasses: o.applyButtonClasses,
  2031. cancelClass: o.cancelClass,
  2032. autoApply: o.autoApply,
  2033. autoUpdateInput: o.autoUpdateInput,
  2034. alwaysShowCalendars: o.alwaysShowCalendars,
  2035. maxSpan: o.maxSpan ? o.maxSpan : o.dayStep ? {
  2036. days: o.dayStep
  2037. } : false,
  2038. locale: o.locale ? o.locale : {
  2039. direction: 'ltr',
  2040. format: o.format,
  2041. separator: " - ", //
  2042. applyLabel: localeName.applyLabel,
  2043. cancelLabel: localeName.cancelLabel,
  2044. fromLabel: localeName.fromLabel,
  2045. toLabel: localeName.toLabel,
  2046. customRangeLabel: localeName.customRangeLabel,
  2047. weekLabel: localeName.weekLabel,
  2048. daysOfWeek: localeName.daysOfWeek,
  2049. monthNames: localeName.monthNames,
  2050. firstDay: 1
  2051. },
  2052. ranges: !o.hasRange ? false : o.ranges ? o.ranges : ranges
  2053. };
  2054. };
  2055. DateTime.prototype.date = function () {
  2056. var that = this, o = that.options;
  2057. var opt = { locale: {} };
  2058. opt.locale.format = "YYYY-MM-DD";
  2059. that.load(opt);
  2060. };
  2061. DateTime.prototype.dateTime = function () {
  2062. var that = this//, o = that.options;
  2063. var opt = { locale: {} };
  2064. opt.locale.format = "YYYY-MM-DD HH:mm";
  2065. opt.timePicker = true;
  2066. that.load(opt);
  2067. };
  2068. DateTime.prototype.dateSecond = function () {
  2069. var that = this//, o = that.options;
  2070. var opt = { locale: {} };
  2071. opt.locale.format = "YYYY-MM-DD HH:mm:SS";
  2072. opt.timePicker = true;
  2073. opt.timePickerSeconds = true;
  2074. that.load(opt);
  2075. };
  2076. DateTime.prototype.dataRange = function () {
  2077. var that = this, o = that.options;
  2078. var opt = { locale: {} };
  2079. opt.singleDatePicker = false;
  2080. that.load(opt);
  2081. };
  2082. DateTime.prototype.dataRangeTime = function () {
  2083. var that = this, o = that.options;
  2084. var opt = { locale: {} };
  2085. opt.locale.format = "YYYY-MM-DD HH:mm";
  2086. opt.timePicker = true;
  2087. opt.singleDatePicker = false;
  2088. that.load(opt);
  2089. };
  2090. DateTime.prototype.dataRangeSecond = function () {
  2091. var that = this, o = that.options;
  2092. var opt = { locale: {} };
  2093. opt.locale.format = "YYYY-MM-DD HH:mm:SS";
  2094. opt.singleDatePicker = false;
  2095. opt.timePicker = true;
  2096. opt.timePickerSeconds = true;
  2097. that.load(opt);
  2098. };
  2099. DateTime.prototype.load = function (opt) {
  2100. var that = this, o = that.options;
  2101. var option = $.extend({}, dateOpt, opt || {});
  2102. $(that.$ele).daterangepicker(option, function (start, end, label) {
  2103. console.log('Data-Change: ' + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD') + ' ( Range: ' + label + ')');
  2104. });
  2105. var cancelEvent = o.cancelEvent && o.cancelEvent.isFunction() ? o.cancelEvent : function () { $(that.$ele).val('') }
  2106. $(that.$ele).on('cancel.daterangepicker', cancelEvent);
  2107. if (o.applyEvent && o.applyEvent.isFunction()) {
  2108. $(that.$ele).on('apply.daterangepicker', o.applyEvent);
  2109. }
  2110. $(that.$ele).on('show.daterangepicker', function () {
  2111. //timeSelect2();
  2112. if (o.showEvent && o.showEvent.isFunction()) {
  2113. o.showEvent();
  2114. }
  2115. });
  2116. if (o.hideEvent && o.hideEvent.isFunction()) {
  2117. $(that.$ele).on('hide.daterangepicker', o.hideEvent);
  2118. }
  2119. if (o.showCalendarEvent && o.showCalendarEvent.isFunction()) {
  2120. $(that.$ele).on('showCalendar.daterangepicker', o.showCalendarEvent);
  2121. }
  2122. if (o.hideCalendarEvent && o.hideCalendarEvent.isFunction()) {
  2123. $(that.$ele).on('hideCalendar.daterangepicker', o.hideCalendarEvent);
  2124. }
  2125. $(that.$ele).val('');
  2126. };
  2127. DateTime.prototype.setStartDate = function (data) {
  2128. var that = this, o = that.options;
  2129. $(that.$ele).data('daterangepicker').setStartDate(data);
  2130. };
  2131. DateTime.prototype.setEndDate = function (data) {
  2132. var that = this, o = that.options;
  2133. $(that.$ele).data('daterangepicker').setEndDate(data);
  2134. };
  2135. var allowedMethods = [
  2136. 'date',
  2137. 'dateTime',
  2138. 'dateSecond',
  2139. 'dataRange',
  2140. 'dataRangeTime',
  2141. 'dataRangeSecond',
  2142. 'setStartDate',
  2143. 'setEndDate'
  2144. ];
  2145. $.fn.iwbDate = function (option) {
  2146. var value,
  2147. args = Array.prototype.slice.call(arguments, 1);
  2148. this.each(function () {
  2149. var $this = $(this);
  2150. var data = $this.data('iwb.date');
  2151. if (!data) {
  2152. data = new DateTime(this, option ? option : {});
  2153. $this.data('iwb.date', data);
  2154. data.init();
  2155. }
  2156. if (typeof option === 'string') {
  2157. if ($.inArray(option, allowedMethods) < 0) {
  2158. throw new Error("Unknown method: " + option);
  2159. }
  2160. value = data[option].apply(data, args);
  2161. } else if (option && option.method && typeof option.method === 'string') {
  2162. if ($.inArray(option.method, allowedMethods) < 0) {
  2163. throw new Error("Unknown method: " + option.method);
  2164. }
  2165. value = data[option.method].apply(data, args);
  2166. }
  2167. else {
  2168. if (!option && $this.hasClass('iwb-date')) {
  2169. data.date();
  2170. } else if ((!option || !option.method) && ($this.hasClass('iwb-date-time') || $this.hasClass('iwb-dateTime'))) {
  2171. data.dateTime();
  2172. } else if ((!option || !option.method) && ($this.hasClass('iwb-date-second') || $this.hasClass('iwb-dateSecond'))) {
  2173. data.dateSecond();
  2174. } else if ((!option || !option.method) && ($this.hasClass('iwb-date-range') || $this.hasClass('iwb-range-date'))) {
  2175. data.dataRange();
  2176. } else if ((!option || !option.method) && ($this.hasClass('iwb-date-range-time') || $this.hasClass('iwb-range-dateTime'))) {
  2177. data.dataRangeTime();
  2178. } else if ((!option || !option.method) && ($this.hasClass('iwb-date-range-second') || $this.hasClass('iwb-range-dateSecond'))) {
  2179. data.dataRangeSecond();
  2180. } else {
  2181. data.load();
  2182. }
  2183. }
  2184. });
  2185. return typeof value === 'undefined' ? this : value;
  2186. };
  2187. $.fn.iwbDateRange = function (option) {
  2188. var value,
  2189. args = Array.prototype.slice.call(arguments, 1);
  2190. this.each(function () {
  2191. var $this = $(this);
  2192. var data = $this.data('iwb.rangeDate');
  2193. if (!data) {
  2194. data = new DateTime(this, option);
  2195. $this.data('iwb.rangeDate', data);
  2196. data.init();
  2197. data.dataRange();
  2198. }
  2199. if (typeof option === 'string') {
  2200. if ($.inArray(option, allowedMethods) < 0) {
  2201. throw new Error("Unknown method: " + option);
  2202. }
  2203. value = data[option].apply(data, args);
  2204. }
  2205. });
  2206. return typeof value === 'undefined' ? this : value;
  2207. };
  2208. $('.iwb-date-time').iwbDate();
  2209. $('.iwb-date').iwbDate();
  2210. })(jQuery, window, document);
  2211. /*Kindeditor*/
  2212. (function ($, window, document, undefined) {
  2213. 'use strict';
  2214. window.editor_K = {};
  2215. var Kindeditor = function (ele, opt) {
  2216. this.$ele = ele,
  2217. this.defaults = {
  2218. isModal: true,
  2219. tools: 'simpleTools',
  2220. resizeMode: 1,
  2221. width: '100%',
  2222. height: '300px',
  2223. bodyClass: 'article-content',
  2224. urlType: '',
  2225. uploadJson: '/system/KindEditorUploadFile',
  2226. filterMode: false,
  2227. allowFileManager: false,
  2228. langType: 'zh-CN',
  2229. 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%;}',
  2230. placeholder: '请输入...',
  2231. placeholderStyle: { fontSize: '13px', color: '#888' },
  2232. pasteImage: { postUrl: '/system/KindEditorUploadFile', placeholder: "\u53ef\u4ee5\u5728\u7f16\u8f91\u5668\u76f4\u63a5\u8d34\u56fe\u3002" },
  2233. syncAfterBlur: true,
  2234. afterChange: function () { this.sync(); },
  2235. afterBlur: function () { this.sync(); },
  2236. spellcheck: false
  2237. },
  2238. this.options = $.extend({}, this.defaults, opt);
  2239. };
  2240. var bugTools =
  2241. ['formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', '|',
  2242. 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist', 'insertunorderedlist', '|',
  2243. 'emoticons', 'image', 'code', 'link', '|', 'removeformat', 'undo', 'redo', 'fullscreen', 'source', 'about'];
  2244. var simpleTools =
  2245. ['formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', '|',
  2246. 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist', 'insertunorderedlist', '|',
  2247. 'emoticons', 'image', 'code', 'link', 'table', '|', 'removeformat', 'undo', 'redo', 'fullscreen', 'source', 'about'];
  2248. var fullTools =
  2249. ['formatblock', 'fontname', 'fontsize', 'lineheight', '|', 'forecolor', 'hilitecolor', '|', 'bold', 'italic', 'underline', 'strikethrough', '|',
  2250. 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', '|',
  2251. 'insertorderedlist', 'insertunorderedlist', '|',
  2252. 'emoticons', 'image', 'insertfile', 'hr', '|', 'link', 'unlink', '/',
  2253. 'undo', 'redo', '|', 'selectall', 'cut', 'copy', 'paste', '|', 'plainpaste', 'wordpaste', '|', 'removeformat', 'clearhtml', 'quickformat', '|',
  2254. 'indent', 'outdent', 'subscript', 'superscript', '|',
  2255. 'table', 'code', '|', 'pagebreak', 'anchor', '|',
  2256. 'fullscreen', 'source', 'preview', 'about'];
  2257. var editorToolsMap = { fullTools: fullTools, simpleTools: simpleTools, bugTools: bugTools };
  2258. //var abp = window.abp || {};
  2259. Kindeditor.prototype.init = function (options) {
  2260. var that = this, o = that.options;
  2261. options = options || {};
  2262. $.metPageCss('/Content/Libs/kindeditor/themes/default/default.css', "dy-css-kindeditor");
  2263. $.metPageJs('/Content/Libs/kindeditor/kindeditor-all-min.js', "dy-js-kindeditor");
  2264. $.metPageJs('/Content/Libs/kindeditor/lang/zh-CN.js', "dy-js-kindeditor-zh-CN");
  2265. that.setKindeditor(options);
  2266. };
  2267. Kindeditor.prototype.setKindeditor = function (options) {
  2268. var that = this, o = that.options;
  2269. var $editor = $(that.$ele);
  2270. var editorId = $editor.attr('id');
  2271. options = options || {};
  2272. options = $.extend({}, o, $editor.data(), options);
  2273. if (editorId === undefined) {
  2274. editorId = 'kindeditor-' + Math.floor(Math.random() * 10000000);
  2275. $editor.attr('id', editorId);
  2276. }
  2277. var editorTool = editorToolsMap[o.tools] || simpleTools;
  2278. /* Remove fullscreen in modal. */
  2279. if (o.isModal) {
  2280. var newEditorTool = new Array();
  2281. var i;
  2282. for (i in editorTool) {
  2283. if (editorTool.hasOwnProperty(i)) {
  2284. if (editorTool[i] !== 'fullscreen') newEditorTool.push(editorTool[i]);
  2285. }
  2286. }
  2287. editorTool = newEditorTool;
  2288. }
  2289. $.extend(options,
  2290. {
  2291. items: editorTool,
  2292. placeholder: $editor.attr('placeholder') || options.placeholder || ''
  2293. });
  2294. try {
  2295. $editor.length && window.KindEditor && window.KindEditor.remove(editorId);
  2296. var editor = window.KindEditor.create('#' + editorId, options);
  2297. window.editor_K['#'] = window.editor_K[editorId] = editor;
  2298. return editor;
  2299. } catch (e) {
  2300. console.log('kindEditor', e);
  2301. return false;
  2302. }
  2303. };
  2304. Kindeditor.prototype.remove = function () {
  2305. var that = this, o = that.options;
  2306. var $editor = $(that.$ele);
  2307. var editorId = $editor.attr('id');
  2308. if (editorId && window.KindEditor) {
  2309. window.KindEditor.remove(editorId);
  2310. $editor.data('iwb.kindEditor', undefined);
  2311. }
  2312. };
  2313. var allowedMethods = [
  2314. 'init',
  2315. 'remove',
  2316. 'setKindeditor'
  2317. ];
  2318. $.fn.iwbKindeditor = function (option) {
  2319. var value,
  2320. args = Array.prototype.slice.call(arguments, 1);
  2321. this.each(function () {
  2322. var $this = $(this);
  2323. var data = $this.data('iwb.kindEditor');
  2324. if (!data) {
  2325. data = new Kindeditor(this, option);
  2326. $this.data('iwb.kindEditor', data);
  2327. data.init();
  2328. }
  2329. if (typeof option === 'string') {
  2330. if ($.inArray(option, allowedMethods) < 0) {
  2331. throw new Error("Unknown method: " + option);
  2332. }
  2333. value = data[option].apply(data, args);
  2334. }
  2335. });
  2336. return typeof value === 'undefined' ? this : value;
  2337. };
  2338. })(jQuery, window, document);
  2339. /*wangEditor*/
  2340. (function ($, window, document, undefined) {
  2341. 'use strict';
  2342. window.editor_W = {};
  2343. var E, editor = undefined;
  2344. var WangEditor = function (ele, opt) {
  2345. this.$ele = ele,
  2346. this.defaults = {
  2347. dataId: undefined,
  2348. dataName: undefined,
  2349. showFullScreen: true,
  2350. menus: undefined,
  2351. //[
  2352. // 'head',
  2353. // 'bold',
  2354. // 'fontSize',
  2355. // 'fontName',
  2356. // 'italic',
  2357. // 'underline',
  2358. // 'strikeThrough',
  2359. // 'indent',
  2360. // 'lineHeight',
  2361. // 'foreColor',
  2362. // 'backColor',
  2363. // 'link',
  2364. // 'list',
  2365. // //'todo',
  2366. // 'justify',
  2367. // //'quote',
  2368. // //'emoticon',
  2369. // 'image',
  2370. // //'video',
  2371. // //'table',
  2372. // //'code',
  2373. // 'splitLine',
  2374. // 'undo',
  2375. // 'redo'
  2376. // ],
  2377. excludeMenus: undefined,
  2378. colors: undefined,
  2379. /*[
  2380. '#000000',
  2381. '#eeece0',
  2382. '#1c487f',
  2383. '#4d80bf'
  2384. ],*/
  2385. fontNames: undefined,
  2386. /*[
  2387. '黑体',
  2388. '仿宋',
  2389. '楷体',
  2390. '标楷体',
  2391. '华文仿宋',
  2392. '华文楷体',
  2393. '宋体',
  2394. '微软雅黑',
  2395. 'Arial',
  2396. 'Tahoma',
  2397. 'Verdana',
  2398. 'Times New Roman',
  2399. 'Courier New',
  2400. ],*/
  2401. lineHeights: undefined,
  2402. //['1', '1.15', '1.6', '2', '2.5', '3'],
  2403. pasteFilterStyle: false, //粘贴样式的过滤
  2404. pasteIgnoreImg: true, //来忽略粘贴的图片
  2405. pasteTextHandle: undefined, // 对粘贴的文本进行处理,然后返回处理后的结果
  2406. onchange: undefined,
  2407. onblur: function (ss) {
  2408. },
  2409. onfocus: function (ss) {
  2410. //console.log(ss);
  2411. },
  2412. linkImgCallback: undefined, // 插入网络图片的回调
  2413. onlineVideoCallback: undefined, // 自定义检查插入视频的回调
  2414. uploadImgServer: "", // 配置 server 接口地址
  2415. uploadImgMaxSize: 2 * 1024 * 1024, //限制大小 2M
  2416. uploadImgAccept: ['jpg', 'jpeg', 'png', 'gif', 'bmp'], //限制类型
  2417. uploadFileName: undefined, //自定义 fileName
  2418. uploadImgHeaders: undefined, //自定义 header
  2419. withCredentials: false, //跨域传递 cookie
  2420. customUploadImg: undefined, //自己实现上传图片
  2421. /*
  2422. function (resultFiles, insertImgFn) {
  2423. // resultFiles 是 input 中选中的文件列表
  2424. // insertImgFn 是获取图片 url 后,插入到编辑器的方法
  2425. // 上传图片,返回结果,将图片插入到编辑器中
  2426. insertImgFn(imgUrl)
  2427. }
  2428. */
  2429. uploadImgTimeout: 5 * 1000, //自定义 timeout 时间
  2430. uploadImgParams: undefined, //自定义上传参数
  2431. uploadImgHooks: undefined, //回调函数
  2432. /*
  2433. {
  2434. // 上传图片之前
  2435. before: function(xhr) {
  2436. console.log(xhr)
  2437. // 可阻止图片上传
  2438. return {
  2439. prevent: true,
  2440. msg: '需要提示给用户的错误信息'
  2441. }
  2442. },
  2443. // 图片上传并返回了结果,图片插入已成功
  2444. success: function(xhr) {
  2445. console.log('success', xhr)
  2446. },
  2447. // 图片上传并返回了结果,但图片插入时出错了
  2448. fail: function(xhr, editor, resData) {
  2449. console.log('fail', resData)
  2450. },
  2451. // 上传图片出错,一般为 http 请求的错误
  2452. error: function(xhr, editor, resData) {
  2453. console.log('error', xhr, resData)
  2454. },
  2455. // 上传图片超时
  2456. timeout: function(xhr) {
  2457. console.log('timeout')
  2458. },
  2459. // 图片上传并返回了结果,想要自己把图片插入到编辑器中
  2460. // 例如服务器端返回的不是 { errno: 0, data: [...] } 这种格式,可使用 customInsert
  2461. customInsert: function(insertImgFn, result) {
  2462. // result 即服务端返回的接口
  2463. console.log('customInsert', result)
  2464. // insertImgFn 可把图片插入到编辑器,传入图片 src ,执行函数即可
  2465. insertImgFn(result.data[0])
  2466. }
  2467. }
  2468. */
  2469. uploadImgMaxLength: 5, // 一次最多上传 5 个图片,
  2470. uploadImgShowBase64: true, // 可使用 base64 格式保存图片
  2471. showLinkImg: false, // 隐藏插入网络图片
  2472. },
  2473. this.options = $.extend({}, this.defaults, opt);
  2474. $.metPageJs('/Content/Libs/wangEditor/wangEditor.min.js', "dy-js-wangEditor");
  2475. E = window.wangEditor;
  2476. //this.init();
  2477. };
  2478. //var abp = window.abp || {};
  2479. WangEditor.prototype.init = function (options) {
  2480. var that = this, o = that.options;
  2481. options = options || {};
  2482. editor = new E(that.$ele);
  2483. that.$ele.form = $(that.$ele).closest('form');
  2484. that.createEditor(options);
  2485. };
  2486. WangEditor.prototype.createEditor = function (options) {
  2487. var that = this;
  2488. options = options || {};
  2489. var o = $.extend(true, {}, that.options, options);
  2490. var dataId = o.dataId || $(that.$ele).data('id');
  2491. if (dataId) {
  2492. var dataName = o.dataName || $(that.$ele).data('name') || dataId;
  2493. var $t = $('<input id="' + dataId + '" name="' + dataName + '" type="hidden" />');
  2494. $(that.$ele).before($t);
  2495. $t.on('change.editor', function () {
  2496. that.setContent($t.val());
  2497. });
  2498. o.onchange = function (html) {
  2499. // 监控变化,同步更新到 input
  2500. $t.val(html);
  2501. }
  2502. if (!o.excludeMenus) {
  2503. var menuStr = $(that.$ele).data('menu');
  2504. var menu = menuStr.split(',');
  2505. if (menu) {
  2506. editor.config.menus = menu;
  2507. }
  2508. }
  2509. }
  2510. var opt = $(that.$ele).data('opt');
  2511. if (!(typeof (opt) === "object" && Object.prototype.toString.call(opt).toLowerCase() === "[object object]")) {
  2512. try {
  2513. opt = opt ? JSON.parse(opt) : {};
  2514. } catch (e) {
  2515. console.log(e);
  2516. }
  2517. }
  2518. editor.config = $.extend({}, editor.config, o, opt || {});
  2519. if (editor.config.excludeMenus) {
  2520. editor.config.excludeMenus = o.excludeMenus;
  2521. }
  2522. if (!editor.config.excludeMenus && o.menus && $.isArray(o.menus)) {
  2523. editor.config.menus = o.menus;
  2524. }
  2525. if (o.colors && $.isArray(o.colors)) {
  2526. editor.config.colors = o.colors;
  2527. }
  2528. if (o.fontNames && $.isArray(o.fontNames)) {
  2529. editor.config.fontNames = o.fontNames;
  2530. }
  2531. if (o.lineHeights && $.isArray(o.lineHeights)) {
  2532. editor.config.lineHeights = o.lineHeights;
  2533. }
  2534. //var $editor = $(that.$ele);
  2535. //var editorId = $editor.attr('id');
  2536. //if (editorId === undefined) {
  2537. // editorId = 'wangEditor-' + Math.floor(Math.random() * 10000000);
  2538. // $editor.attr('id', editorId);
  2539. //}
  2540. editor.create();
  2541. //window.editor_W['#'] = window.editor_W[editorId] = editor;
  2542. }
  2543. WangEditor.prototype.setContent = function (txt) {
  2544. editor.txt.html(txt);
  2545. }
  2546. var allowedMethods = [
  2547. 'setContent'
  2548. ];
  2549. $.fn.iwbWangEditor = function (option) {
  2550. var value,
  2551. args = Array.prototype.slice.call(arguments, 1);
  2552. this.each(function () {
  2553. var $this = $(this);
  2554. var data = $this.data('iwb.WangEditor');
  2555. if (!data) {
  2556. data = new WangEditor(this, option);
  2557. $this.data('iwb.WangEditor', data);
  2558. data.init();
  2559. }
  2560. if (typeof option === 'string') {
  2561. if ($.inArray(option, allowedMethods) < 0) {
  2562. throw new Error("Unknown method: " + option);
  2563. }
  2564. value = data[option].apply(data, args);
  2565. }
  2566. });
  2567. return typeof value === 'undefined' ? this : value;
  2568. };
  2569. })(jQuery, window, document);
  2570. ; (function (window, document, $) {
  2571. //开启严格模式,规范代码,提高浏览器运行效率
  2572. "use strict"
  2573. var _global;
  2574. var progressTool = function (opt) {
  2575. var defaultOption = {
  2576. OutDom: undefined,
  2577. InnerDom: undefined,
  2578. OutDomCss: null,
  2579. InnerDomCss: null,
  2580. ScaleCss: null,
  2581. initValue: 0,
  2582. curValue: 0,
  2583. isShowValue: true,
  2584. ShowValueCss: {},
  2585. moveCallback: function (curScalePer, innerDom) { },
  2586. changeEndCall: function (curScalePer, innerDom, that) { }
  2587. }
  2588. $.extend(defaultOption, opt);
  2589. this.defaultOption = defaultOption;
  2590. $.metPageCss('/Content/Css/z_Progress.css', "dy-css-z_Progress"); //初始加载外部样式CSS
  2591. this.outDom = typeof defaultOption.OutDom === "string"
  2592. ? $("#" + defaultOption.OutDom)
  2593. : defaultOption.OutDom;
  2594. this.outDom.toggleClass('z_progress');
  2595. if (defaultOption.OutDomCss != null) {
  2596. this.outDom.css(defaultOption.OutDomCss);
  2597. }
  2598. this.outDom.html('');
  2599. var innerDomStr = '<div class="z_progress-bar"><div class="Scale"></div></div>';
  2600. this.outDom.append(innerDomStr);
  2601. if (defaultOption.isShowValue) {
  2602. this.outDom.append('<span class="showValue"></span>');
  2603. this.outDom.find('.showValue').css(defaultOption.ShowValueCss);
  2604. }
  2605. this.innerDom = this.outDom.find(".z_progress-bar");
  2606. if (defaultOption.InnerDomCss != null) {
  2607. this.innerDom.css(defaultOption.InnerDomCss);
  2608. }
  2609. this.scaleDom = this.innerDom.find('.Scale');
  2610. if (defaultOption.ScaleCss != null) {
  2611. this.scaleDom.css(defaultOption.ScaleCss);
  2612. }
  2613. this.scaleWidth = this.scaleDom.width();
  2614. this.curValue = defaultOption.initValue;
  2615. this.moveBeforeVal = this.curValue;
  2616. this.setValue(this.curValue);
  2617. this.bindEvent();
  2618. }
  2619. progressTool.prototype.bindEvent = function () {
  2620. var that = this;
  2621. var outDom = that.outDom;
  2622. var innerDom = that.innerDom;
  2623. var scaleDom = that.scaleDom;
  2624. var flag = false;
  2625. scaleDom.on({
  2626. mousedown: function () {
  2627. flag = true;
  2628. that.moveBeforeVal = that.curValue;
  2629. scaleDom.css('cursor', 'w-resize');
  2630. },
  2631. mouseup: function () {
  2632. flag = false;
  2633. scaleDom.css('cursor', 'default');
  2634. that.defaultOption.changeEndCall(that.curValue, innerDom, that);
  2635. }
  2636. });
  2637. outDom.on({
  2638. mousemove: function (e) {
  2639. if (!flag) {
  2640. return;
  2641. }
  2642. var innerLeftDis = innerDom.offset().left;
  2643. var maxLength = outDom.width() + innerLeftDis;
  2644. if (e.clientX <= maxLength && e.clientX >= innerLeftDis) {
  2645. var inWidth = (e.clientX - innerLeftDis);
  2646. that.change(inWidth);
  2647. }
  2648. },
  2649. mouseup: function () {
  2650. flag = false;
  2651. that.defaultOption.changeEndCall(that.curValue, innerDom, that);
  2652. }
  2653. });
  2654. }
  2655. progressTool.prototype.change = function (inWidth) {
  2656. var that = this;
  2657. var outDom = that.outDom;
  2658. var innerDom = that.innerDom;
  2659. var scaleDom = that.scaleDom;
  2660. var scaleWidth = that.scaleWidth;
  2661. var v = Math.round(inWidth / outDom.width() * 100);
  2662. if (v === 0) {
  2663. scaleDom.css('right', '-' + scaleWidth + 'px');
  2664. } else {
  2665. scaleDom.css('right', '0px');
  2666. }
  2667. innerDom.css("width", v + "%");
  2668. //$("#showValue").html(v + "%");
  2669. if (that.defaultOption.isShowValue) {
  2670. var showValue = that.outDom.find('.showValue');
  2671. showValue.html(v + "%");
  2672. }
  2673. that.curValue = v;
  2674. that.defaultOption.moveCallback(v, innerDom);
  2675. }
  2676. progressTool.prototype.setValue = function (v) {
  2677. var that = this;
  2678. if (v === 0) {
  2679. that.scaleDom.css('right', '-' + that.scaleWidth + 'px');
  2680. } else {
  2681. that.scaleDom.css('right', '0px');
  2682. }
  2683. if (that.defaultOption.isShowValue) {
  2684. var showValue = that.outDom.find('.showValue');
  2685. showValue.html(v + "%");
  2686. }
  2687. that.innerDom.css("width", v + "%");
  2688. that.curValue = v;
  2689. //that.defaultOption.moveCallback(v);
  2690. }
  2691. progressTool.prototype.getValue = function () {
  2692. var that = this;
  2693. return that.curValue;
  2694. }
  2695. progressTool.prototype.invokeCallBack = function () {
  2696. var that = this;
  2697. that.defaultOption.moveCallback(that.curValue, that.innerDom);
  2698. }
  2699. _global = (function () {
  2700. return this || (0, eval)('this');
  2701. }());
  2702. if (typeof module !== "undefined" && module.exports) {
  2703. module.exports = progressTool;
  2704. } else if (typeof define === "function" && define.amd) {
  2705. define(function () {
  2706. return progressTool;
  2707. });
  2708. } else {
  2709. !('progressTool' in _global) && (_global.progressTool = progressTool);
  2710. }
  2711. })(window, document, $);
  2712. $.AdminBSB = {};
  2713. $.AdminBSB.options = {
  2714. colors: {
  2715. red: '#F44336',
  2716. pink: '#E91E63',
  2717. purple: '#9C27B0',
  2718. deepPurple: '#673AB7',
  2719. indigo: '#3F51B5',
  2720. blue: '#2196F3',
  2721. lightBlue: '#03A9F4',
  2722. cyan: '#00BCD4',
  2723. teal: '#009688',
  2724. green: '#4CAF50',
  2725. lightGreen: '#8BC34A',
  2726. lime: '#CDDC39',
  2727. yellow: '#ffe821',
  2728. amber: '#FFC107',
  2729. orange: '#FF9800',
  2730. deepOrange: '#FF5722',
  2731. brown: '#795548',
  2732. grey: '#9E9E9E',
  2733. blueGrey: '#607D8B',
  2734. black: '#000000',
  2735. white: '#ffffff'
  2736. },
  2737. leftSideBar: {
  2738. scrollColor: 'rgba(0,0,0,0.5)',
  2739. scrollWidth: '4px',
  2740. scrollAlwaysVisible: false,
  2741. scrollBorderRadius: '0',
  2742. scrollRailBorderRadius: '0',
  2743. scrollActiveItemWhenPageLoad: true,
  2744. breakpointWidth: 1170
  2745. },
  2746. dropdownMenu: {
  2747. effectIn: 'fadeIn',
  2748. effectOut: 'fadeOut'
  2749. }
  2750. };
  2751. /* Left Sidebar - Function =================================================================================================
  2752. * You can manage the left sidebar menu options
  2753. *
  2754. */
  2755. $.AdminBSB.leftSideBar = {
  2756. activate: function () {
  2757. var that = this;
  2758. var $body = $('body');
  2759. var $overlay = $('.overlay');
  2760. //Close sidebar
  2761. $(window).click(function (e) {
  2762. var $target = $(e.target);
  2763. if (e.target.nodeName.toLowerCase() === 'i') {
  2764. $target = $(e.target).parent();
  2765. }
  2766. if (!$target.hasClass('bars') && that.isOpen() && $target.parents('#left-sidebar').length === 0) {
  2767. //if (!$target.hasClass('js-right-sidebar'))
  2768. // $overlay.fadeOut();
  2769. $body.removeClass('overlay-open');
  2770. }
  2771. });
  2772. $.each($('.menu-toggle.toggled'), function (i, val) {
  2773. $(val).next().slideToggle(0);
  2774. });
  2775. //When page load
  2776. $.each($('.menu .list li.active'), function (i, val) {
  2777. var $activeAnchors = $(val).find('a:eq(0)');
  2778. var $parentAnchors = $(val).parentsUntil('.menu .list', 'li').children('a:first-child');
  2779. $activeAnchors = $activeAnchors.add($parentAnchors);
  2780. $activeAnchors.addClass('toggled');
  2781. $activeAnchors.next().show();
  2782. });
  2783. //Collapse or Expand Menu
  2784. $('.menu-toggle').on('click', function (e) {
  2785. var $this = $(this);
  2786. var $content = $this.next();
  2787. if ($($this.parents('ul')[0]).hasClass('list')) {
  2788. var $not = $(e.target).hasClass('menu-toggle') ? e.target : $(e.target).parents('.menu-toggle');
  2789. $.each($('.menu-toggle.toggled').not($not).next(), function (i, val) {
  2790. if ($(val).is(':visible')) {
  2791. $(val).prev().toggleClass('toggled');
  2792. $(val).slideUp();
  2793. }
  2794. });
  2795. }
  2796. $this.toggleClass('toggled');
  2797. $content.slideToggle(320);
  2798. });
  2799. //Set menu height
  2800. that.setMenuHeight();
  2801. that.checkStatuForResize(true);
  2802. $(window).resize(function () {
  2803. that.setMenuHeight();
  2804. that.checkStatuForResize(false);
  2805. });
  2806. //Set Waves
  2807. var theme = "block";
  2808. var bodyClassName = $body.prop('className');
  2809. if (bodyClassName) {
  2810. var classArray = bodyClassName.split(' ');
  2811. for (var j = 0; j < classArray.length; j++) {
  2812. if (classArray[j].indexOf('theme') === 0) {
  2813. theme = classArray[j].split('-')[1];
  2814. break;
  2815. }
  2816. }
  2817. }
  2818. Waves.attach('.menu .list a', ['waves-' + theme]);
  2819. Waves.init();
  2820. },
  2821. setMenuHeight: function (isFirstTime) {
  2822. if (typeof $.fn.slimScroll != 'undefined') {
  2823. var configs = $.AdminBSB.options.leftSideBar;
  2824. var height = ($(window).height() - ($('.legal').outerHeight() + $('.user-info').outerHeight() + $('.navbar').innerHeight()));
  2825. var $el = $('.list');
  2826. $el.slimscroll({
  2827. height: height + "px",
  2828. color: configs.scrollColor,
  2829. size: configs.scrollWidth,
  2830. alwaysVisible: configs.scrollAlwaysVisible,
  2831. borderRadius: configs.scrollBorderRadius,
  2832. railBorderRadius: configs.scrollRailBorderRadius
  2833. });
  2834. //Scroll active menu item when page load, if option set = true
  2835. if ($.AdminBSB.options.leftSideBar.scrollActiveItemWhenPageLoad) {
  2836. var $activeItem = $('.menu .list li.active');
  2837. if ($activeItem.length) {
  2838. var activeItemOffsetTop = $activeItem[0].offsetTop;
  2839. if (activeItemOffsetTop > 150) $el.slimscroll({ scrollTo: activeItemOffsetTop + 'px' });
  2840. }
  2841. }
  2842. }
  2843. },
  2844. checkStatuForResize: function (firstTime) {
  2845. var $body = $('body');
  2846. // var $openCloseBar = $('.navbar .navbar-header .bars');
  2847. var width = $body.width();
  2848. if (firstTime) {
  2849. $body.find('.content, .sidebar').addClass('no-animate').delay(1000).queue(function () {
  2850. $(this).removeClass('no-animate').dequeue();
  2851. });
  2852. }
  2853. if (width < $.AdminBSB.options.leftSideBar.breakpointWidth) {
  2854. $body.addClass('ls-closed');
  2855. //$openCloseBar.fadeIn();
  2856. }
  2857. else {
  2858. $body.removeClass('ls-closed');
  2859. //$openCloseBar.fadeOut();
  2860. }
  2861. },
  2862. isOpen: function () {
  2863. return $('body').hasClass('overlay-open');
  2864. }
  2865. };
  2866. //==========================================================================================================================
  2867. /* Right Sidebar - Function ================================================================================================
  2868. * You can manage the right sidebar menu options
  2869. *
  2870. */
  2871. $.AdminBSB.rightSideBar = {
  2872. activate: function () {
  2873. var _this = this;
  2874. var $sidebar = $('#rightsidebar');
  2875. var $overlay = $('.overlay');
  2876. //Close sidebar
  2877. $(window).click(function (e) {
  2878. var $target = $(e.target);
  2879. if (e.target.nodeName.toLowerCase() === 'i') { $target = $(e.target).parent(); }
  2880. if (!$target.hasClass('js-right-sidebar') && _this.isOpen() && $target.parents('#rightsidebar').length === 0) {
  2881. if (!$target.hasClass('bars')) $overlay.fadeOut();
  2882. $sidebar.removeClass('open');
  2883. }
  2884. });
  2885. $('.js-right-sidebar').on('click', function () {
  2886. $sidebar.toggleClass('open');
  2887. if (_this.isOpen()) { $overlay.fadeIn(); } else { $overlay.fadeOut(); }
  2888. });
  2889. },
  2890. isOpen: function () {
  2891. return $('.right-sidebar').hasClass('open');
  2892. }
  2893. }
  2894. //==========================================================================================================================
  2895. /* Searchbar - Function ================================================================================================
  2896. * You can manage the search bar
  2897. *
  2898. */
  2899. var $searchBar = $('.search-bar');
  2900. $.AdminBSB.search = {
  2901. activate: function () {
  2902. var _this = this;
  2903. //Search button click event
  2904. $('.js-search').on('click', function () {
  2905. _this.showSearchBar();
  2906. });
  2907. //Close search click event
  2908. $searchBar.find('.close-search').on('click', function () {
  2909. _this.hideSearchBar();
  2910. });
  2911. //ESC key on pressed
  2912. $searchBar.find('input[type="text"]').on('keyup', function (e) {
  2913. if (e.keyCode == 27) {
  2914. _this.hideSearchBar();
  2915. }
  2916. });
  2917. },
  2918. showSearchBar: function () {
  2919. $searchBar.addClass('open');
  2920. $searchBar.find('input[type="text"]').focus();
  2921. },
  2922. hideSearchBar: function () {
  2923. $searchBar.removeClass('open');
  2924. $searchBar.find('input[type="text"]').val('');
  2925. }
  2926. }
  2927. //==========================================================================================================================
  2928. /* Navbar - Function =======================================================================================================
  2929. * You can manage the navbar
  2930. *
  2931. */
  2932. $.AdminBSB.navbar = {
  2933. activate: function () {
  2934. var $body = $('body');
  2935. var $overlay = $('.overlay');
  2936. //Open left sidebar panel
  2937. $('.bars').on('click', function () {
  2938. $body.toggleClass('ls-closed');
  2939. //if ($body.hasClass('ls-closed')) $body.toggleClass('overlay-open');
  2940. if ($body.hasClass('overlay-open')) { $overlay.fadeIn(); } else { $overlay.fadeOut(); }
  2941. });
  2942. //Close collapse bar on click event
  2943. $('.nav [data-close="true"]').on('click', function () {
  2944. var isVisible = $('.navbar-toggle').is(':visible');
  2945. var $navbarCollapse = $('.navbar-collapse');
  2946. if (isVisible) {
  2947. $navbarCollapse.slideUp(function () {
  2948. $navbarCollapse.removeClass('in').removeAttr('style');
  2949. });
  2950. }
  2951. });
  2952. }
  2953. }
  2954. //==========================================================================================================================
  2955. /* Input - Function ========================================================================================================
  2956. * You can manage the inputs(also textareas) with name of class 'form-control'
  2957. *
  2958. */
  2959. $.AdminBSB.input = {
  2960. activate: function ($parentSelector) {
  2961. $parentSelector = $parentSelector || $('body');
  2962. //On focus event
  2963. $parentSelector.find('.form-control').focus(function () {
  2964. $(this).parent().addClass('focused');
  2965. });
  2966. //On focusout event
  2967. $parentSelector.find('.form-control').focusout(function () {
  2968. var $this = $(this);
  2969. if ($this.parents('.form-group').hasClass('form-float')) {
  2970. if ($this.val() == '') { $this.parents('.form-line').removeClass('focused'); }
  2971. }
  2972. else {
  2973. $this.parents('.form-line').removeClass('focused');
  2974. }
  2975. });
  2976. //On label click
  2977. $parentSelector.on('click', '.form-float .form-line .form-label', function () {
  2978. $(this).parent().find('input').focus();
  2979. });
  2980. //Not blank form
  2981. $parentSelector.find('.form-control').each(function () {
  2982. if ($(this).val() !== '') {
  2983. $(this).parents('.form-line').addClass('focused');
  2984. }
  2985. });
  2986. }
  2987. }
  2988. //==========================================================================================================================
  2989. /* Form - Select - Function ================================================================================================
  2990. * You can manage the 'select' of form elements
  2991. *
  2992. */
  2993. $.AdminBSB.select = {
  2994. activate: function () {
  2995. if ($.fn.selectpicker) { $('select:not(.ms)').selectpicker(); }
  2996. }
  2997. }
  2998. //==========================================================================================================================
  2999. /* DropdownMenu - Function =================================================================================================
  3000. * You can manage the dropdown menu
  3001. *
  3002. */
  3003. //$.AdminBSB.dropdownMenu = {
  3004. // activate: function () {
  3005. // var _this = this;
  3006. // $('.dropdown, .dropup, .btn-group').on({
  3007. // "show.bs.dropdown": function () {
  3008. // var dropdown = _this.dropdownEffect(this);
  3009. // _this.dropdownEffectStart(dropdown, dropdown.effectIn);
  3010. // },
  3011. // "shown.bs.dropdown": function () {
  3012. // var dropdown = _this.dropdownEffect(this);
  3013. // if (dropdown.effectIn && dropdown.effectOut) {
  3014. // _this.dropdownEffectEnd(dropdown, function () { });
  3015. // }
  3016. // },
  3017. // "hide.bs.dropdown": function (e) {
  3018. // var dropdown = _this.dropdownEffect(this);
  3019. // if (dropdown.effectOut) {
  3020. // e.preventDefault();
  3021. // _this.dropdownEffectStart(dropdown, dropdown.effectOut);
  3022. // _this.dropdownEffectEnd(dropdown, function () {
  3023. // dropdown.dropdown.removeClass('open');
  3024. // });
  3025. // }
  3026. // }
  3027. // });
  3028. // //Set Waves
  3029. // Waves.attach('.dropdown-menu li a', ['waves-block']);
  3030. // Waves.init();
  3031. // },
  3032. // dropdownEffect: function (target) {
  3033. // var effectIn = $.AdminBSB.options.dropdownMenu.effectIn, effectOut = $.AdminBSB.options.dropdownMenu.effectOut;
  3034. // var dropdown = $(target), dropdownMenu = $('.dropdown-menu', target);
  3035. // if (dropdown.length > 0) {
  3036. // var udEffectIn = dropdown.data('effect-in');
  3037. // var udEffectOut = dropdown.data('effect-out');
  3038. // if (udEffectIn !== undefined) { effectIn = udEffectIn; }
  3039. // if (udEffectOut !== undefined) { effectOut = udEffectOut; }
  3040. // }
  3041. // return {
  3042. // target: target,
  3043. // dropdown: dropdown,
  3044. // dropdownMenu: dropdownMenu,
  3045. // effectIn: effectIn,
  3046. // effectOut: effectOut
  3047. // };
  3048. // },
  3049. // dropdownEffectStart: function (data, effectToStart) {
  3050. // if (effectToStart) {
  3051. // data.dropdown.addClass('dropdown-animating');
  3052. // data.dropdownMenu.addClass('animated dropdown-animated');
  3053. // data.dropdownMenu.addClass(effectToStart);
  3054. // }
  3055. // },
  3056. // dropdownEffectEnd: function (data, callback) {
  3057. // var animationEnd = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend';
  3058. // data.dropdown.one(animationEnd, function () {
  3059. // data.dropdown.removeClass('dropdown-animating');
  3060. // data.dropdownMenu.removeClass('animated dropdown-animated');
  3061. // data.dropdownMenu.removeClass(data.effectIn);
  3062. // data.dropdownMenu.removeClass(data.effectOut);
  3063. // if (typeof callback == 'function') {
  3064. // callback();
  3065. // }
  3066. // });
  3067. // }
  3068. //}
  3069. //==========================================================================================================================
  3070. /* Browser - Function ======================================================================================================
  3071. * You can manage browser
  3072. *
  3073. */
  3074. var edge = 'Microsoft Edge';
  3075. var ie10 = 'Internet Explorer 10';
  3076. var ie11 = 'Internet Explorer 11';
  3077. var opera = 'Opera';
  3078. var firefox = 'Mozilla Firefox';
  3079. var chrome = 'Google Chrome';
  3080. var safari = 'Safari';
  3081. $.AdminBSB.browser = {
  3082. activate: function () {
  3083. var _this = this;
  3084. var className = _this.getClassName();
  3085. if (className !== '') $('html').addClass(_this.getClassName());
  3086. },
  3087. getBrowser: function () {
  3088. var userAgent = navigator.userAgent.toLowerCase();
  3089. if (/edge/i.test(userAgent)) {
  3090. return edge;
  3091. } else if (/rv:11/i.test(userAgent)) {
  3092. return ie11;
  3093. } else if (/msie 10/i.test(userAgent)) {
  3094. return ie10;
  3095. } else if (/opr/i.test(userAgent)) {
  3096. return opera;
  3097. } else if (/chrome/i.test(userAgent)) {
  3098. return chrome;
  3099. } else if (/firefox/i.test(userAgent)) {
  3100. return firefox;
  3101. } else if (!!navigator.userAgent.match(/Version\/[\d\.]+.*Safari/)) {
  3102. return safari;
  3103. }
  3104. return undefined;
  3105. },
  3106. getClassName: function () {
  3107. var browser = this.getBrowser();
  3108. if (browser === edge) {
  3109. return 'edge';
  3110. } else if (browser === ie11) {
  3111. return 'ie11';
  3112. } else if (browser === ie10) {
  3113. return 'ie10';
  3114. } else if (browser === opera) {
  3115. return 'opera';
  3116. } else if (browser === chrome) {
  3117. return 'chrome';
  3118. } else if (browser === firefox) {
  3119. return 'firefox';
  3120. } else if (browser === safari) {
  3121. return 'safari';
  3122. } else {
  3123. return '';
  3124. }
  3125. }
  3126. }
  3127. //==========================================================================================================================