iwb.js 120 KB

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