admin.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. var editor="";
  2. var editor2="";
  3. var art_editor;
  4. var notify = null;
  5. var isNotifyShowing = false;
  6. var isError = false;
  7. $(function() {
  8. Notification.requestPermission(function(status) {});
  9. $("#addanswerkvip").click(function (){
  10. if(!editor.hasContents()){ //此处以非空为例
  11. alert("请输入内容");
  12. return false;
  13. }
  14. });
  15. $("#addansweragainkvip").click(function (){
  16. if(!editor2.hasContents()){ //此处以非空为例
  17. alert("请输入内容");
  18. return false;
  19. }
  20. });
  21. // 轮询查找是否有未处理的审批
  22. var permission = Notification.permission;
  23. if (permission === 'granted') {
  24. var interval = setInterval(checkNotify, 60000);
  25. if (isError) {
  26. clearInterval(interval);
  27. }
  28. }
  29. });
  30. /**
  31. * 获取未审批数量
  32. */
  33. function checkNotify() {
  34. $.ajax({
  35. url: '/examine_check',
  36. type: 'get',
  37. data: '',
  38. dataType: 'json',
  39. error: function() {
  40. console.log('数据错误');
  41. isError = true;
  42. },
  43. success: function(response) {
  44. var count = response.count;
  45. count = parseInt(count);
  46. if (count > 0 && !isNotifyShowing) {
  47. notify = new Notification("你有"+ count +"条问答需要审批", {
  48. icon: '/global/img/wen.png',
  49. body: '点击本消息可跳转至审批页',
  50. silent: true
  51. });
  52. notify.onclick = function() {
  53. notify.close();
  54. window.location.href = '/index/main_examine_manage';
  55. };
  56. notify.onshow = function () {
  57. isNotifyShowing = true;
  58. };
  59. notify.onclose = function () {
  60. isNotifyShowing = false;
  61. };
  62. }
  63. }
  64. });
  65. }
  66. function login_form() {
  67. var name = $("#name").val();
  68. var password = $("#password").val();
  69. if (name.length == 0 || password.length == 0) {
  70. alert('提示');
  71. return false;
  72. }
  73. }
  74. function user_form(){
  75. var password = $("#password").val();
  76. var confirmpw = $("#confirmpw").val();
  77. if (password != confirmpw) {
  78. alert('密码不一致');
  79. return false;
  80. }
  81. }
  82. function article_form(){
  83. var title = $("#title").val();
  84. if (title == "") {
  85. alert('请填写相关信息');
  86. return false;
  87. }
  88. }
  89. //选中所有用户
  90. function checkall(name) {
  91. var e = is_ie ? event : checkall.caller.arguments[0];
  92. obj = is_ie ? e.srcElement : e.target;
  93. var arr = document.getElementsByName(name);
  94. var k = arr.length;
  95. for(var i=0; i<k; i++) {
  96. arr[i].checked = obj.checked;
  97. }
  98. }
  99. //选中删除用户
  100. function remove(){
  101. if($("input[name='uid[]']:checked").length == 0){
  102. alert('你没有选择任何用户');
  103. return false;
  104. }
  105. if(confirm('是否同时删除用户的所有问答?')==true){
  106. document.userForm.action="/index/main_user_manage_delete/all";
  107. document.userForm.submit();
  108. }else{
  109. // document.userForm.action="/index/main_user_manage_delete/some";
  110. // document.userForm.submit();
  111. }
  112. }
  113. //设置问题状态
  114. function set_status_question(){
  115. if($("input[name='id[]']:checked").length == 0){
  116. alert('你没有选择任何问题');
  117. return false;
  118. }
  119. if(confirm('确认将问题设置为未解决.只针对已关闭的问题')==true){
  120. document.userForm.action="/index/main_question_manage_set_status";
  121. document.userForm.submit();
  122. }else{
  123. }
  124. }
  125. //关闭选中问题
  126. function colse_question(){
  127. if($("input[name='id[]']:checked").length == 0){
  128. alert('你没有选择任何问题');
  129. return false;
  130. }
  131. if(confirm('确认关闭选中问题')==true){
  132. document.userForm.action="/index/main_question_manage_close";
  133. document.userForm.submit();
  134. }else{
  135. }
  136. }
  137. //选中删除问题
  138. function remove_question(){
  139. if($("input[name='id[]']:checked").length == 0){
  140. alert('你没有选择任何问题');
  141. return false;
  142. }
  143. if(confirm('确认删除选中问答?此操作不可返回')==true){
  144. document.userForm.action="/index/main_question_manage_delete";
  145. document.userForm.submit();
  146. }else{
  147. }
  148. }
  149. //选中删除问题
  150. function remove_article(){
  151. if($("input[name='id[]']:checked").length == 0){
  152. alert('你没有选择任何公告');
  153. return false;
  154. }
  155. if(confirm('确认删除选中公告?此操作不可返回')==true){
  156. document.userForm.action="/index/main_article_delete_manage";
  157. document.userForm.submit();
  158. }else{
  159. }
  160. }
  161. function group_form(){
  162. var grouptitle = $("#grouptitle").val();
  163. if (grouptitle=="") {
  164. alert('请填写用户组名称');
  165. return false;
  166. }
  167. }
  168. var userAgent = navigator.userAgent.toLowerCase();
  169. var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
  170. var is_moz = (navigator.product == 'Gecko')
  171. && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
  172. var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera)
  173. && userAgent.substr(userAgent.indexOf('msie') + 5, 3);
  174. function getbyid(id) {
  175. return document.getElementById(id);
  176. }
  177. Array.prototype.push = function(value) {
  178. this[this.length] = value;
  179. return this.length;
  180. }
  181. function _attachEvent(obj, evt, func) {
  182. if (obj.addEventListener) {
  183. obj.addEventListener(evt, func, false);
  184. } else if (obj.attachEvent) {
  185. obj.attachEvent("on" + evt, func);
  186. }
  187. }
  188. function _cancelBubble(e, returnValue) {
  189. if (!e)
  190. return;
  191. if (is_ie) {
  192. if (!returnValue)
  193. e.returnValue = false;
  194. e.cancelBubble = true;
  195. } else {
  196. e.stopPropagation();
  197. if (!returnValue)
  198. e.preventDefault();
  199. }
  200. }
  201. function checkall(name) {
  202. var e = is_ie ? event : checkall.caller.arguments[0];
  203. obj = is_ie ? e.srcElement : e.target;
  204. var arr = document.getElementsByName(name);
  205. var k = arr.length;
  206. for ( var i = 0; i < k; i++) {
  207. arr[i].checked = obj.checked;
  208. }
  209. }
  210. function getposition(obj) {
  211. var r = new Array();
  212. r['x'] = obj.offsetLeft;
  213. r['y'] = obj.offsetTop;
  214. while (obj = obj.offsetParent) {
  215. r['x'] += obj.offsetLeft;
  216. r['y'] += obj.offsetTop;
  217. }
  218. return r;
  219. }
  220. function addMouseEvent(obj) {
  221. var checkbox, atr, ath, i;
  222. atr = obj.getElementsByTagName("tr");
  223. for (i = 0; i < atr.length; i++) {
  224. atr[i].onclick = function() {
  225. ath = this.getElementsByTagName("th");
  226. checkbox = this.getElementsByTagName("input")[0];
  227. if (!ath.length && checkbox.getAttribute("type") == "checkbox") {
  228. if (this.className != "currenttr") {
  229. this.className = "currenttr";
  230. checkbox.checked = true;
  231. } else {
  232. this.className = "";
  233. checkbox.checked = false;
  234. }
  235. }
  236. }
  237. }
  238. }
  239. // editor.js
  240. if (is_ie)
  241. document.documentElement.addBehavior("#default#userdata");
  242. function setdata(key, value) {
  243. if (is_ie) {
  244. document.documentElement.load(key);
  245. document.documentElement.setAttribute("value", value);
  246. document.documentElement.save(key);
  247. return document.documentElement.getAttribute("value");
  248. } else {
  249. sessionStorage.setItem(key, value);
  250. }
  251. }
  252. function getdata(key) {
  253. if (is_ie) {
  254. document.documentElement.load(key);
  255. return document.documentElement.getAttribute("value");
  256. } else {
  257. return sessionStorage.getItem(key)
  258. && sessionStorage.getItem(key).toString().length == 0 ? ''
  259. : (sessionStorage.getItem(key) == null ? '' : sessionStorage
  260. .getItem(key));
  261. }
  262. }
  263. function form_option_selected(obj, value) {
  264. for ( var i = 0; i < obj.options.length; i++) {
  265. if (obj.options[i].value == value) {
  266. obj.options[i].selected = true;
  267. }
  268. }
  269. }
  270. function setselect(selectobj, value) {
  271. var len = selectobj.options.length;
  272. for (i = 0; i < len; i++) {
  273. if (selectobj.options[i].value == value) {
  274. selectobj.options[i].selected = true;
  275. }
  276. }
  277. }
  278. function show(id, display) {
  279. if (!getbyid(id))
  280. return false;
  281. if (display == 'auto') {
  282. getbyid(id).style.display = getbyid(id).style.display == '' ? 'none'
  283. : '';
  284. } else {
  285. getbyid(id).style.display = display;
  286. }
  287. }
  288. function category_form(){
  289. var title = $("#name").val();
  290. if (title == "") {
  291. alert('请填写相关信息');
  292. return false;
  293. }
  294. }
  295. //选中删除分类
  296. function remove_category(){
  297. if($("input[name='id[]']:checked").length == 0){
  298. alert('你没有选择任何分类');
  299. return false;
  300. }
  301. if(confirm('确认删除选中分类和属于该分类的所有问题?此操作不可返回')==true){
  302. document.userForm.action="/index/main_category_delete_manage";
  303. document.userForm.submit();
  304. }else{
  305. }
  306. }
  307. //选中删除分类
  308. function remove_answer(){
  309. if($("input[name='id[]']:checked").length == 0){
  310. alert('你没有选择回答');
  311. return false;
  312. }
  313. if(confirm('确认删除选中回答?此操作不可返回')==true){
  314. document.userForm.action="/index/main_answer_manage_delete";
  315. document.userForm.submit();
  316. }else{
  317. }
  318. }