Étiquette : Niveau intermédiaire

Resolve Promise one after another, in sequence

Below is the code that is handy when you want to execute several Promise actions in sequence: function PromiseChain(arr, fct) { var dfd = Promise.resolve(); var res = arr.map(function(item,idx) { dfd = dfd.then(function() { return fct(item,idx) }); return dfd }); return Promise.all(res) } // for short version: // function PromiseChain(n,r){var e=Promise.resolve(),i=n.map(function(n,i){return e=e.then(function(){return r(n,i)})});return Promise.all(i)} And […]

Deep clone an object in JavaScript

We can find many discussions and solutions about this issue. In my case the one that worked is this code. Below you’ll find a compressed version of the extend() function (with a fix): function extend(){var r,t,n,o,e=arguments[0]||{},f=1,i=arguments.length,u=!1,y=function(r){if(null===r|| »object »!=typeof r||r.nodeType||null!==r&&r===r.window)return!1;try{if(r.constructor&&!this.hasOwnProperty.call(r.constructor.prototype, »isPrototypeOf »))return!1}catch(t){return!1}return!0};for(« boolean »==typeof e&&(u=e,e=arguments[f]||{},f++), »object »!=typeof e&& »function »!=typeof e&&(e={}),!1;i>f;f+=1)if(null!==(r=arguments[f]))for(t in r)e!==r[t]&& »undefined »==typeof e[t]&&(u&&r[t]&&(y(r[t])||(n=Array.isArray(r[t])))?(n?(n=!1,o=e[t]&&Array.isArray(e[t])?e[t]:[]):o=e[t]&&y(e[t])?e[t]:{},e[t]=extend(u,o,r[t])):void 0!==r[t]&&(e[t]=r[t]));return e} And here an example: var object_a = { value_1: ‘a’, […]

Check permissions in Sharepoint based on a PermMask

In some cases you could get this kind of hexadecimal numbers from Sharepoint for the PermMask: 0xb008431061, or 0x1b03c4313ff, and so on. To verify the PermMask against the different level of permissions you can proceed with the below method (using functions from core.js): var permMask = ‘0x1b03c4313ff’; var permissions = new SP.BasePermissions(); permissions.initPropertiesFromJson({High:GetPermMaskH(permMask), Low:GetPermMaskL(permMask)}); // […]

Redirect after Deleting [Sharepoint]

When I open a dialog for an EditFrom and use the « Delete Item » button from the ribbon, then the main page is redirected to the related Sharepoint list. This behavior is very bad for the user experience. To change it I used the below Javascript code: // replace the Delete Item default action when into […]

How to open an Excel document from SharePoint into Chrome/Firefox in readonly/edit mode

With Sharepoint 2010, when you use Internet Explorer you can open an Office document in readonly or in edit mode. Also, when trying to open an Excel file in Firefox/Chrome it will probably open the ugly xslviewer and won’t let you deal with your file. After searching a bit about it, I found a clue […]

Execute an action before saving a form but after the form validation [Sharepoint]

Let’s say you want to do an asynchronous request just before saving a Sharepoint form, but after Sharepoint verified all the fields in your form (for mandatory ones, or for format, …). Here is my solution to do it (using jQuery.Deferred): // this function will do our asynchronous check function beforeSaving() { var deferred=jQuery.Deferred(); setTimeout(function() […]

Disable X-Frame-Options on Sharepoint

I needed to communicate with an iframe on Sharepoint, however Sharepoint returned Load denied by X-Frame-Options … To override this limitation you have to create a Webpart page where you’ll add the code <WebPartPages:AllowFraming runat= »server » /> into the <asp:Content> section (that might work somewhere else, but I did this way). You can also add it […]

Bypass a lookup field not displayed because of threshold on NewForm and EditForm [Sharepoint 2013]

EDIT 22/Dec/2016: there is s a new version of this article at https://blog.kodono.info/wordpress/2016/12/22/2-bypass-a-lookup-field-not-displayed-because-of-threshold-on-newform-and-editform-sharepoint-2013/ Sharepoint is really annoying to limit the access to the list with more than 5,000 items… It causes many troubles, and one of them is when you use a lookup field into a form that is tied to a big list. Sharepoint […]

Incruster des sous-titres dans une vidéo

Voilà une opération qui pourrait paraitre simple et qui pourtant est difficile à trouver sur le Net… Pour cela on va utiliser le logiciel HandBrake. Commencer par le télécharger puis l’installer. On choisit notre fichier vidéo d’origine (ici un .mp4) en cliquant sur « Source » : On choisit la destination, c’est-à-dire là où notre nouveau fichier […]