iwb.js 131 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387
  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.getSelections = function () {
  911. var $that = this;
  912. var o = $that.options;
  913. if (o.multipleSelect) {
  914. return selectionRows;
  915. }
  916. var $table = (typeof (o.table) === 'string' ? $('#' + o.table) : $(o.table));
  917. return $table.bootstrapTable("getSelections");
  918. }
  919. Table.prototype.getAllSelections = function () {
  920. var $that = this;
  921. var o = $that.options;
  922. if (o.multipleSelect) {
  923. return selectionRows;
  924. }
  925. var $table = (typeof (o.table) === 'string' ? $('#' + o.table) : $(o.table));
  926. return $table.bootstrapTable("getAllSelections");
  927. }
  928. var allowedMethods = [
  929. 'loadTable',
  930. 'refresh',
  931. 'getFuns',
  932. 'defaultCreate',
  933. 'defaultUpdate',
  934. 'defaultDelete',
  935. 'resetView',
  936. 'destroy',
  937. 'setSearchList',
  938. 'getSelections',
  939. 'getAllSelections',
  940. ];
  941. $.fn.iwbTable = function (option) {
  942. var value,
  943. args = Array.prototype.slice.call(arguments, 1);
  944. this.each(function () {
  945. var $this = $(this);
  946. var data = $this.data('iwb.table'),
  947. options = $.extend({}, $this.data(),
  948. typeof option === 'object' && option);
  949. if (typeof option === 'string') {
  950. if ($.inArray(option, allowedMethods) < 0) {
  951. throw new Error("Unknown method: " + option);
  952. }
  953. if (!data) {
  954. return;
  955. }
  956. value = data[option].apply(data, args);
  957. if (option === 'destroy') {
  958. $this.removeData('iwb.table');
  959. $this.removeData('iwbtable.init');
  960. return;
  961. }
  962. }
  963. if ($this.data('iwbtable.init')) {
  964. return;
  965. }
  966. $this.data('iwbtable.init', true);
  967. if (!data) {
  968. data = new Table(this, options);
  969. $this.data('iwb.table', data);
  970. }
  971. });
  972. return typeof value === 'undefined' ? this : value;
  973. };
  974. })(jQuery, window, document);
  975. /*Modal*/
  976. (function ($, window, document, undefined) {
  977. 'use strict';
  978. var Modal = function (ele, opt) {
  979. this.$ele = ele,
  980. this.defaults = {
  981. modal: ele,
  982. modaltitle: '',
  983. data: null,
  984. dataFun: undefined,
  985. form: null,
  986. table: undefined,
  987. errorPlacement: function (error, element) {
  988. element.parent().before(error);
  989. //if (element.is('select')) {
  990. // if (!element.next().next().hasClass('error')) {
  991. // element.next().after(error);
  992. // element.focus();
  993. // }
  994. //} else {
  995. // element.parent().before(error);
  996. // element.focus();
  997. //}
  998. },
  999. rules: {},
  1000. readonly: '',
  1001. disabled: '',
  1002. select2: true,
  1003. select2tree: false,
  1004. url: '',
  1005. type: 'post',
  1006. savebtn: null,
  1007. save: null,
  1008. success: null,
  1009. shownBefore: null,
  1010. shownAfter: null,
  1011. isRefresh: true,
  1012. draggable: true,
  1013. backdrop: 'static',
  1014. keyboard: true,
  1015. kindeditorOption: {},
  1016. content: undefined,
  1017. abp: window.abp
  1018. },
  1019. this.options = $.extend({}, this.defaults, opt);
  1020. this.draggable();
  1021. };
  1022. //var abp = window.abp || {};
  1023. Modal.prototype.getModal = function () {
  1024. var $that = this;
  1025. var $modal = $that.options.modalId
  1026. ? $('#' + $that.options.modalId)
  1027. : typeof ($that.options.modal) === 'string'
  1028. ? $('#' + $that.options.modal)
  1029. : $($that.options.modal);
  1030. return $modal;
  1031. };
  1032. Modal.prototype.open = function () {
  1033. var $that = this;
  1034. var $modal = $that.getModal();
  1035. $modal.off('show.bs.modal.open').on('show.bs.modal.open',
  1036. function () {
  1037. $that.showBefore();
  1038. $that.init();
  1039. $that.setData();
  1040. $that.setSelect2();
  1041. $that.initKindeditor();
  1042. $that.verticalCenter();
  1043. $that.bindSave();
  1044. $.formValidate($modal.find('form'), { noValid: true });
  1045. $that.showAfter();
  1046. });
  1047. $that.show2();
  1048. };
  1049. Modal.prototype.show = function () {
  1050. var $that = this;
  1051. var $modal = $that.getModal();
  1052. $modal.off('show.bs.modal.open').on('show.bs.modal.open',
  1053. function () {
  1054. $that.showBefore();
  1055. $that.setData();
  1056. $that.setSelect2();
  1057. $that.initKindeditor();
  1058. $that.verticalCenter();
  1059. $.formValidate($modal.find('form'), { noValid: true });
  1060. $that.showAfter();
  1061. });
  1062. $that.show2();
  1063. };
  1064. Modal.prototype.show2 = function ($modal) {
  1065. var $that = this, o = $that.options;
  1066. $modal = $modal || $that.getModal();
  1067. $modal.modal({ backdrop: o.backdrop, keyboard: o.keyboard });
  1068. $modal.modal('show');
  1069. //$that.verticalCenter();
  1070. };
  1071. Modal.prototype.create = function (opts) {
  1072. var $that = this, o = $that.options = $.extend({}, $that.options, opts);
  1073. if (!o.modalId) {
  1074. if (o.modal) {
  1075. o.modalId = typeof (o.modal) === 'string' ? o.modal : $(o.modal).attr('id');
  1076. } else {
  1077. o.modalId = 'Modal_' + (Math.floor((Math.random() * 1000000))) + new Date().getTime();
  1078. }
  1079. }
  1080. if (o.modalSize === null) {
  1081. o.modalSize = "";
  1082. }
  1083. else if (!o.modalSize) {
  1084. o.modalSize = 'modal-lg';
  1085. }
  1086. if (o.width) {
  1087. o.widthStr = 'max-width:' + o.width + 'px';
  1088. }
  1089. var createContainer = function (modalId, modalSize, width) {
  1090. abp.ui.setBusy($("body"));
  1091. $that.removeContainer(modalId);
  1092. var containerId = modalId + 'Container';
  1093. return $('<div id="' + containerId + '" tabindex="-1"></div>')
  1094. .append(
  1095. '<div id="' + modalId + '" class="modal fade">' +
  1096. ' <div class="modal-dialog ' + modalSize + '" style="' + width + '">' +
  1097. ' <div class="modal-content"></div>' +
  1098. ' </div>' +
  1099. '</div>'
  1100. ).appendTo('body');
  1101. };
  1102. var show = function () {
  1103. $('#' + o.modalId).off('show.bs.modal').on('show.bs.modal', function () {
  1104. $that.showBefore();
  1105. if (o.data) {
  1106. $that.setData();
  1107. }
  1108. $that.setSelect2();
  1109. $that.bindSave();
  1110. $.formValidate($('#' + o.modalId).find('form'), { noValid: true });
  1111. $that.showAfter();
  1112. });
  1113. $that.show2();
  1114. //$('#' + o.modalId).modal({ backdrop: o.backdrop, keyboard: o.keyboard }).modal('show');
  1115. abp.ui.clearBusy($("body"));
  1116. };
  1117. var $modalContent = createContainer(o.modalId, o.modalSize, o.widthStr).find('.modal-content');
  1118. if (o.viewUrl) {
  1119. $modalContent.load(o.viewUrl, o.args, function (response, status, xhr) {
  1120. if (status === "error") {
  1121. abp.message.warn(abp.localization.abpWeb('InternalServerError'));
  1122. return;
  1123. }
  1124. if (o.scriptUrl) {
  1125. $.loadScript(o.scriptUrl, function () {
  1126. show();
  1127. });
  1128. } else {
  1129. show();
  1130. }
  1131. });
  1132. } else if (o.content) {
  1133. $modalContent.append(o.content);
  1134. show();
  1135. } else if (o.modalBody) {
  1136. var modalHeader = o.modalHeader
  1137. ? modalHeader
  1138. : '<div class="modal-header"><h4 class="modal-title"><span class="modal-title-span">' +
  1139. (o.modaltitle ? o.modaltitle : "") +
  1140. '</span></h4><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button></div>';
  1141. var modalFooter = o.modalFooter
  1142. ? o.modalFooter
  1143. : '<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>';
  1144. $modalContent.append(modalHeader);
  1145. $modalContent.append(o.modalBody);
  1146. $modalContent.append(modalFooter);
  1147. show();
  1148. } else {
  1149. abp.ui.clearBusy($("body"));
  1150. return;
  1151. }
  1152. };
  1153. Modal.prototype.hide = function () {
  1154. var $that = this, o = $that.options;
  1155. var $modal = $that.getModal();
  1156. if (o.modalId) {
  1157. $that.removeContainer(o.modalId);
  1158. }
  1159. return $modal.modal('hide');
  1160. };
  1161. Modal.prototype.removeContainer = function (modalId) {
  1162. var containerId = modalId + 'Container';
  1163. var containerSelector = '#' + containerId;
  1164. var $container = $(containerSelector);
  1165. if ($container.length) {
  1166. $container.remove();
  1167. }
  1168. };
  1169. Modal.prototype.showBefore = function () {
  1170. var $that = this;
  1171. if ($that.options.shownBefore && typeof ($that.options.shownBefore) === 'function') {
  1172. $that.options.shownBefore($that);
  1173. }
  1174. };
  1175. Modal.prototype.showAfter = function () {
  1176. var $that = this;
  1177. if ($that.options.shownAfter && typeof ($that.options.shownAfter) === 'function') {
  1178. $that.options.shownAfter($that);
  1179. }
  1180. };
  1181. Modal.prototype.init = function () {
  1182. var $that = this;
  1183. var $modal = $that.getModal();
  1184. $modal.find('input,select,textarea').val('').removeClass('error valid');
  1185. $modal.find('input:not(.disabled),select:not(.disabled),textarea:not(.disabled)').prop('disabled', false);
  1186. $modal.find('input:not(.readonly),select:not(.readonly),textarea:not(.readonly)').prop('readonly', false);
  1187. $modal.find('label.error').remove();
  1188. $modal.find('.modal-title-span').html($that.options.modaltitle);
  1189. $that.setReadonly();
  1190. $that.setDisabled();
  1191. $that.cleanFile();
  1192. $modal.find('input:not(:disabled,[type=\'hidden\'],[readonly=\'readonly\']):first').focus();
  1193. };
  1194. Modal.prototype.setReadonly = function () {
  1195. var $that = this;
  1196. var $modal = $that.getModal();
  1197. if (!$that.options.readonly)
  1198. return;
  1199. var readonly = $that.options.readonly.split(',');
  1200. for (var i = 0; i < readonly.length; i++) {
  1201. if (readonly[i]) {
  1202. $modal.find('#' + readonly[i]).prop('readonly', true);
  1203. }
  1204. }
  1205. };
  1206. Modal.prototype.setDisabled = function () {
  1207. var $that = this;
  1208. var $modal = $that.getModal();
  1209. if (!$that.options.disabled)
  1210. return;
  1211. var disabled = $that.options.disabled.split(',');
  1212. for (var i = 0; i < disabled.length; i++) {
  1213. if (disabled[i]) {
  1214. $modal.find('#' + disabled[i]).prop('disabled', true);
  1215. }
  1216. }
  1217. };
  1218. Modal.prototype.setData = function () {
  1219. var $that = this;
  1220. var $modal = $that.getModal();
  1221. var $form = $that.options.form ? $($that.options.form) : $modal.find('form');
  1222. $.formDeserialize($form, $that.options.data);
  1223. };
  1224. Modal.prototype.setSelect2 = function () {
  1225. var $that = this;
  1226. var $modal = $that.getModal();
  1227. if ($that.options.select2) {
  1228. $modal.find("select").select2();
  1229. $modal.find('select').off("change.ff").on("change.ff",
  1230. function () {
  1231. $(this).focus();
  1232. $(this).next(".error").remove();
  1233. $(this).blur();
  1234. });
  1235. }
  1236. if ($that.options.select2tree) {
  1237. var tree = $that.options.select2tree.split(',');
  1238. for (var i = 0; i < tree.length; i++) {
  1239. $modal.find('#' + tree[i]).select2tree();
  1240. }
  1241. }
  1242. };
  1243. Modal.prototype.initKindeditor = function () {
  1244. var $that = this;
  1245. var $modal = $that.getModal();
  1246. $modal.find('textarea.kindeditor').each(function (i, v) {
  1247. if ($(v).length && $.fn.iwbKindeditor) {
  1248. var val = $(v).val();
  1249. if ($(v).data("iwb.kindEditor")) {
  1250. $(v).iwbKindeditor('remove');
  1251. }
  1252. var option = $that.options.kindeditorOption || {};
  1253. $(v).iwbKindeditor(option);
  1254. window.editor[$(v).attr('id')].html(val);
  1255. }
  1256. });
  1257. };
  1258. Modal.prototype.cleanFile = function () {
  1259. var $that = this;
  1260. var $modal = $that.getModal();
  1261. $modal.find('input[type="file"]').each(function (i, v) {
  1262. $(v).iwbFileUpload('cleanFile');
  1263. });
  1264. };
  1265. Modal.prototype.bindSave = function () {
  1266. var $that = this;
  1267. var $modal = $that.getModal();
  1268. var $saveBtn = $that.options.savebtn
  1269. ? $($that.options.savebtn)
  1270. : $modal.find('.save-btn').length > 0
  1271. ? $modal.find('.save-btn')
  1272. : $modal.find('.save').length > 0
  1273. ? $modal.find('.save')
  1274. : $modal.find('#save');
  1275. var opt = $that.getSaveOptions();
  1276. var save = null;
  1277. if ($that.options.save && typeof ($that.options.save) === "function") {
  1278. save = function () { $that.options.save(opt); };
  1279. } else if ($that.options.url) {
  1280. save = function () { $.iwbAjax($that.options.url, opt); };
  1281. }
  1282. if (save !== null) {
  1283. $saveBtn.off('click.save').on('click.save', save);
  1284. $modal.find('.modal-body').keydown(function (e) {
  1285. if (e.which === 13) {
  1286. if (e.target.tagName.toLocaleLowerCase() === "textarea") {
  1287. e.stopPropagation();
  1288. } else {
  1289. e.preventDefault();
  1290. save.call(this);
  1291. }
  1292. }
  1293. });
  1294. }
  1295. //var opt = $that.getSaveOptions();
  1296. //if ($that.options.save && typeof $that.options.save === "function") {
  1297. // $that.options.save(opt);
  1298. //} else {
  1299. // $.iwbAjax($that.options.url, opt);
  1300. //}
  1301. };
  1302. Modal.prototype.getSaveOptions = function () {
  1303. var $that = this;
  1304. var $modal = $that.getModal();
  1305. var $form = $that.options.form ? $($that.options.form) : $modal.find('form');
  1306. return {
  1307. url: $that.options.url,
  1308. type: $that.options.type,
  1309. success: $that.options.success,
  1310. form: $form,
  1311. data: null,
  1312. dataFun: $that.options.dataFun,
  1313. table: $that.options.table,
  1314. modal: $that.options.modal,
  1315. blockUI: $modal.find('.modal-dialog'),
  1316. isRefresh: $that.options.isRefresh
  1317. };
  1318. };
  1319. Modal.prototype.verticalCenter = function () {
  1320. var $that = this;
  1321. var $modal = $that.getModal();
  1322. $modal.css('display', 'block');
  1323. var topHeight = $(window).height() - $modal.find('.modal-dialog').height() - 150;
  1324. if (topHeight < 30) {
  1325. topHeight = 30;
  1326. }
  1327. $modal.find('.modal-dialog').animate({ 'marginTop': topHeight / 2 + "px" });
  1328. };
  1329. Modal.prototype.draggable = function () {
  1330. var $that = this;
  1331. var $modal = $that.getModal();
  1332. if ($that.options.draggable) {
  1333. //console.log('draggable');
  1334. $('.modal-header').css('cursor', 'move');
  1335. /** 拖拽模态框*/
  1336. var dragModal = {
  1337. mouseStartPoint: { 'left': 0, 'top': 0 },
  1338. mouseEndPoint: { 'left': 0, 'top': 0 },
  1339. mouseDragDown: false,
  1340. basePoint: { 'left': 0, 'top': 0 },
  1341. moveTarget: null,
  1342. topleng: 0
  1343. };
  1344. $modal.off('mousedown.drag').on('mousedown.drag',
  1345. '.modal-header',
  1346. function (e) {
  1347. //webkit内核和火狐禁止文字被选中
  1348. $('body').addClass('drag-select');
  1349. //ie浏览器禁止文字选中
  1350. document.body.onselectstart = document.body.ondrag = function () {
  1351. return false;
  1352. };
  1353. if ($(e.target).hasClass('close')) //点关闭按钮不能移动对话框
  1354. return;
  1355. dragModal.mouseDragDown = true;
  1356. dragModal.moveTargetHeader = $(this);
  1357. dragModal.moveTarget = $(this).closest('.modal-content');
  1358. dragModal.mouseStartPoint = { 'left': e.clientX, 'top': e.pageY };
  1359. dragModal.basePoint = dragModal.moveTarget.offset();
  1360. dragModal.topLeng = e.pageY - e.clientY;
  1361. });
  1362. $modal.off('mouseup.drag').on('mouseup.drag',
  1363. function () {
  1364. dragModal.mouseDragDown = false;
  1365. dragModal.moveTarget = undefined;
  1366. dragModal.mouseStartPoint = { 'left': 0, 'top': 0 };
  1367. dragModal.basePoint = { 'left': 0, 'top': 0 };
  1368. });
  1369. $modal.off('mousemove.drag').on('mousemove.drag',
  1370. function (e) {
  1371. if (!dragModal.mouseDragDown || dragModal.moveTarget === undefined) return;
  1372. var mousX = e.clientX;
  1373. var mousY = e.pageY;
  1374. if (mousX < 0) mousX = 0;
  1375. if (mousY < 0) mousY = 25;
  1376. dragModal.mouseEndPoint = { 'left': mousX, 'top': mousY };
  1377. var width = dragModal.moveTarget.width();
  1378. var height = dragModal.moveTargetHeader.height();
  1379. var clientWidth = document.body.clientWidth;
  1380. var clientHeight = document.body.clientHeight;
  1381. if (dragModal.mouseEndPoint.left < dragModal.mouseStartPoint.left - dragModal.basePoint.left) {
  1382. dragModal.mouseEndPoint.left = 0;
  1383. } else if (dragModal.mouseEndPoint.left >=
  1384. clientWidth - width + dragModal.mouseStartPoint.left - dragModal.basePoint.left) {
  1385. dragModal.mouseEndPoint.left = clientWidth - width - 38;
  1386. } else {
  1387. dragModal.mouseEndPoint.left =
  1388. dragModal.mouseEndPoint.left -
  1389. (dragModal.mouseStartPoint.left - dragModal.basePoint.left); //移动修正,更平滑
  1390. }
  1391. if (dragModal.mouseEndPoint.top - (dragModal.mouseStartPoint.top - dragModal.basePoint.top) <
  1392. dragModal.topLeng) {
  1393. dragModal.mouseEndPoint.top = dragModal.topLeng;
  1394. } else if (dragModal.mouseEndPoint.top - dragModal.topLeng >
  1395. clientHeight - height + dragModal.mouseStartPoint.top - dragModal.basePoint.top) {
  1396. dragModal.mouseEndPoint.top = clientHeight - height - 38 + dragModal.topLeng;
  1397. } else {
  1398. dragModal.mouseEndPoint.top = dragModal.mouseEndPoint.top -
  1399. (dragModal.mouseStartPoint.top - dragModal.basePoint.top);
  1400. }
  1401. dragModal.moveTarget.offset(dragModal.mouseEndPoint);
  1402. });
  1403. $(document).on('hidden.bs.modal',
  1404. '.modal',
  1405. function () {
  1406. $('.modal-content').css({ 'top': 0, 'left': 0 });
  1407. $('body').removeClass('drag-select');
  1408. document.body.onselectstart = document.body.ondrag = null;
  1409. });
  1410. } else {
  1411. $('.modal-header').css('cursor', 'default');
  1412. }
  1413. };
  1414. var allowedMethods = [
  1415. 'open',
  1416. 'show',
  1417. 'show2',
  1418. 'hide',
  1419. 'create'
  1420. ];
  1421. $.fn.iwbModal = function (option) {
  1422. var value,
  1423. args = Array.prototype.slice.call(arguments, 1);
  1424. this.each(function () {
  1425. var modal = new Modal(this, option);
  1426. if (typeof option === 'string') {
  1427. if ($.inArray(option, allowedMethods) < 0) {
  1428. throw new Error("Unknown method: " + option);
  1429. }
  1430. value = modal[option].apply(modal, args);
  1431. } else {
  1432. modal.open();
  1433. }
  1434. });
  1435. return typeof value === 'undefined' ? this : value;
  1436. };
  1437. })(jQuery, window, document);
  1438. /*FileUpload*/
  1439. (function ($, window, document, undefined) {
  1440. 'use strict';
  1441. var abp = window.abp || {};
  1442. var File = function (ele, opt) {
  1443. this.$ele = ele,
  1444. this.defaults = {
  1445. file: ele,
  1446. maxSize: 2,
  1447. isImage: true,
  1448. targetInfo: undefined,
  1449. targetName: "fileName",
  1450. targetExt: "fileExt",
  1451. callback: undefined,
  1452. abp: window.abp
  1453. },
  1454. this.options = $.extend({}, this.defaults, opt || {});
  1455. //var $that = this;
  1456. //$that.show();
  1457. };
  1458. File.prototype.getFile = function () {
  1459. var $that = this;
  1460. var $file = typeof ($that.options.file) === 'string' ? $('#' + $that.options.file) : $($that.options.file);
  1461. return $file;
  1462. };
  1463. File.prototype.show = function () {
  1464. var $that = this;
  1465. var $file = $that.getFile();
  1466. $file.off('change.file.check').on('change.file.check', function () {
  1467. $that.fileCheck($that);
  1468. });
  1469. $file.closest('.iwb-file ').removeClass("file-success").removeClass("file-error");
  1470. //return $file[0].click();
  1471. };
  1472. File.prototype.fileCheck = function ($that) {
  1473. var $file = $that.getFile();
  1474. if ($that.checkSize()) {
  1475. var fileName = $file.val().split("\\").pop();
  1476. $file.closest('.iwb-file ').addClass("file-success").find("label").text(fileName);
  1477. var file = document.getElementById($file.attr("id")).files[0];
  1478. $that.readFile(file);
  1479. if ($that.options.targetName && $that.options.targetName !== undefined) {
  1480. var name = fileName.substring(0, fileName.lastIndexOf("."));
  1481. if (!$that.options.targetName)
  1482. return;
  1483. var targetName = $that.options.targetName.split(',');
  1484. for (var i = 0; i < targetName.length; i++) {
  1485. $('#' + targetName[i]).val(name);
  1486. }
  1487. }
  1488. if ($that.options.targetExt && $that.options.targetExt !== undefined) {
  1489. var ext = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length);
  1490. if (!$that.options.targetExt)
  1491. return;
  1492. var targetExt = $that.options.targetExt.split(',');
  1493. for (var j = 0; j < targetExt.length; j++) {
  1494. $('#' + targetExt[j]).val(ext);
  1495. }
  1496. }
  1497. var callback = $that.options.callback;
  1498. if (callback && typeof (callback) === "function") {
  1499. callback(fileName, file);
  1500. }
  1501. } else {
  1502. var target = $that.options.targetInfo ? $that.options.targetInfo : $file.attr('id').replace('_file', '');
  1503. $('#' + target).closest('.iwb-file ').addClass("file-error").find("label").text(abp.localization.iwbZero('SelectFile'));
  1504. }
  1505. };
  1506. File.prototype.checkSize = function () {
  1507. var $that = this;
  1508. var $file = $that.getFile();
  1509. var maxsize = $that.options.maxSize * 1024 * 1024;
  1510. //var errMsg = "上传的附件文件不能超过" + $that.options.maxSize + "M。";
  1511. //var tipMsg = "您的浏览器暂不支持计算上传文件的大小,确保上传文件不要超过" + $that.options.maxSize + "M,建议使用IE、FireFox、Chrome浏览器。";
  1512. var errMsg = abp.localization.iwbZero('FileUploadErrorMsg', $that.options.maxSize);
  1513. var tipMsg = abp.localization.iwbZero('FileUploadTipMsg', $that.options.maxSize);
  1514. var browserCfg = {};
  1515. var ua = window.navigator.userAgent;
  1516. if (ua.indexOf("MSIE") >= 1) {
  1517. browserCfg.ie = true;
  1518. } else if (ua.indexOf("Firefox") >= 1) {
  1519. browserCfg.firefox = true;
  1520. } else if (ua.indexOf("Chrome") >= 1) {
  1521. browserCfg.chrome = true;
  1522. }
  1523. try {
  1524. var objFile = document.getElementById($file.attr("id"));
  1525. if (objFile.value === "") {
  1526. //layer.alert("请先选择上传文件", { icon: 7, title: "提示信息" });
  1527. return false;
  1528. }
  1529. var filesize;
  1530. if (browserCfg.firefox || browserCfg.chrome) {
  1531. filesize = objFile.files[0].size;
  1532. } else if (browserCfg.ie) {
  1533. var objImg = document.createElement("img");
  1534. objImg.id = "tempImg";
  1535. objImg.style.display = "none";
  1536. document.body.appendChild(objImg);
  1537. objImg.dynsrc = objFile.value;
  1538. filesize = objImg.fileSize;
  1539. } else {
  1540. $that.cleanFile();
  1541. abp.message.warn(tipMsg);
  1542. return false;
  1543. }
  1544. if (filesize === -1) {
  1545. $that.cleanFile();
  1546. abp.message.warn(tipMsg);
  1547. return false;
  1548. } else if (filesize > maxsize) {
  1549. $that.cleanFile();
  1550. abp.message.warn(errMsg);
  1551. return false;
  1552. } else {
  1553. return true;
  1554. }
  1555. } catch (e) {
  1556. $that.cleanFile();
  1557. abp.message.error(e);
  1558. return false;
  1559. }
  1560. };
  1561. File.prototype.readFile = function (file) {
  1562. //判断是否是图片类型
  1563. //console.log(file.type);
  1564. if (!file) {
  1565. return;
  1566. }
  1567. var $that = this;
  1568. var $file = $that.getFile();
  1569. if ($that.options.isImage && !/image\/\w+/.test(file.type)) {
  1570. abp.message.warn(abp.localization.iwbZero('FileUploadOnlyImage'));
  1571. return;
  1572. }
  1573. var reader = new FileReader();
  1574. reader.readAsDataURL(file);
  1575. reader.onload = function () {
  1576. var fileinfo = this.result.substring(this.result.indexOf(',') + 1);
  1577. console.log(fileinfo);
  1578. var target = $that.options.targetInfo ? $that.options.targetInfo : $file.attr('id').replace('_file', '');
  1579. $('#' + target).val(fileinfo);
  1580. };
  1581. };
  1582. File.prototype.cleanFile = function () {
  1583. var $that = this;
  1584. var $file = $that.getFile();
  1585. $file.closest('.iwb-file ').removeClass("file-success").removeClass("file-error").find("label").text(abp.localization.iwbZero('SelectFile'));
  1586. $file.closest('.iwb-file ').find('input').val('');
  1587. $file.after($file.clone().val(""));
  1588. $file.remove();
  1589. };
  1590. var allowedMethods = [
  1591. 'show',
  1592. 'readFile',
  1593. 'cleanFile',
  1594. 'fileCheck',
  1595. 'checkSize'
  1596. ];
  1597. $.fn.iwbFileUpload = function (option) {
  1598. var value,
  1599. args = Array.prototype.slice.call(arguments, 1);
  1600. this.each(function () {
  1601. var $this = $(this);
  1602. var data = $this.data('iwb.FileUpload');
  1603. if (!data) {
  1604. data = new File(this, option);
  1605. $this.data('iwb.FileUpload', data);
  1606. }
  1607. if (typeof option === 'string') {
  1608. if ($.inArray(option, allowedMethods) < 0) {
  1609. throw new Error("Unknown method: " + option);
  1610. }
  1611. value = data[option].apply(data, args);
  1612. } else {
  1613. data.show();
  1614. }
  1615. });
  1616. return typeof value === 'undefined' ? this : value;
  1617. };
  1618. })(jQuery, window, document);
  1619. /*FileOpenShow*/
  1620. (function ($, window, document, undefined) {
  1621. 'use strict';
  1622. var File = function (ele, opt) {
  1623. this.$ele = ele,
  1624. this.defaults = {
  1625. url: undefined,
  1626. type: 'img'
  1627. },
  1628. this.options = $.extend({}, this.defaults, opt);
  1629. if ($(this.$ele).data('type')) {
  1630. this.options.type = $(this.$ele).data('type');
  1631. }
  1632. if (!this.options.url) {
  1633. this.options.url = $(this.$ele).data('url');
  1634. }
  1635. if (this.options.url && this.options.url.indexOf("/") !== 0) {
  1636. this.options.url = "/" + this.options.url;
  1637. }
  1638. };
  1639. //var abp = window.abp || {};
  1640. File.prototype.show = function () {
  1641. var $that = this;
  1642. switch ($that.options.type) {
  1643. case 'img':
  1644. case 'image':
  1645. this.showImage();
  1646. break;
  1647. case 'office':
  1648. this.showOffice();
  1649. break;
  1650. default:
  1651. this.showFile();
  1652. return;
  1653. }
  1654. };
  1655. File.prototype.showImage = function () {
  1656. var $that = this;
  1657. $.metPageCss('/Content/Libs/viewer/viewer.min.css', "dy-css-viewer");
  1658. $.metPageJs('/Content/Libs/viewer/viewer.min.js', "dy-js-viewer");
  1659. if ($("#Img-Modal").length > 0) {
  1660. $("#Img-Modal").remove();
  1661. }
  1662. $("body").append(' <ul id="Img-Modal" style="display:none"><li><img src="' +
  1663. $that.options.url +
  1664. '" data-original="' +
  1665. $that.options.url +
  1666. '" alt="Picture" /></li></ul>');
  1667. var $image = $('#Img-Modal');
  1668. var options = {
  1669. // inline: true,
  1670. url: 'data-original',
  1671. button: true,
  1672. navbar: false,
  1673. title: false,
  1674. toolbar: false,
  1675. ready: function (e) {
  1676. console.log(e.type);
  1677. }
  1678. };
  1679. $image.on({
  1680. show: function (e) {
  1681. console.log(e.type);
  1682. },
  1683. hidden: function (e) {
  1684. $image.viewer('destroy');
  1685. $image.remove();
  1686. }
  1687. }).viewer(options);
  1688. $image.viewer("show");
  1689. $image.css("display", "none");
  1690. };
  1691. File.prototype.showOffice = function () {
  1692. var $that = this;
  1693. var url = 'http://ow365.cn/?i=17314&furl=http://' + window.location.host + $that.options.url;
  1694. $that.showFile(url);
  1695. };
  1696. File.prototype.showFile = function (url) {
  1697. var $that = this;
  1698. url = url || $that.options.url;
  1699. if ($('#File-Modal').length <= 0) {
  1700. $('body').append(
  1701. '<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>');
  1702. }
  1703. $('#File-Modal').find('.modal-body')
  1704. .html('<iframe src="' + url + '" width="100%"; style="min-height: calc(100vh - 200px);" frameborder="0"></iframe>');
  1705. $(document).off('click.download', '#File-Modal #download').on('click.download', '#File-Modal #download',
  1706. function () { $that.download(url) });
  1707. $('#File-Modal').iwbModal('show2');
  1708. };
  1709. File.prototype.download = function (url) {
  1710. var $that = this;
  1711. url = url || $that.options.url;
  1712. if ($('#tempLink-fd').length > 0) {
  1713. $('#tempLink-fd').remove();
  1714. }
  1715. $('body').append('<a id="tempLink-fd" href="' + url + '" style="display:none"></a>');
  1716. $('#tempLink-fd')[0].click();
  1717. $('#tempLink-fd').remove();
  1718. };
  1719. var allowedMethods = [
  1720. 'show',
  1721. 'download'
  1722. ];
  1723. $.fn.iwbFileShow = function (option) {
  1724. var value,
  1725. args = Array.prototype.slice.call(arguments, 1);
  1726. this.each(function () {
  1727. var $this = $(this);
  1728. var data = $this.data('iwb.FileShow');
  1729. if (!data || typeof option !== 'string') {
  1730. data = new File(this, option);
  1731. $this.data('iwb.FileShow', data);
  1732. }
  1733. if (typeof option === 'string') {
  1734. if ($.inArray(option, allowedMethods) < 0) {
  1735. throw new Error("Unknown method: " + option);
  1736. }
  1737. value = data[option].apply(data, args);
  1738. } else {
  1739. data.show();
  1740. }
  1741. });
  1742. return typeof value === 'undefined' ? this : value;
  1743. };
  1744. })(jQuery, window, document);
  1745. /*TreeView*/
  1746. (function ($, window, document, undefined) {
  1747. 'use strict';
  1748. var TreeView = function (ele, opt) {
  1749. var that = this;
  1750. var tempId = '';
  1751. var onNodeSelected = function (e, data, that) {
  1752. var o = that.options;
  1753. if (!data || !data[o.selectFiledName]) {
  1754. return;
  1755. }
  1756. var $input = (typeof (o.selectFiledInput) === 'string' ? $('#' + o.selectFiledInput) : $(o.selectFiledInput));
  1757. tempId = data[o.selectFiledName];
  1758. $input.val(tempId);
  1759. var $table = (typeof (o.table) === 'string' ? $('#' + o.table) : $(o.table));
  1760. $table.iwbTable('refresh', true);
  1761. };
  1762. var onNodeUnselected = function (e, data, that) {
  1763. var o = that.options;
  1764. var $input = (typeof (o.selectFiledInput) === 'string' ? $('#' + o.selectFiledInput) : $(o.selectFiledInput));
  1765. $input.val('');
  1766. var $table = (typeof (o.table) === 'string' ? $('#' + o.table) : $(o.table));
  1767. $table.iwbTable('refresh', true);
  1768. };
  1769. this.$ele = ele,
  1770. this.defaults = {
  1771. url: undefined,
  1772. data: undefined,
  1773. levels: 2,
  1774. emptyIcon: "iconfont icon-delete",
  1775. collapseIcon: 'iconfont icon-delete ',
  1776. expandIcon: 'iconfont icon-add',
  1777. selectedBackColor: '#563d7c',
  1778. onNodeSelected: function (e, d) {
  1779. onNodeSelected(e, d, that);
  1780. },
  1781. onNodeUnselected: function (e, d) {
  1782. onNodeUnselected(e, d, that);
  1783. },
  1784. table: 'table',
  1785. selectFiledName: 'id',
  1786. selectFiledInput: 'keyWords'
  1787. },
  1788. this.options = $.extend({}, this.defaults, opt);
  1789. };
  1790. //var abp = window.abp || {};
  1791. TreeView.prototype.init = function () {
  1792. var that = this, o = that.options;
  1793. $.metPageCss('/Content/Libs/bootstrap-treeview/bootstrap-treeview.min.css', "dy-css-treeview");
  1794. $.metPageJs('/Content/Libs/bootstrap-treeview/bootstrap-treeview.min.js', "dy-js-treeview");
  1795. if (o.data) {
  1796. that.loadTree();
  1797. } else if (o.url) {
  1798. that.postData();
  1799. }
  1800. };
  1801. TreeView.prototype.loadTree = function (data) {
  1802. var that = this, o = that.options;
  1803. var option = $.extend({}, o);
  1804. if (data) {
  1805. option.data = data;
  1806. }
  1807. $(that.$ele).treeview(option);
  1808. };
  1809. TreeView.prototype.postData = function (url) {
  1810. var that = this, o = that.options;
  1811. url = url || o.url;
  1812. $.iwbAjax({
  1813. url: window.appUrl + url,
  1814. isAlert: false,
  1815. isValidate: false,
  1816. isRefresh: false,
  1817. success: function (res) {
  1818. if (res) {
  1819. that.loadTree(res);
  1820. }
  1821. }
  1822. });
  1823. };
  1824. var allowedMethods = [
  1825. 'init'
  1826. ];
  1827. $.fn.iwbTreeView = function (option) {
  1828. var value,
  1829. args = Array.prototype.slice.call(arguments, 1);
  1830. this.each(function () {
  1831. var $this = $(this);
  1832. var data = $this.data('iwb.TreeView');
  1833. if (!data) {
  1834. data = new TreeView(this, option);
  1835. $this.data('iwb.TreeView', data);
  1836. data.init();
  1837. }
  1838. if (typeof option === 'string') {
  1839. if ($.inArray(option, allowedMethods) < 0) {
  1840. throw new Error("Unknown method: " + option);
  1841. }
  1842. value = data[option].apply(data, args);
  1843. }
  1844. });
  1845. return typeof value === 'undefined' ? this : value;
  1846. };
  1847. })(jQuery, window, document);
  1848. /*DateTime*/
  1849. (function ($, window, document, undefined) {
  1850. 'use strict';
  1851. var DateTime = function (ele, opt) {
  1852. this.$ele = ele,
  1853. this.defaults = {
  1854. language: 'zh-CN',
  1855. format: "yyyy-mm-dd", //yyyy-mm-ddThh:ii:ssZ
  1856. autoclose: true, //当选择一个日期之后是否立即关闭此日期时间选择器。
  1857. startView: 2, //日期时间选择器打开之后首先显示的视图。 可接受的值:0 or 'hour' \ 1 or 'day' \2 or 'month' (the default )\3 or 'year' \4 or 'decade' for the 10-year overview.
  1858. minView: 2, //日期时间选择器所能够提供的最精确的时间选择视图。
  1859. maxView: 4, //日期时间选择器最高能展示的选择范围视图。
  1860. todayBtn: true,
  1861. weekStart: 0, //一周从哪一天开始。0(星期日)到6(星期六)
  1862. startDate: '2015-01-01', //开始时间
  1863. endDate: null, //结束时间,
  1864. forceParse: true, //强制解析
  1865. minuteStep: 10, //分钟视图中分钟间隔
  1866. twoDateId: undefined,//双日期外部Id(默认找里面的 .startTime和.endTime)
  1867. startId: undefined,//开始日期Id,不填就是本身
  1868. endId: undefined,//结束日期Id
  1869. isAutoSetDate: true,//双日期自动填写另一个日期
  1870. startEndInterval: 30,//双日期自动填写间隔(天)
  1871. defaultDate: undefined//默认日期时间
  1872. },
  1873. this.options = $.extend({}, this.defaults, opt);
  1874. };
  1875. //var abp = window.abp || {};
  1876. DateTime.prototype.init = function () {
  1877. var that = this;//, o = that.options;
  1878. $.metPageCss('/Content/Libs/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css', "dy-css-dateTime");
  1879. //$.metPageCss('/Content/Plugins/bootstrap-datetimepicker/css/bootstrap-datetimepicker-wr.css', "dy-css-dateTime-self");
  1880. $.metPageJs('/Content/Libs/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js', "dy-js-dateTime");
  1881. $.metPageJs('/Content/Libs/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js', "dy-js-dateTime-zhCN");
  1882. };
  1883. DateTime.prototype.date = function () {
  1884. var that = this, o = that.options;
  1885. o.format = "yyyy-mm-dd";
  1886. o.startView = 2;
  1887. o.minView = 2;
  1888. that.load();
  1889. };
  1890. DateTime.prototype.dateTime = function () {
  1891. var that = this, o = that.options;
  1892. o.format = "yyyy-mm-dd hh:ii";
  1893. o.startView = 2;
  1894. o.minView = 1;
  1895. that.load();
  1896. };
  1897. DateTime.prototype.dateSecond = function () {
  1898. var that = this, o = that.options;
  1899. o.format = "yyyy-mm-dd hh:ii:ss";
  1900. o.startView = 2;
  1901. o.minView = 0;
  1902. that.load();
  1903. };
  1904. DateTime.prototype.twoDate = function () {
  1905. var that = this, o = that.options;
  1906. var $start, $end;
  1907. if (o.twoDateId) {
  1908. $start = $('#' + o.twoDateId).find('.startTime');
  1909. $end = $('#' + o.twoDateId).find('.endTime');
  1910. } else {
  1911. $start = $('#' + o.startId);
  1912. $end = $('#' + o.endId);
  1913. }
  1914. $start = $start.length > 0 ? $start : $(that.$ele);
  1915. if ($end.length <= 0) {
  1916. $end = $start.parent().find('.endTime');
  1917. if ($end.length <= 0) {
  1918. throw new Error("Unknown EndDate Selector");
  1919. }
  1920. }
  1921. $start.datetimepicker('remove');
  1922. $start.datetimepicker(o).on('show',
  1923. function (event) {
  1924. event.preventDefault();
  1925. event.stopPropagation();
  1926. }).on('hide',
  1927. function (event) {
  1928. event.preventDefault();
  1929. event.stopPropagation();
  1930. }).on("changeDate",
  1931. function (e) {
  1932. //console.log(e);
  1933. //console.log(e.date.valueOf());
  1934. $end.datetimepicker('setStartDate', e.date);
  1935. if (o.isAutoSetDate && o.startEndInterval && o.startEndInterval > 0) {
  1936. $end.datetimepicker('setDate',
  1937. new Date(e.date.valueOf() + 1000 * 60 * 60 * 24 * o.startEndInterval));
  1938. }
  1939. });
  1940. $end.datetimepicker('remove');
  1941. $end.datetimepicker(o).on('show',
  1942. function (event) {
  1943. event.preventDefault();
  1944. event.stopPropagation();
  1945. }).on('hide',
  1946. function (event) {
  1947. event.preventDefault();
  1948. event.stopPropagation();
  1949. }).on("changeDate",
  1950. function (e) {
  1951. //console.log(e);
  1952. //console.log(e.date.valueOf());
  1953. $start.datetimepicker('setEndDate', e.date);
  1954. if (o.isAutoSetDate && o.startEndInterval && o.startEndInterval > 0) {
  1955. $start.datetimepicker('setDate', new Date(e.date.valueOf() - 1000 * 60 * 60 * 24 * o.startEndInterval));
  1956. }
  1957. });
  1958. if (o.isAutoSetDate) {
  1959. var eDate = o.defaultDate ? o.defaultDate : new Date();
  1960. $end.datetimepicker("setDate", eDate);
  1961. $start.datetimepicker("setDate",
  1962. new Date(eDate.valueOf() - 1000 * 60 * 60 * 24 * (o.startEndInterval ? o.startEndInterval : 30)));
  1963. }
  1964. };
  1965. DateTime.prototype.load = function () {
  1966. var that = this, o = that.options;
  1967. $(that.$ele).datetimepicker('remove');
  1968. $(that.$ele).datetimepicker(o).on('show', function (event) {
  1969. event.preventDefault();
  1970. event.stopPropagation();
  1971. }).on('hide', function (event) {
  1972. event.preventDefault();
  1973. event.stopPropagation();
  1974. });
  1975. };
  1976. //var allowedMethods = [
  1977. // 'date',
  1978. // 'dateTime',
  1979. // 'dateSecond',
  1980. // 'twoDate'
  1981. //];
  1982. //$.fn.iwbDate2 = function (option) {
  1983. // var value,
  1984. // args = Array.prototype.slice.call(arguments, 1);
  1985. // this.each(function () {
  1986. // var $this = $(this);
  1987. // var data = $this.data('iwb.dateTime');
  1988. // if (!data) {
  1989. // data = new DateTime(this, option ? option : {});
  1990. // $this.data('iwb.dateTime', data);
  1991. // data.init();
  1992. // }
  1993. // if (typeof option === 'string') {
  1994. // if ($.inArray(option, allowedMethods) < 0) {
  1995. // throw new Error("Unknown method: " + option);
  1996. // }
  1997. // value = data[option].apply(data, args);
  1998. // } else if (option && option.method && typeof option.method === 'string') {
  1999. // if ($.inArray(option.method, allowedMethods) < 0) {
  2000. // throw new Error("Unknown method: " + option.method);
  2001. // }
  2002. // value = data[option.method].apply(data, args);
  2003. // }
  2004. // else {
  2005. // if (!option && $this.hasClass('iwb-date')) {
  2006. // data.date();
  2007. // } else if (!option && ($this.hasClass('iwb-date-time') || $this.hasClass('iwb-dateTime'))) {
  2008. // data.dateTime();
  2009. // } else if (!option && ($this.hasClass('iwb-date-second') || $this.hasClass('iwb-dateSecond'))) {
  2010. // data.dateSecond();
  2011. // } else if (!option && ($this.hasClass('startTime') || $this.hasClass('iwb-date-two') || $this.hasClass('iwb-twoDate'))) {
  2012. // data.twoDate();
  2013. // } else {
  2014. // data.load();
  2015. // }
  2016. // }
  2017. // });
  2018. // return typeof value === 'undefined' ? this : value;
  2019. //};
  2020. //$.fn.iwbTwoDate2 = function (option) {
  2021. // this.each(function () {
  2022. // var $this = $(this);
  2023. // var data = $this.data('iwb.dateTime');
  2024. // if (!data) {
  2025. // data = new DateTime(this, option);
  2026. // $this.data('iwb.dateTime', data);
  2027. // data.init();
  2028. // data.twoDate();
  2029. // }
  2030. // });
  2031. // return this;
  2032. //};
  2033. //$('.iwb-date-time').iwbDate();
  2034. //$('.iwb-date').iwbDate();
  2035. })(jQuery, window, document);
  2036. /*DateTime*/
  2037. (function ($, window, document, undefined) {
  2038. 'use strict';
  2039. var DateTime = function (ele, opt) {
  2040. this.$ele = ele,
  2041. this.defaults = {
  2042. language: 'zh-CN',
  2043. singleDatePicker: true,
  2044. dayStep: false,
  2045. opens: "center",
  2046. drops: "down",
  2047. format: "YYYY-MM-DD", //YYYY-MM-DD HH:MM:SS
  2048. showEvent: undefined,
  2049. showCalendarEvent: undefined,
  2050. hideEvent: undefined,
  2051. hideCalendarEvent: undefined,
  2052. applyEvent: undefined,
  2053. cancelEvent: undefined,
  2054. minDate: '2015-01-01',
  2055. maxDate: false,
  2056. showWeekNumbers: false,
  2057. showISOWeekNumbers: false,
  2058. timePicker: false,
  2059. timePicker24Hour: true,
  2060. timePickerIncrement: 5,
  2061. timePickerSeconds: false,
  2062. linkedCalendars: true,
  2063. showCustomRangeLabel: false,
  2064. alwaysShowCalendars: true,
  2065. autoApply: true,
  2066. autoUpdateInput: true,
  2067. buttonClasses: "btn btn-sm",
  2068. applyButtonClasses: "btn-success",
  2069. cancelClass: "btn-default",
  2070. startDate: undefined, //开始时间
  2071. endDate: undefined, //结束时间,
  2072. maxSpan: undefined,
  2073. locale: undefined,
  2074. ranges: undefined,
  2075. hasRange: false
  2076. },
  2077. this.options = $.extend({}, this.defaults, opt);
  2078. };
  2079. var dateOpt = {};
  2080. var timeSelect2 = function () {
  2081. $('.daterangepicker .calendar-time > select').select2();
  2082. }
  2083. //var abp = window.abp || {};
  2084. DateTime.prototype.init = function () {
  2085. var that = this; var o = that.options;
  2086. $.metPageCss('/Content/Libs/bootstrap-daterangepicker/daterangepicker.css', "dy-css-daterangepicker");
  2087. $.metPageJs('/Content/Libs/bootstrap-daterangepicker/moment.min.js', "dy-js-daterangepicker.moment");
  2088. $.metPageJs('/Content/Libs/bootstrap-daterangepicker/daterangepicker.js', "dy-js-daterangepicker");
  2089. var localeName = {
  2090. applyLabel: 'Apply',
  2091. cancelLabel: 'Cancel',
  2092. fromLabel: "",
  2093. toLabel: "",
  2094. customRangeLabel: 'Custom Range',
  2095. daysOfWeek: moment.weekdaysMin(),
  2096. monthNames: moment.monthsShort()
  2097. },
  2098. ranges = {
  2099. 'Today': [moment(), moment()],
  2100. 'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
  2101. 'Last 7 Days': [moment().subtract(6, 'days'), moment()],
  2102. 'Last 30 Days': [moment().subtract(29, 'days'), moment()],
  2103. 'This Month': [moment().startOf('month'), moment().endOf('month')],
  2104. 'Last Month': [
  2105. moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')
  2106. ]
  2107. };
  2108. if (o.language.toLowerCase() === 'zh-cn' || o.language.toLowerCase() === 'zh-hans') {
  2109. localeName = {
  2110. applyLabel: "确定",
  2111. cancelLabel: "清空",
  2112. fromLabel: "起始时间",
  2113. toLabel: "结束时间'",
  2114. customRangeLabel: "自定义",
  2115. weekLabel: "W",
  2116. daysOfWeek: ["日", "一", "二", "三", "四", "五", "六"],
  2117. monthNames: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
  2118. };
  2119. ranges = {
  2120. '今日': [moment(), moment()],
  2121. '昨日': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
  2122. '最近 7 日': [moment().subtract(6, 'days'), moment()],
  2123. '最近 30 最近': [moment().subtract(29, 'days'), moment()],
  2124. '上个月': [moment().startOf('month'), moment().endOf('month')],
  2125. '本月': [
  2126. moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')
  2127. ]
  2128. };
  2129. }
  2130. dateOpt = {
  2131. format: o.format, //YYYY-MM-DD HH:MM:SS
  2132. opens: o.opens,
  2133. startDate: o.startDate ? o.startDate : false,
  2134. endDate: o.endDate ? o.endDate : false,
  2135. singleDatePicker: o.singleDatePicker,
  2136. drops: o.drops,
  2137. minDate: o.minDate,
  2138. maxDate: o.maxDate,
  2139. showCustomRangeLabel: o.showCustomRangeLabel ? o.hasRange : o.showCustomRangeLabel,
  2140. linkedCalendars: o.linkedCalendars,
  2141. showWeekNumbers: o.showWeekNumbers,
  2142. showISOWeekNumbers: o.showISOWeekNumbers,
  2143. timePicker: o.timePicker,
  2144. timePicker24Hour: o.timePicker24Hour,
  2145. timePickerIncrement: o.timePickerIncrement,
  2146. timePickerSeconds: o.timePickerSeconds,
  2147. buttonClasses: o.buttonClasses,
  2148. applyButtonClasses: o.applyButtonClasses,
  2149. cancelClass: o.cancelClass,
  2150. autoApply: o.autoApply,
  2151. autoUpdateInput: o.autoUpdateInput,
  2152. alwaysShowCalendars: o.alwaysShowCalendars,
  2153. maxSpan: o.maxSpan ? o.maxSpan : o.dayStep ? {
  2154. days: o.dayStep
  2155. } : false,
  2156. locale: o.locale ? o.locale : {
  2157. direction: 'ltr',
  2158. format: o.format,
  2159. separator: " - ", //
  2160. applyLabel: localeName.applyLabel,
  2161. cancelLabel: localeName.cancelLabel,
  2162. fromLabel: localeName.fromLabel,
  2163. toLabel: localeName.toLabel,
  2164. customRangeLabel: localeName.customRangeLabel,
  2165. weekLabel: localeName.weekLabel,
  2166. daysOfWeek: localeName.daysOfWeek,
  2167. monthNames: localeName.monthNames,
  2168. firstDay: 1
  2169. },
  2170. ranges: !o.hasRange ? false : o.ranges ? o.ranges : ranges
  2171. };
  2172. console.log(dateOpt.ranges);
  2173. };
  2174. DateTime.prototype.date = function () {
  2175. var that = this, o = that.options;
  2176. that.load();
  2177. };
  2178. DateTime.prototype.dateTime = function () {
  2179. var that = this//, o = that.options;
  2180. dateOpt.locale.format = "YYYY-MM-DD HH:MM";
  2181. dateOpt.timePicker = true;
  2182. that.load();
  2183. };
  2184. DateTime.prototype.dateSecond = function () {
  2185. var that = this//, o = that.options;
  2186. dateOpt.locale.format = "YYYY-MM-DD HH:MM:SS";
  2187. dateOpt.timePicker = true;
  2188. dateOpt.timePickerSeconds = true;
  2189. that.load();
  2190. };
  2191. DateTime.prototype.dataRange = function () {
  2192. var that = this, o = that.options;
  2193. dateOpt.singleDatePicker = false;
  2194. that.load();
  2195. };
  2196. DateTime.prototype.dataRangeTime = function () {
  2197. var that = this, o = that.options;
  2198. dateOpt.locale.format = "YYYY-MM-DD HH:MM";
  2199. dateOpt.timePicker = true;
  2200. dateOpt.singleDatePicker = false;
  2201. that.load();
  2202. };
  2203. DateTime.prototype.dataRangeSecond = function () {
  2204. var that = this, o = that.options;
  2205. dateOpt.locale.format = "YYYY-MM-DD HH:MM:SS";
  2206. dateOpt.singleDatePicker = false;
  2207. dateOpt.timePicker = true;
  2208. dateOpt.timePickerSeconds = true;
  2209. that.load();
  2210. };
  2211. DateTime.prototype.load = function () {
  2212. var that = this, o = that.options;
  2213. $(that.$ele).daterangepicker(dateOpt, function (start, end, label) {
  2214. console.log('Data-Change: ' + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD') + ' ( Range: ' + label + ')');
  2215. });
  2216. var cancelEvent = o.cancelEvent && o.cancelEvent.isFunction() ? o.cancelEvent : function () { $(that.$ele).val('') }
  2217. $(that.$ele).on('cancel.daterangepicker', cancelEvent);
  2218. if (o.applyEvent && o.applyEvent.isFunction()) {
  2219. $(that.$ele).on('apply.daterangepicker', o.applyEvent);
  2220. }
  2221. $(that.$ele).on('show.daterangepicker', function () {
  2222. timeSelect2();
  2223. if (o.showEvent && o.showEvent.isFunction()) {
  2224. o.showEvent();
  2225. }
  2226. });
  2227. if (o.hideEvent && o.hideEvent.isFunction()) {
  2228. $(that.$ele).on('hide.daterangepicker', o.hideEvent);
  2229. }
  2230. if (o.showCalendarEvent && o.showCalendarEvent.isFunction()) {
  2231. $(that.$ele).on('showCalendar.daterangepicker', o.showCalendarEvent);
  2232. }
  2233. if (o.hideCalendarEvent && o.hideCalendarEvent.isFunction()) {
  2234. $(that.$ele).on('hideCalendar.daterangepicker', o.hideCalendarEvent);
  2235. }
  2236. $(that.$ele).val('');
  2237. };
  2238. DateTime.prototype.setStartDate = function (data) {
  2239. var that = this, o = that.options;
  2240. $(that.$ele).data('daterangepicker').setStartDate(data);
  2241. };
  2242. DateTime.prototype.setEndDate = function (data) {
  2243. var that = this, o = that.options;
  2244. $(that.$ele).data('daterangepicker').setEndDate(data);
  2245. };
  2246. var allowedMethods = [
  2247. 'date',
  2248. 'dateTime',
  2249. 'dateSecond',
  2250. 'dataRange',
  2251. 'dataRangeTime',
  2252. 'dataRangeSecond',
  2253. 'setStartDate',
  2254. 'setEndDate'
  2255. ];
  2256. $.fn.iwbDate = function (option) {
  2257. var value,
  2258. args = Array.prototype.slice.call(arguments, 1);
  2259. this.each(function () {
  2260. var $this = $(this);
  2261. var data = $this.data('iwb.date');
  2262. if (!data) {
  2263. data = new DateTime(this, option ? option : {});
  2264. $this.data('iwb.date', data);
  2265. data.init();
  2266. }
  2267. if (typeof option === 'string') {
  2268. if ($.inArray(option, allowedMethods) < 0) {
  2269. throw new Error("Unknown method: " + option);
  2270. }
  2271. value = data[option].apply(data, args);
  2272. } else if (option && option.method && typeof option.method === 'string') {
  2273. if ($.inArray(option.method, allowedMethods) < 0) {
  2274. throw new Error("Unknown method: " + option.method);
  2275. }
  2276. value = data[option.method].apply(data, args);
  2277. }
  2278. else {
  2279. if (!option && $this.hasClass('iwb-date')) {
  2280. data.date();
  2281. } else if ((!option || !option.method) && ($this.hasClass('iwb-date-time') || $this.hasClass('iwb-dateTime'))) {
  2282. data.dateTime();
  2283. } else if ((!option || !option.method) && ($this.hasClass('iwb-date-second') || $this.hasClass('iwb-dateSecond'))) {
  2284. data.dateSecond();
  2285. } else if ((!option || !option.method) && ($this.hasClass('iwb-date-range') || $this.hasClass('iwb-range-date'))) {
  2286. data.dataRange();
  2287. } else if ((!option || !option.method) && ($this.hasClass('iwb-date-range-time') || $this.hasClass('iwb-range-dateTime'))) {
  2288. data.dataRangeTime();
  2289. } else if ((!option || !option.method) && ($this.hasClass('iwb-date-range-second') || $this.hasClass('iwb-range-dateSecond'))) {
  2290. data.dataRangeSecond();
  2291. } else {
  2292. data.load();
  2293. }
  2294. }
  2295. });
  2296. return typeof value === 'undefined' ? this : value;
  2297. };
  2298. $.fn.iwbDateRange = function (option) {
  2299. var value,
  2300. args = Array.prototype.slice.call(arguments, 1);
  2301. this.each(function () {
  2302. var $this = $(this);
  2303. var data = $this.data('iwb.rangeDate');
  2304. if (!data) {
  2305. data = new DateTime(this, option);
  2306. $this.data('iwb.rangeDate', data);
  2307. data.init();
  2308. data.dataRange();
  2309. }
  2310. if (typeof option === 'string') {
  2311. if ($.inArray(option, allowedMethods) < 0) {
  2312. throw new Error("Unknown method: " + option);
  2313. }
  2314. value = data[option].apply(data, args);
  2315. }
  2316. });
  2317. return typeof value === 'undefined' ? this : value;
  2318. };
  2319. $('.iwb-date-time').iwbDate();
  2320. $('.iwb-date').iwbDate();
  2321. })(jQuery, window, document);
  2322. /*DateTime*/
  2323. (function ($, window, document, undefined) {
  2324. 'use strict';
  2325. var DateTime = function (ele, opt) {
  2326. this.$ele = ele,
  2327. this.defaults = {
  2328. language: 'zh-CN',
  2329. singleDatePicker: true,
  2330. dayStep: false,
  2331. opens: "center",
  2332. drops: "down",
  2333. format: "YYYY-MM-DD", //YYYY-MM-DD HH:MM:SS
  2334. showEvent: undefined,
  2335. showCalendarEvent: undefined,
  2336. hideEvent: undefined,
  2337. hideCalendarEvent: undefined,
  2338. applyEvent: undefined,
  2339. cancelEvent: undefined,
  2340. minDate: '2015-01-01',
  2341. maxDate: false,
  2342. showWeekNumbers: false,
  2343. showISOWeekNumbers: false,
  2344. timePicker: false,
  2345. timePicker24Hour: true,
  2346. timePickerIncrement: 5,
  2347. timePickerSeconds: false,
  2348. linkedCalendars: true,
  2349. showCustomRangeLabel: false,
  2350. alwaysShowCalendars: true,
  2351. autoApply: true,
  2352. autoUpdateInput: true,
  2353. buttonClasses: "btn btn-sm",
  2354. applyButtonClasses: "btn-success",
  2355. cancelClass: "btn-default",
  2356. startDate: undefined, //开始时间
  2357. endDate: undefined, //结束时间,
  2358. maxSpan: undefined,
  2359. locale: undefined,
  2360. ranges: undefined,
  2361. hasRange: false
  2362. },
  2363. this.options = $.extend({}, this.defaults, opt);
  2364. };
  2365. var dateOpt = {};
  2366. var timeSelect2 = function () {
  2367. $('.daterangepicker .calendar-time > select').select2();
  2368. }
  2369. //var abp = window.abp || {};
  2370. DateTime.prototype.init = function () {
  2371. var that = this; var o = that.options;
  2372. $.metPageCss('/Content/Libs/bootstrap-daterangepicker/daterangepicker.css', "dy-css-daterangepicker");
  2373. $.metPageJs('/Content/Libs/bootstrap-daterangepicker/daterangepicker.js', "dy-js-daterangepicker");
  2374. var lang = o.language.toLowerCase();
  2375. if (lang === 'zh-hans') {
  2376. lang = 'zh-cn';
  2377. }
  2378. moment.locale(lang);
  2379. var localeName = {
  2380. applyLabel: 'Apply',
  2381. cancelLabel: 'Cancel',
  2382. fromLabel: "",
  2383. toLabel: "",
  2384. customRangeLabel: 'Custom Range',
  2385. daysOfWeek: moment.weekdaysMin(),
  2386. monthNames: moment.monthsShort()
  2387. },
  2388. ranges = {
  2389. 'Today': [moment(), moment()],
  2390. 'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
  2391. 'Last 7 Days': [moment().subtract(6, 'days'), moment()],
  2392. 'Last 30 Days': [moment().subtract(29, 'days'), moment()],
  2393. 'This Month': [moment().startOf('month'), moment().endOf('month')],
  2394. 'Last Month': [
  2395. moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')
  2396. ]
  2397. };
  2398. dateOpt = {
  2399. format: o.format, //YYYY-MM-DD HH:MM:SS
  2400. opens: o.opens,
  2401. startDate: o.startDate ? o.startDate : false,
  2402. endDate: o.endDate ? o.endDate : false,
  2403. singleDatePicker: o.singleDatePicker,
  2404. drops: o.drops,
  2405. minDate: o.minDate,
  2406. maxDate: o.maxDate,
  2407. showCustomRangeLabel: o.showCustomRangeLabel ? o.hasRange : o.showCustomRangeLabel,
  2408. linkedCalendars: o.linkedCalendars,
  2409. showWeekNumbers: o.showWeekNumbers,
  2410. showISOWeekNumbers: o.showISOWeekNumbers,
  2411. timePicker: o.timePicker,
  2412. timePicker24Hour: o.timePicker24Hour,
  2413. timePickerIncrement: o.timePickerIncrement,
  2414. timePickerSeconds: o.timePickerSeconds,
  2415. buttonClasses: o.buttonClasses,
  2416. applyButtonClasses: o.applyButtonClasses,
  2417. cancelClass: o.cancelClass,
  2418. autoApply: o.autoApply,
  2419. autoUpdateInput: o.autoUpdateInput,
  2420. alwaysShowCalendars: o.alwaysShowCalendars,
  2421. maxSpan: o.maxSpan ? o.maxSpan : o.dayStep ? {
  2422. days: o.dayStep
  2423. } : false,
  2424. locale: o.locale ? o.locale : {
  2425. direction: 'ltr',
  2426. format: o.format,
  2427. separator: " - ", //
  2428. applyLabel: localeName.applyLabel,
  2429. cancelLabel: localeName.cancelLabel,
  2430. fromLabel: localeName.fromLabel,
  2431. toLabel: localeName.toLabel,
  2432. customRangeLabel: localeName.customRangeLabel,
  2433. weekLabel: localeName.weekLabel,
  2434. daysOfWeek: localeName.daysOfWeek,
  2435. monthNames: localeName.monthNames,
  2436. firstDay: 1
  2437. },
  2438. ranges: !o.hasRange ? false : o.ranges ? o.ranges : ranges
  2439. };
  2440. };
  2441. DateTime.prototype.date = function () {
  2442. var that = this, o = that.options;
  2443. var opt = { locale: {} };
  2444. opt.locale.format = "YYYY-MM-DD";
  2445. that.load(opt);
  2446. };
  2447. DateTime.prototype.dateTime = function () {
  2448. var that = this//, o = that.options;
  2449. var opt = { locale: {} };
  2450. opt.locale.format = "YYYY-MM-DD HH:mm";
  2451. opt.timePicker = true;
  2452. that.load(opt);
  2453. };
  2454. DateTime.prototype.dateSecond = function () {
  2455. var that = this//, o = that.options;
  2456. var opt = { locale: {} };
  2457. opt.locale.format = "YYYY-MM-DD HH:mm:SS";
  2458. opt.timePicker = true;
  2459. opt.timePickerSeconds = true;
  2460. that.load(opt);
  2461. };
  2462. DateTime.prototype.dataRange = function () {
  2463. var that = this, o = that.options;
  2464. var opt = { locale: {} };
  2465. opt.singleDatePicker = false;
  2466. that.load(opt);
  2467. };
  2468. DateTime.prototype.dataRangeTime = function () {
  2469. var that = this, o = that.options;
  2470. var opt = { locale: {} };
  2471. opt.locale.format = "YYYY-MM-DD HH:mm";
  2472. opt.timePicker = true;
  2473. opt.singleDatePicker = false;
  2474. that.load(opt);
  2475. };
  2476. DateTime.prototype.dataRangeSecond = function () {
  2477. var that = this, o = that.options;
  2478. var opt = { locale: {} };
  2479. opt.locale.format = "YYYY-MM-DD HH:mm:SS";
  2480. opt.singleDatePicker = false;
  2481. opt.timePicker = true;
  2482. opt.timePickerSeconds = true;
  2483. that.load(opt);
  2484. };
  2485. DateTime.prototype.load = function (opt) {
  2486. var that = this, o = that.options;
  2487. var option = $.extend({}, dateOpt, opt || {});
  2488. $(that.$ele).daterangepicker(option, function (start, end, label) {
  2489. console.log('Data-Change: ' + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD') + ' ( Range: ' + label + ')');
  2490. });
  2491. var cancelEvent = o.cancelEvent && o.cancelEvent.isFunction() ? o.cancelEvent : function () { $(that.$ele).val('') }
  2492. $(that.$ele).on('cancel.daterangepicker', cancelEvent);
  2493. if (o.applyEvent && o.applyEvent.isFunction()) {
  2494. $(that.$ele).on('apply.daterangepicker', o.applyEvent);
  2495. }
  2496. $(that.$ele).on('show.daterangepicker', function () {
  2497. timeSelect2();
  2498. if (o.showEvent && o.showEvent.isFunction()) {
  2499. o.showEvent();
  2500. }
  2501. });
  2502. if (o.hideEvent && o.hideEvent.isFunction()) {
  2503. $(that.$ele).on('hide.daterangepicker', o.hideEvent);
  2504. }
  2505. if (o.showCalendarEvent && o.showCalendarEvent.isFunction()) {
  2506. $(that.$ele).on('showCalendar.daterangepicker', o.showCalendarEvent);
  2507. }
  2508. if (o.hideCalendarEvent && o.hideCalendarEvent.isFunction()) {
  2509. $(that.$ele).on('hideCalendar.daterangepicker', o.hideCalendarEvent);
  2510. }
  2511. $(that.$ele).val('');
  2512. };
  2513. DateTime.prototype.setStartDate = function (data) {
  2514. var that = this, o = that.options;
  2515. $(that.$ele).data('daterangepicker').setStartDate(data);
  2516. };
  2517. DateTime.prototype.setEndDate = function (data) {
  2518. var that = this, o = that.options;
  2519. $(that.$ele).data('daterangepicker').setEndDate(data);
  2520. };
  2521. var allowedMethods = [
  2522. 'date',
  2523. 'dateTime',
  2524. 'dateSecond',
  2525. 'dataRange',
  2526. 'dataRangeTime',
  2527. 'dataRangeSecond',
  2528. 'setStartDate',
  2529. 'setEndDate'
  2530. ];
  2531. $.fn.iwbDate = function (option) {
  2532. var value,
  2533. args = Array.prototype.slice.call(arguments, 1);
  2534. this.each(function () {
  2535. var $this = $(this);
  2536. var data = $this.data('iwb.date');
  2537. if (!data) {
  2538. data = new DateTime(this, option ? option : {});
  2539. $this.data('iwb.date', data);
  2540. data.init();
  2541. }
  2542. if (typeof option === 'string') {
  2543. if ($.inArray(option, allowedMethods) < 0) {
  2544. throw new Error("Unknown method: " + option);
  2545. }
  2546. value = data[option].apply(data, args);
  2547. } else if (option && option.method && typeof option.method === 'string') {
  2548. if ($.inArray(option.method, allowedMethods) < 0) {
  2549. throw new Error("Unknown method: " + option.method);
  2550. }
  2551. value = data[option.method].apply(data, args);
  2552. }
  2553. else {
  2554. if (!option && $this.hasClass('iwb-date')) {
  2555. data.date();
  2556. } else if ((!option || !option.method) && ($this.hasClass('iwb-date-time') || $this.hasClass('iwb-dateTime'))) {
  2557. data.dateTime();
  2558. } else if ((!option || !option.method) && ($this.hasClass('iwb-date-second') || $this.hasClass('iwb-dateSecond'))) {
  2559. data.dateSecond();
  2560. } else if ((!option || !option.method) && ($this.hasClass('iwb-date-range') || $this.hasClass('iwb-range-date'))) {
  2561. data.dataRange();
  2562. } else if ((!option || !option.method) && ($this.hasClass('iwb-date-range-time') || $this.hasClass('iwb-range-dateTime'))) {
  2563. data.dataRangeTime();
  2564. } else if ((!option || !option.method) && ($this.hasClass('iwb-date-range-second') || $this.hasClass('iwb-range-dateSecond'))) {
  2565. data.dataRangeSecond();
  2566. } else {
  2567. data.load();
  2568. }
  2569. }
  2570. });
  2571. return typeof value === 'undefined' ? this : value;
  2572. };
  2573. $.fn.iwbDateRange = function (option) {
  2574. var value,
  2575. args = Array.prototype.slice.call(arguments, 1);
  2576. this.each(function () {
  2577. var $this = $(this);
  2578. var data = $this.data('iwb.rangeDate');
  2579. if (!data) {
  2580. data = new DateTime(this, option);
  2581. $this.data('iwb.rangeDate', data);
  2582. data.init();
  2583. data.dataRange();
  2584. }
  2585. if (typeof option === 'string') {
  2586. if ($.inArray(option, allowedMethods) < 0) {
  2587. throw new Error("Unknown method: " + option);
  2588. }
  2589. value = data[option].apply(data, args);
  2590. }
  2591. });
  2592. return typeof value === 'undefined' ? this : value;
  2593. };
  2594. $('.iwb-date-time').iwbDate();
  2595. $('.iwb-date').iwbDate();
  2596. })(jQuery, window, document);
  2597. /*Kindeditor*/
  2598. (function ($, window, document, undefined) {
  2599. 'use strict';
  2600. window.editor = {};
  2601. var Kindeditor = function (ele, opt) {
  2602. this.$ele = ele,
  2603. this.defaults = {
  2604. isModal: true,
  2605. tools: 'simpleTools',
  2606. resizeMode: 1,
  2607. width: '100%',
  2608. height: '300px',
  2609. bodyClass: 'article-content',
  2610. urlType: '',
  2611. uploadJson: '/system/KindEditorUploadFile',
  2612. filterMode: false,
  2613. allowFileManager: false,
  2614. langType: 'zh-CN',
  2615. 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%;}',
  2616. placeholder: '请输入...',
  2617. placeholderStyle: { fontSize: '13px', color: '#888' },
  2618. pasteImage: { postUrl: '/system/KindEditorUploadFile', placeholder: "\u53ef\u4ee5\u5728\u7f16\u8f91\u5668\u76f4\u63a5\u8d34\u56fe\u3002" },
  2619. syncAfterBlur: true,
  2620. afterChange: function () { this.sync(); },
  2621. afterBlur: function () { this.sync(); },
  2622. spellcheck: false
  2623. },
  2624. this.options = $.extend({}, this.defaults, opt);
  2625. };
  2626. var bugTools =
  2627. ['formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', '|',
  2628. 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist', 'insertunorderedlist', '|',
  2629. 'emoticons', 'image', 'code', 'link', '|', 'removeformat', 'undo', 'redo', 'fullscreen', 'source', 'about'];
  2630. var simpleTools =
  2631. ['formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', '|',
  2632. 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist', 'insertunorderedlist', '|',
  2633. 'emoticons', 'image', 'code', 'link', 'table', '|', 'removeformat', 'undo', 'redo', 'fullscreen', 'source', 'about'];
  2634. var fullTools =
  2635. ['formatblock', 'fontname', 'fontsize', 'lineheight', '|', 'forecolor', 'hilitecolor', '|', 'bold', 'italic', 'underline', 'strikethrough', '|',
  2636. 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', '|',
  2637. 'insertorderedlist', 'insertunorderedlist', '|',
  2638. 'emoticons', 'image', 'insertfile', 'hr', '|', 'link', 'unlink', '/',
  2639. 'undo', 'redo', '|', 'selectall', 'cut', 'copy', 'paste', '|', 'plainpaste', 'wordpaste', '|', 'removeformat', 'clearhtml', 'quickformat', '|',
  2640. 'indent', 'outdent', 'subscript', 'superscript', '|',
  2641. 'table', 'code', '|', 'pagebreak', 'anchor', '|',
  2642. 'fullscreen', 'source', 'preview', 'about'];
  2643. var editorToolsMap = { fullTools: fullTools, simpleTools: simpleTools, bugTools: bugTools };
  2644. //var abp = window.abp || {};
  2645. Kindeditor.prototype.init = function (options) {
  2646. var that = this, o = that.options;
  2647. options = options || {};
  2648. $.metPageCss('/Content/Libs/kindeditor/themes/default/default.css', "dy-css-kindeditor");
  2649. $.metPageJs('/Content/Libs/kindeditor/kindeditor-all-min.js', "dy-js-kindeditor");
  2650. $.metPageJs('/Content/Libs/kindeditor/lang/zh-CN.js', "dy-js-kindeditor-zh-CN");
  2651. that.setKindeditor(options);
  2652. };
  2653. Kindeditor.prototype.setKindeditor = function (options) {
  2654. var that = this, o = that.options;
  2655. var $editor = $(that.$ele);
  2656. var editorId = $editor.attr('id');
  2657. options = options || {};
  2658. options = $.extend({}, o, $editor.data(), options);
  2659. if (editorId === undefined) {
  2660. editorId = 'kindeditor-' + Math.floor(Math.random() * 10000000);
  2661. $editor.attr('id', editorId);
  2662. }
  2663. var editorTool = editorToolsMap[o.tools] || simpleTools;
  2664. /* Remove fullscreen in modal. */
  2665. if (o.isModal) {
  2666. var newEditorTool = new Array();
  2667. var i;
  2668. for (i in editorTool) {
  2669. if (editorTool.hasOwnProperty(i)) {
  2670. if (editorTool[i] !== 'fullscreen') newEditorTool.push(editorTool[i]);
  2671. }
  2672. }
  2673. editorTool = newEditorTool;
  2674. }
  2675. $.extend(options,
  2676. {
  2677. items: editorTool,
  2678. placeholder: $editor.attr('placeholder') || options.placeholder || ''
  2679. });
  2680. try {
  2681. $editor.length && window.KindEditor && window.KindEditor.remove(editorId);
  2682. var editor = window.KindEditor.create('#' + editorId, options);
  2683. window.editor['#'] = window.editor[editorId] = editor;
  2684. return editor;
  2685. } catch (e) {
  2686. console.log('kindEditor', e);
  2687. return false;
  2688. }
  2689. };
  2690. Kindeditor.prototype.remove = function () {
  2691. var that = this, o = that.options;
  2692. var $editor = $(that.$ele);
  2693. var editorId = $editor.attr('id');
  2694. if (editorId && window.KindEditor) {
  2695. window.KindEditor.remove(editorId);
  2696. $editor.data('iwb.kindEditor', undefined);
  2697. }
  2698. };
  2699. var allowedMethods = [
  2700. 'init',
  2701. 'remove',
  2702. 'setKindeditor'
  2703. ];
  2704. $.fn.iwbKindeditor = function (option) {
  2705. var value,
  2706. args = Array.prototype.slice.call(arguments, 1);
  2707. this.each(function () {
  2708. var $this = $(this);
  2709. var data = $this.data('iwb.kindEditor');
  2710. if (!data) {
  2711. data = new Kindeditor(this, option);
  2712. $this.data('iwb.kindEditor', data);
  2713. data.init();
  2714. }
  2715. if (typeof option === 'string') {
  2716. if ($.inArray(option, allowedMethods) < 0) {
  2717. throw new Error("Unknown method: " + option);
  2718. }
  2719. value = data[option].apply(data, args);
  2720. }
  2721. });
  2722. return typeof value === 'undefined' ? this : value;
  2723. };
  2724. })(jQuery, window, document);
  2725. ; (function (window, document, $) {
  2726. //开启严格模式,规范代码,提高浏览器运行效率
  2727. "use strict"
  2728. var _global;
  2729. var progressTool = function (opt) {
  2730. var defaultOption = {
  2731. OutDom: undefined,
  2732. InnerDom: undefined,
  2733. OutDomCss: null,
  2734. InnerDomCss: null,
  2735. ScaleCss: null,
  2736. initValue: 0,
  2737. curValue: 0,
  2738. isShowValue: true,
  2739. ShowValueCss: {},
  2740. moveCallback: function (curScalePer, innerDom) { },
  2741. changeEndCall: function (curScalePer, innerDom, that) { }
  2742. }
  2743. $.extend(defaultOption, opt);
  2744. this.defaultOption = defaultOption;
  2745. $.metPageCss('/Content/Css/z_Progress.css', "dy-css-z_Progress"); //初始加载外部样式CSS
  2746. this.outDom = typeof defaultOption.OutDom === "string"
  2747. ? $("#" + defaultOption.OutDom)
  2748. : defaultOption.OutDom;
  2749. this.outDom.toggleClass('z_progress');
  2750. if (defaultOption.OutDomCss != null) {
  2751. this.outDom.css(defaultOption.OutDomCss);
  2752. }
  2753. this.outDom.html('');
  2754. var innerDomStr = '<div class="z_progress-bar"><div class="Scale"></div></div>';
  2755. this.outDom.append(innerDomStr);
  2756. if (defaultOption.isShowValue) {
  2757. this.outDom.append('<span class="showValue"></span>');
  2758. this.outDom.find('.showValue').css(defaultOption.ShowValueCss);
  2759. }
  2760. this.innerDom = this.outDom.find(".z_progress-bar");
  2761. if (defaultOption.InnerDomCss != null) {
  2762. this.innerDom.css(defaultOption.InnerDomCss);
  2763. }
  2764. this.scaleDom = this.innerDom.find('.Scale');
  2765. if (defaultOption.ScaleCss != null) {
  2766. this.scaleDom.css(defaultOption.ScaleCss);
  2767. }
  2768. this.scaleWidth = this.scaleDom.width();
  2769. this.curValue = defaultOption.initValue;
  2770. this.moveBeforeVal = this.curValue;
  2771. this.setValue(this.curValue);
  2772. this.bindEvent();
  2773. }
  2774. progressTool.prototype.bindEvent = function () {
  2775. var that = this;
  2776. var outDom = that.outDom;
  2777. var innerDom = that.innerDom;
  2778. var scaleDom = that.scaleDom;
  2779. var flag = false;
  2780. scaleDom.on({
  2781. mousedown: function () {
  2782. flag = true;
  2783. that.moveBeforeVal = that.curValue;
  2784. scaleDom.css('cursor', 'w-resize');
  2785. },
  2786. mouseup: function () {
  2787. flag = false;
  2788. scaleDom.css('cursor', 'default');
  2789. that.defaultOption.changeEndCall(that.curValue, innerDom, that);
  2790. }
  2791. });
  2792. outDom.on({
  2793. mousemove: function (e) {
  2794. if (!flag) {
  2795. return;
  2796. }
  2797. var innerLeftDis = innerDom.offset().left;
  2798. var maxLength = outDom.width() + innerLeftDis;
  2799. if (e.clientX <= maxLength && e.clientX >= innerLeftDis) {
  2800. var inWidth = (e.clientX - innerLeftDis);
  2801. that.change(inWidth);
  2802. }
  2803. },
  2804. mouseup: function () {
  2805. flag = false;
  2806. that.defaultOption.changeEndCall(that.curValue, innerDom, that);
  2807. }
  2808. });
  2809. }
  2810. progressTool.prototype.change = function (inWidth) {
  2811. var that = this;
  2812. var outDom = that.outDom;
  2813. var innerDom = that.innerDom;
  2814. var scaleDom = that.scaleDom;
  2815. var scaleWidth = that.scaleWidth;
  2816. var v = Math.round(inWidth / outDom.width() * 100);
  2817. if (v === 0) {
  2818. scaleDom.css('right', '-' + scaleWidth + 'px');
  2819. } else {
  2820. scaleDom.css('right', '0px');
  2821. }
  2822. innerDom.css("width", v + "%");
  2823. //$("#showValue").html(v + "%");
  2824. if (that.defaultOption.isShowValue) {
  2825. var showValue = that.outDom.find('.showValue');
  2826. showValue.html(v + "%");
  2827. }
  2828. that.curValue = v;
  2829. that.defaultOption.moveCallback(v, innerDom);
  2830. }
  2831. progressTool.prototype.setValue = function (v) {
  2832. var that = this;
  2833. if (v === 0) {
  2834. that.scaleDom.css('right', '-' + that.scaleWidth + 'px');
  2835. } else {
  2836. that.scaleDom.css('right', '0px');
  2837. }
  2838. if (that.defaultOption.isShowValue) {
  2839. var showValue = that.outDom.find('.showValue');
  2840. showValue.html(v + "%");
  2841. }
  2842. that.innerDom.css("width", v + "%");
  2843. that.curValue = v;
  2844. //that.defaultOption.moveCallback(v);
  2845. }
  2846. progressTool.prototype.getValue = function () {
  2847. var that = this;
  2848. return that.curValue;
  2849. }
  2850. progressTool.prototype.invokeCallBack = function () {
  2851. var that = this;
  2852. that.defaultOption.moveCallback(that.curValue, that.innerDom);
  2853. }
  2854. _global = (function () {
  2855. return this || (0, eval)('this');
  2856. }());
  2857. if (typeof module !== "undefined" && module.exports) {
  2858. module.exports = progressTool;
  2859. } else if (typeof define === "function" && define.amd) {
  2860. define(function () {
  2861. return progressTool;
  2862. });
  2863. } else {
  2864. !('progressTool' in _global) && (_global.progressTool = progressTool);
  2865. }
  2866. })(window, document, $);
  2867. $.AdminBSB = {};
  2868. $.AdminBSB.options = {
  2869. colors: {
  2870. red: '#F44336',
  2871. pink: '#E91E63',
  2872. purple: '#9C27B0',
  2873. deepPurple: '#673AB7',
  2874. indigo: '#3F51B5',
  2875. blue: '#2196F3',
  2876. lightBlue: '#03A9F4',
  2877. cyan: '#00BCD4',
  2878. teal: '#009688',
  2879. green: '#4CAF50',
  2880. lightGreen: '#8BC34A',
  2881. lime: '#CDDC39',
  2882. yellow: '#ffe821',
  2883. amber: '#FFC107',
  2884. orange: '#FF9800',
  2885. deepOrange: '#FF5722',
  2886. brown: '#795548',
  2887. grey: '#9E9E9E',
  2888. blueGrey: '#607D8B',
  2889. black: '#000000',
  2890. white: '#ffffff'
  2891. },
  2892. leftSideBar: {
  2893. scrollColor: 'rgba(0,0,0,0.5)',
  2894. scrollWidth: '4px',
  2895. scrollAlwaysVisible: false,
  2896. scrollBorderRadius: '0',
  2897. scrollRailBorderRadius: '0',
  2898. scrollActiveItemWhenPageLoad: true,
  2899. breakpointWidth: 1170
  2900. },
  2901. dropdownMenu: {
  2902. effectIn: 'fadeIn',
  2903. effectOut: 'fadeOut'
  2904. }
  2905. };
  2906. /* Left Sidebar - Function =================================================================================================
  2907. * You can manage the left sidebar menu options
  2908. *
  2909. */
  2910. $.AdminBSB.leftSideBar = {
  2911. activate: function () {
  2912. var that = this;
  2913. var $body = $('body');
  2914. var $overlay = $('.overlay');
  2915. //Close sidebar
  2916. $(window).click(function (e) {
  2917. var $target = $(e.target);
  2918. if (e.target.nodeName.toLowerCase() === 'i') {
  2919. $target = $(e.target).parent();
  2920. }
  2921. if (!$target.hasClass('bars') && that.isOpen() && $target.parents('#left-sidebar').length === 0) {
  2922. //if (!$target.hasClass('js-right-sidebar'))
  2923. // $overlay.fadeOut();
  2924. $body.removeClass('overlay-open');
  2925. }
  2926. });
  2927. $.each($('.menu-toggle.toggled'), function (i, val) {
  2928. $(val).next().slideToggle(0);
  2929. });
  2930. //When page load
  2931. $.each($('.menu .list li.active'), function (i, val) {
  2932. var $activeAnchors = $(val).find('a:eq(0)');
  2933. var $parentAnchors = $(val).parentsUntil('.menu .list', 'li').children('a:first-child');
  2934. $activeAnchors = $activeAnchors.add($parentAnchors);
  2935. $activeAnchors.addClass('toggled');
  2936. $activeAnchors.next().show();
  2937. });
  2938. //Collapse or Expand Menu
  2939. $('.menu-toggle').on('click', function (e) {
  2940. var $this = $(this);
  2941. var $content = $this.next();
  2942. if ($($this.parents('ul')[0]).hasClass('list')) {
  2943. var $not = $(e.target).hasClass('menu-toggle') ? e.target : $(e.target).parents('.menu-toggle');
  2944. $.each($('.menu-toggle.toggled').not($not).next(), function (i, val) {
  2945. if ($(val).is(':visible')) {
  2946. $(val).prev().toggleClass('toggled');
  2947. $(val).slideUp();
  2948. }
  2949. });
  2950. }
  2951. $this.toggleClass('toggled');
  2952. $content.slideToggle(320);
  2953. });
  2954. //Set menu height
  2955. that.setMenuHeight();
  2956. that.checkStatuForResize(true);
  2957. $(window).resize(function () {
  2958. that.setMenuHeight();
  2959. that.checkStatuForResize(false);
  2960. });
  2961. //Set Waves
  2962. var theme = "block";
  2963. var bodyClassName = $body.prop('className');
  2964. if (bodyClassName) {
  2965. var classArray = bodyClassName.split(' ');
  2966. for (var j = 0; j < classArray.length; j++) {
  2967. if (classArray[j].indexOf('theme') === 0) {
  2968. theme = classArray[j].split('-')[1];
  2969. break;
  2970. }
  2971. }
  2972. }
  2973. Waves.attach('.menu .list a', ['waves-' + theme]);
  2974. Waves.init();
  2975. },
  2976. setMenuHeight: function (isFirstTime) {
  2977. if (typeof $.fn.slimScroll != 'undefined') {
  2978. var configs = $.AdminBSB.options.leftSideBar;
  2979. var height = ($(window).height() - ($('.legal').outerHeight() + $('.user-info').outerHeight() + $('.navbar').innerHeight()));
  2980. var $el = $('.list');
  2981. $el.slimscroll({
  2982. height: height + "px",
  2983. color: configs.scrollColor,
  2984. size: configs.scrollWidth,
  2985. alwaysVisible: configs.scrollAlwaysVisible,
  2986. borderRadius: configs.scrollBorderRadius,
  2987. railBorderRadius: configs.scrollRailBorderRadius
  2988. });
  2989. //Scroll active menu item when page load, if option set = true
  2990. if ($.AdminBSB.options.leftSideBar.scrollActiveItemWhenPageLoad) {
  2991. var $activeItem = $('.menu .list li.active');
  2992. if ($activeItem.length) {
  2993. var activeItemOffsetTop = $activeItem[0].offsetTop;
  2994. if (activeItemOffsetTop > 150) $el.slimscroll({ scrollTo: activeItemOffsetTop + 'px' });
  2995. }
  2996. }
  2997. }
  2998. },
  2999. checkStatuForResize: function (firstTime) {
  3000. var $body = $('body');
  3001. // var $openCloseBar = $('.navbar .navbar-header .bars');
  3002. var width = $body.width();
  3003. if (firstTime) {
  3004. $body.find('.content, .sidebar').addClass('no-animate').delay(1000).queue(function () {
  3005. $(this).removeClass('no-animate').dequeue();
  3006. });
  3007. }
  3008. if (width < $.AdminBSB.options.leftSideBar.breakpointWidth) {
  3009. $body.addClass('ls-closed');
  3010. //$openCloseBar.fadeIn();
  3011. }
  3012. else {
  3013. $body.removeClass('ls-closed');
  3014. //$openCloseBar.fadeOut();
  3015. }
  3016. },
  3017. isOpen: function () {
  3018. return $('body').hasClass('overlay-open');
  3019. }
  3020. };
  3021. //==========================================================================================================================
  3022. /* Right Sidebar - Function ================================================================================================
  3023. * You can manage the right sidebar menu options
  3024. *
  3025. */
  3026. $.AdminBSB.rightSideBar = {
  3027. activate: function () {
  3028. var _this = this;
  3029. var $sidebar = $('#rightsidebar');
  3030. var $overlay = $('.overlay');
  3031. //Close sidebar
  3032. $(window).click(function (e) {
  3033. var $target = $(e.target);
  3034. if (e.target.nodeName.toLowerCase() === 'i') { $target = $(e.target).parent(); }
  3035. if (!$target.hasClass('js-right-sidebar') && _this.isOpen() && $target.parents('#rightsidebar').length === 0) {
  3036. if (!$target.hasClass('bars')) $overlay.fadeOut();
  3037. $sidebar.removeClass('open');
  3038. }
  3039. });
  3040. $('.js-right-sidebar').on('click', function () {
  3041. $sidebar.toggleClass('open');
  3042. if (_this.isOpen()) { $overlay.fadeIn(); } else { $overlay.fadeOut(); }
  3043. });
  3044. },
  3045. isOpen: function () {
  3046. return $('.right-sidebar').hasClass('open');
  3047. }
  3048. }
  3049. //==========================================================================================================================
  3050. /* Searchbar - Function ================================================================================================
  3051. * You can manage the search bar
  3052. *
  3053. */
  3054. var $searchBar = $('.search-bar');
  3055. $.AdminBSB.search = {
  3056. activate: function () {
  3057. var _this = this;
  3058. //Search button click event
  3059. $('.js-search').on('click', function () {
  3060. _this.showSearchBar();
  3061. });
  3062. //Close search click event
  3063. $searchBar.find('.close-search').on('click', function () {
  3064. _this.hideSearchBar();
  3065. });
  3066. //ESC key on pressed
  3067. $searchBar.find('input[type="text"]').on('keyup', function (e) {
  3068. if (e.keyCode == 27) {
  3069. _this.hideSearchBar();
  3070. }
  3071. });
  3072. },
  3073. showSearchBar: function () {
  3074. $searchBar.addClass('open');
  3075. $searchBar.find('input[type="text"]').focus();
  3076. },
  3077. hideSearchBar: function () {
  3078. $searchBar.removeClass('open');
  3079. $searchBar.find('input[type="text"]').val('');
  3080. }
  3081. }
  3082. //==========================================================================================================================
  3083. /* Navbar - Function =======================================================================================================
  3084. * You can manage the navbar
  3085. *
  3086. */
  3087. $.AdminBSB.navbar = {
  3088. activate: function () {
  3089. var $body = $('body');
  3090. var $overlay = $('.overlay');
  3091. //Open left sidebar panel
  3092. $('.bars').on('click', function () {
  3093. $body.toggleClass('ls-closed');
  3094. //if ($body.hasClass('ls-closed')) $body.toggleClass('overlay-open');
  3095. if ($body.hasClass('overlay-open')) { $overlay.fadeIn(); } else { $overlay.fadeOut(); }
  3096. });
  3097. //Close collapse bar on click event
  3098. $('.nav [data-close="true"]').on('click', function () {
  3099. var isVisible = $('.navbar-toggle').is(':visible');
  3100. var $navbarCollapse = $('.navbar-collapse');
  3101. if (isVisible) {
  3102. $navbarCollapse.slideUp(function () {
  3103. $navbarCollapse.removeClass('in').removeAttr('style');
  3104. });
  3105. }
  3106. });
  3107. }
  3108. }
  3109. //==========================================================================================================================
  3110. /* Input - Function ========================================================================================================
  3111. * You can manage the inputs(also textareas) with name of class 'form-control'
  3112. *
  3113. */
  3114. $.AdminBSB.input = {
  3115. activate: function ($parentSelector) {
  3116. $parentSelector = $parentSelector || $('body');
  3117. //On focus event
  3118. $parentSelector.find('.form-control').focus(function () {
  3119. $(this).parent().addClass('focused');
  3120. });
  3121. //On focusout event
  3122. $parentSelector.find('.form-control').focusout(function () {
  3123. var $this = $(this);
  3124. if ($this.parents('.form-group').hasClass('form-float')) {
  3125. if ($this.val() == '') { $this.parents('.form-line').removeClass('focused'); }
  3126. }
  3127. else {
  3128. $this.parents('.form-line').removeClass('focused');
  3129. }
  3130. });
  3131. //On label click
  3132. $parentSelector.on('click', '.form-float .form-line .form-label', function () {
  3133. $(this).parent().find('input').focus();
  3134. });
  3135. //Not blank form
  3136. $parentSelector.find('.form-control').each(function () {
  3137. if ($(this).val() !== '') {
  3138. $(this).parents('.form-line').addClass('focused');
  3139. }
  3140. });
  3141. }
  3142. }
  3143. //==========================================================================================================================
  3144. /* Form - Select - Function ================================================================================================
  3145. * You can manage the 'select' of form elements
  3146. *
  3147. */
  3148. $.AdminBSB.select = {
  3149. activate: function () {
  3150. if ($.fn.selectpicker) { $('select:not(.ms)').selectpicker(); }
  3151. }
  3152. }
  3153. //==========================================================================================================================
  3154. /* DropdownMenu - Function =================================================================================================
  3155. * You can manage the dropdown menu
  3156. *
  3157. */
  3158. //$.AdminBSB.dropdownMenu = {
  3159. // activate: function () {
  3160. // var _this = this;
  3161. // $('.dropdown, .dropup, .btn-group').on({
  3162. // "show.bs.dropdown": function () {
  3163. // var dropdown = _this.dropdownEffect(this);
  3164. // _this.dropdownEffectStart(dropdown, dropdown.effectIn);
  3165. // },
  3166. // "shown.bs.dropdown": function () {
  3167. // var dropdown = _this.dropdownEffect(this);
  3168. // if (dropdown.effectIn && dropdown.effectOut) {
  3169. // _this.dropdownEffectEnd(dropdown, function () { });
  3170. // }
  3171. // },
  3172. // "hide.bs.dropdown": function (e) {
  3173. // var dropdown = _this.dropdownEffect(this);
  3174. // if (dropdown.effectOut) {
  3175. // e.preventDefault();
  3176. // _this.dropdownEffectStart(dropdown, dropdown.effectOut);
  3177. // _this.dropdownEffectEnd(dropdown, function () {
  3178. // dropdown.dropdown.removeClass('open');
  3179. // });
  3180. // }
  3181. // }
  3182. // });
  3183. // //Set Waves
  3184. // Waves.attach('.dropdown-menu li a', ['waves-block']);
  3185. // Waves.init();
  3186. // },
  3187. // dropdownEffect: function (target) {
  3188. // var effectIn = $.AdminBSB.options.dropdownMenu.effectIn, effectOut = $.AdminBSB.options.dropdownMenu.effectOut;
  3189. // var dropdown = $(target), dropdownMenu = $('.dropdown-menu', target);
  3190. // if (dropdown.length > 0) {
  3191. // var udEffectIn = dropdown.data('effect-in');
  3192. // var udEffectOut = dropdown.data('effect-out');
  3193. // if (udEffectIn !== undefined) { effectIn = udEffectIn; }
  3194. // if (udEffectOut !== undefined) { effectOut = udEffectOut; }
  3195. // }
  3196. // return {
  3197. // target: target,
  3198. // dropdown: dropdown,
  3199. // dropdownMenu: dropdownMenu,
  3200. // effectIn: effectIn,
  3201. // effectOut: effectOut
  3202. // };
  3203. // },
  3204. // dropdownEffectStart: function (data, effectToStart) {
  3205. // if (effectToStart) {
  3206. // data.dropdown.addClass('dropdown-animating');
  3207. // data.dropdownMenu.addClass('animated dropdown-animated');
  3208. // data.dropdownMenu.addClass(effectToStart);
  3209. // }
  3210. // },
  3211. // dropdownEffectEnd: function (data, callback) {
  3212. // var animationEnd = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend';
  3213. // data.dropdown.one(animationEnd, function () {
  3214. // data.dropdown.removeClass('dropdown-animating');
  3215. // data.dropdownMenu.removeClass('animated dropdown-animated');
  3216. // data.dropdownMenu.removeClass(data.effectIn);
  3217. // data.dropdownMenu.removeClass(data.effectOut);
  3218. // if (typeof callback == 'function') {
  3219. // callback();
  3220. // }
  3221. // });
  3222. // }
  3223. //}
  3224. //==========================================================================================================================
  3225. /* Browser - Function ======================================================================================================
  3226. * You can manage browser
  3227. *
  3228. */
  3229. var edge = 'Microsoft Edge';
  3230. var ie10 = 'Internet Explorer 10';
  3231. var ie11 = 'Internet Explorer 11';
  3232. var opera = 'Opera';
  3233. var firefox = 'Mozilla Firefox';
  3234. var chrome = 'Google Chrome';
  3235. var safari = 'Safari';
  3236. $.AdminBSB.browser = {
  3237. activate: function () {
  3238. var _this = this;
  3239. var className = _this.getClassName();
  3240. if (className !== '') $('html').addClass(_this.getClassName());
  3241. },
  3242. getBrowser: function () {
  3243. var userAgent = navigator.userAgent.toLowerCase();
  3244. if (/edge/i.test(userAgent)) {
  3245. return edge;
  3246. } else if (/rv:11/i.test(userAgent)) {
  3247. return ie11;
  3248. } else if (/msie 10/i.test(userAgent)) {
  3249. return ie10;
  3250. } else if (/opr/i.test(userAgent)) {
  3251. return opera;
  3252. } else if (/chrome/i.test(userAgent)) {
  3253. return chrome;
  3254. } else if (/firefox/i.test(userAgent)) {
  3255. return firefox;
  3256. } else if (!!navigator.userAgent.match(/Version\/[\d\.]+.*Safari/)) {
  3257. return safari;
  3258. }
  3259. return undefined;
  3260. },
  3261. getClassName: function () {
  3262. var browser = this.getBrowser();
  3263. if (browser === edge) {
  3264. return 'edge';
  3265. } else if (browser === ie11) {
  3266. return 'ie11';
  3267. } else if (browser === ie10) {
  3268. return 'ie10';
  3269. } else if (browser === opera) {
  3270. return 'opera';
  3271. } else if (browser === chrome) {
  3272. return 'chrome';
  3273. } else if (browser === firefox) {
  3274. return 'firefox';
  3275. } else if (browser === safari) {
  3276. return 'safari';
  3277. } else {
  3278. return '';
  3279. }
  3280. }
  3281. }
  3282. //==========================================================================================================================