项目上遇到一个需求,在我们已经开发好的"会议室预约"系统上,增加一个对时间控制,具体要求如下

  只有北京会议,除管理员以外的人在预定会议室时,一次只能预约两小时,不能预约30以后的会议室。

  经过考虑以觉得,只有通过sharepoint客户端脚本实现是最简单的,以下是实现方式

引入net的验证控件

<asp:customvalidator id="CustomValidator2" runat="server" ErrorMessage="不可预定三十天以后会议室!" ClientValidationFunction="valiatorEndTime"></asp:customvalidator>
 <asp:customvalidator id="CustomValidator3" runat="server" ErrorMessage="该用户预定会议室的时间一次不得超过两小时间!" ClientValidationFunction="valiatorTime"></asp:customvalidator>

JS实现代码:

var falg=false;ExecuteOrDelayUntilScriptLoaded(getAllSiteGroups1, "sp.js");//Get All The Site Groups in SharePoint Using ECMAScriptvar groupCollection;var id=0;function getAllSiteGroups1() {var clientContext = new SP.ClientContext();this.groupCollection = clientContext.get_web().get_siteGroups();clientContext.load(groupCollection);clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceededgetAllSiteGroups),Function.createDelegate(this, this.onQueryFailedgetAllSiteGroups));}function onQuerySucceededgetAllSiteGroups() {thisHREF = document.location.href;if(thisHREF.indexOf("SPMeetingRoomBooking")>0){var groupName = 'Site Groups: \n';var groupsEnumerator = this.groupCollection.getEnumerator();while (groupsEnumerator.moveNext()) {var group = groupsEnumerator.get_current();if(group.get_title()=="会议室管理员"){id=group.get_id();}}getAllSiteGroups();}else{falg= true;}}function onQueryFailedgetAllSiteGroups(sender, args) {}//Get All The Site Groups in SharePoint Using ECMAScriptvar groupCollection;function getAllSiteGroups() {var context = new SP.ClientContext();var siteColl = context.get_site();var web = siteColl.get_rootWeb();var groupCollection = web.get_siteGroups();// Get the Our Group's ID       var _group = groupCollection.getById(id); // ID of the Group that we are checkingvar users = _group.get_users(); // Get all Users of the group
         context.load(_group);context.load(users);this._users = users;this._currentUser = web.get_currentUser(); // Get current usercontext.load(this._currentUser);context.executeQueryAsync(Function.createDelegate(this, this.CheckUserSucceededUserIsInGroup),Function.createDelegate(this, this.CheckUserfailedUserIsInGroup));}//The below Checks  if User is the member of the specified groupfunction CheckUserSucceededUserIsInGroup() {//debugger;IsInThisGroupFlag = false;var userLoginName = this._currentUser.get_loginName();if(userLoginName.split('\\')[1]=="system"){falg= true;}else if (this._users.get_count() > 0) {var _usersEnum = this._users.getEnumerator();while (_usersEnum.moveNext()) {var user = _usersEnum.get_current();if (user.get_loginName() == userLoginName) {//debugger;falg= true;}else{falg=false;}}}}function CheckUserfailedUserIsInGroup() {falg=false;}function searchFieldEditorElement(tagName, identifier, title) { var len = identifier.length; var tags = document.getElementsByTagName(tagName); for (var i = 0; i < tags.length; i++) { var tempString = tags[i].id;if (tags[i].title == title) { return tags[i]; } } return null; }function valiatorTime(source,args){var txtstartDate = searchFieldEditorElement("input", "DateTimeFieldDate", "开始时间"); var txtendDate = searchFieldEditorElement("input", "DateTimeFieldDate", "结束时间"); var startDateID = txtstartDate.id;var startDataHoursID=startDateID +"Hours";var startDataMinutesID=startDateID +"Minutes";var startDataValue=document.getElementById(startDateID ).value;var startDataHoursValue=document.getElementById(startDataHoursID).value;var startDataMinutesValue=document.getElementById(startDataMinutesID).value;var startTimestr=startDataValue+" "+startDataHoursValue+startDataMinutesValue+":00";var startTime=new Date(startTimestr);var endDateID = txtendDate.id; var endDataHoursID=endDateID+"Hours";var endDataMinutesID=endDateID+"Minutes";var endDataValue=document.getElementById(endDateID ).value;var endDataHoursValue=document.getElementById(endDataHoursID).value;var endDataMinutesValue=document.getElementById(endDataMinutesID).value;var endTimestr=endDataValue+" "+endDataHoursValue+endDataMinutesValue+":00";var endTime=new Date(endTimestr);var betTime=(endTime.getTime()-startTime.getTime())/(1000*60*60);if(betTime>2 && falg==false){args.IsValid=false;}else{args.IsValid=true;}}function valiatorEndTime(source,args1){var txtendDate = searchFieldEditorElement("input", "DateTimeFieldDate", "结束时间");var endDateID = txtendDate.id; var endDataHoursID=endDateID+"Hours";var endDataMinutesID=endDateID+"Minutes";var endDataValue=document.getElementById(endDateID ).value;var endDataHoursValue=document.getElementById(endDataHoursID).value;var endDataMinutesValue=document.getElementById(endDataMinutesID).value;var endTimestr=endDataValue+" "+endDataHoursValue+endDataMinutesValue+":00";var endTime=new Date(endTimestr);var betTime=(endTime.getTime()-new Date())/(1000*60*60*24);if(betTime>30 && falg==false){args1.IsValid=false;}else{args1.IsValid=true;}}_spBodyOnLoadFunctionNames.push("valiatorField");  

转载于:https://www.cnblogs.com/jinhailang/p/3385868.html

通过sharepoint 客户脚本,验证列表添加页面上的时间相关推荐

  1. 项目部署到服务器上页面上的时间与数据库相差8小时

    更多详细请关注博客原文:盐鱼律己-项目部署到服务器上页面上的时间与数据库相差8小时 问题描述 项目在本地运行时页面上的时间与数据库中的相同,但是部署到服务器上后页面上显示的时间比数据库中早8个小时. ...

  2. 如何利用Featue对特定的文档库或列表添加listviewtoolbar上的button

    名字有点长,实在想不出什么好名字. 我们经常会遇到一个问题,就是需要在某一个列表或者文档库视图画面的listviewtoolbar上添加一个按钮来做一些操作.比如说页面跳转,列表操作等.目前很多人都知 ...

  3. [油猴脚本开发指南]脚本往页面上添加新元素

    本节主要内容 转载自油猴中文网:https://bbs.tampermonkey.net.cn/ 李恒道QQ4548212 油猴中文网https://bbs.tampermonkey.net.cn/ ...

  4. SharePoint 使用脚本为表单绑定事件

    在SharePoint的使用过程中,我们经常需要为表单页面做一些特殊处理,比如说新建页面的时候有多选项的字段,但是只能选择指定数量的选项,尤其在新闻列表或者调查列表等特殊场景中,广泛使用. 下面,我们 ...

  5. windows2008下配置iis时出现错误“由于扩展配置问题而无法提供您请求的页面。如果该页面是脚本,请添加处理程序。如果应下载文件,请添加 MIME 映射。”...

    iis7配置php的时候配置完后可以访问php页面,但是重启后就出现403,"由于扩展配置问题而无法提供您请求的页面.如果该页面是脚本,请添加处理程序.如果应下载文件,请添加 MIME 映射 ...

  6. 这是销售人员最必不可少的Python脚本,没有之一!批量验证和添加手机号码微信好友!

    前言 今天去销售部找女友吃午餐,我看到她在忙,就没有打扰她!销售人员嘛,无非就是找客户然后推销自己要卖的产品!比如房地产销售就是卖房,4s店的销售就是卖车嘛!原来他们都有那种专门一键添加微信的脚本的, ...

  7. HTTP 错误 404.3 – Not Found 由于扩展配置问题而无法提供您请求的页面。如果该页面是脚本,请添加处理程序...

    最近新安装了win7.搭建好了环境,运行程序,发现以前用的aspx居然报错 出现如下错误: HTTP 错误 404.3 – Not Found 由于扩展配置问题而无法提供您请求的页面.如果该页面是脚本 ...

  8. WebService部署时提示:HTTP错误 404.3-Not Found,如果该页面是脚本,请添加处理程序,如果应下载文件,请添加MIME映射

    场景 在Windows上将WebService部署到IIS时 能看到服务的结构 但是点击asmx文件时提示: HTTP错误 404.3-Not Found,如果该页面是脚本,请添加处理程序,如果应下载 ...

  9. HTTP 错误 404.3 – Not Found 由于扩展配置问题而无法提供您请求的页面。如果该页面是脚本,请添加处理程序。如果应下载文件,请添加 MIME 映射。...

    今天,在vs2013中新建了一个placard.json文件,当我用jq读取它的时候,去提示404,直接在浏览器访问这个文件,提示: HTTP 错误 404.3 – Not Found 由于扩展配置问 ...

最新文章

  1. js+css实现骰子的随机转动
  2. go语言切片切片与指针
  3. python中max函数用法_Python中max函数用法实例分析
  4. 工程图样中粗实线的用途_图纸天天画,粗实线和细实线的线宽比例是多少?2:1还是3:1?...
  5. 【渝粤教育】电大中专职业生涯规划 (2)_1作业 题库
  6. 【剑指offer】面试题55 - I. 二叉树的深度(java)
  7. cuckoo沙箱常见报错总结
  8. DPDK Qos之报文处理流水线
  9. 视觉SLAM笔记(3) 视觉SLAM框架
  10. linux docker自动启动命令行,docker容器内服务随容器自启动
  11. 【kafka】kafka 数据重复的一个 案例
  12. 【Codeforces Round #442 (Div. 2) C】Slava and tanks
  13. python时间加一个月减一个月_python – 从pandas中的datetime列减去一年
  14. realtek audio console无法连接rpc服务_笔记本网络连接图标不见了怎么办?
  15. 攻防世界——MyDriver2-397
  16. 【python】BMR基础代谢率计算器的设计
  17. 一文分析 Only fullscreen opaque activities can request orientation 报错原因及解决方案
  18. 程序猿成长之路之密码学篇-DES介绍
  19. 华为od统一考试B卷【按身高体重排队】C语言 实现
  20. 【jmeter性能测试】模拟多个IP同时登录

热门文章

  1. sql ntext 替换存储过程
  2. 做一个项目,平时都用到哪些工具提高效率(上)【转】
  3. 零基础 Amazon Web Services (AWS) 入门教程图文版(四)
  4. 滚屏加载--无刷新动态加载数据技术的应用
  5. Magento: 后台添加预览按钮 View product in frontend from Magento admin
  6. 常用JavaScript函数 71 -(自我总结)
  7. 22个国外电子商务系统
  8. 西瓜书机器学习总结(一)
  9. Intellij Java注释模板
  10. 2016校招真题编程练习——微信红包(腾讯)