Sunday, April 27, 2014

Native HTML5 Drag and Drop

http://www.html5rocks.com/en/tutorials/dnd/basics/
By Eric Bidelman                              
http://www.html5rocks.com/en/tutorials/dnd/basics/


<!DOCTYPE html>

<html>
<head>
    <meta charset="utf-8">
    <title>Native HTML5 Drag and Drop</title>

    <style>
        [draggable] {
            -moz-user-select: none;
            -khtml-user-select: none;
            -webkit-user-select: none;
            user-select: none;
            /* Required to make elements draggable in old WebKit */
            -khtml-user-drag: element;
            -webkit-user-drag: element;
        }

        .column {
            height: 70px;
            width: 170px;
            float: left;
            border: 2px solid #666666;
            background-color: #ccc;
            margin-right: 5px;
            -webkit-border-radius: 10px;
            -moz-border-radius: 10px;
            -o-border-radius: 10px;
            -ms-border-radius: 10px;
            border-radius: 10px;
            -webkit-box-shadow: inset 0 0 3px #000;
            -moz-box-shadow: inset 0 0 3px #000;
            -ms-box-shadow: inset 0 0 3px #000;
            -o-box-shadow: inset 0 0 3px #000;
            box-shadow: inset 0 0 3px #000;
            text-align: center;
            cursor: move;
        }

        .column header {
                color: #fff;
                text-shadow: #000 0 1px;
                box-shadow: 5px;
                padding: 5px;
                background: -moz-linear-gradient(left center, rgb(0,0,0), rgb(79,79,79), rgb(21,21,21));
                background: -webkit-gradient(linear, left top, right top, color-stop(0, rgb(0,0,0)), color-stop(0.50, rgb(79,79,79)), color-stop(1, rgb(21,21,21)));
                background: -webkit-linear-gradient(left center, rgb(0,0,0), rgb(79,79,79), rgb(21,21,21));
                background: -ms-linear-gradient(left center, rgb(0,0,0), rgb(79,79,79), rgb(21,21,21));
                background: -o-linear-gradient(left center, rgb(0,0,0), rgb(79,79,79), rgb(21,21,21));
                border-bottom: 1px solid #ddd;
                -webkit-border-top-left-radius: 10px;
                -moz-border-radius-topleft: 10px;
                -ms-border-radius-topleft: 10px;
                -o-border-radius-topleft: 10px;
                border-top-left-radius: 10px;
                -webkit-border-top-right-radius: 10px;
                -moz-border-radius-topright: 10px;
                -ms-border-radius-topright: 10px;
                -o-border-radius-topright: 10px;
                border-top-right-radius: 10px;
            }

        .column.over {
                border: 2px dashed #000;
            }
    </style>
</head>
<body>
    <div>
        <div id="columns">
            <div class="column">
                <header>A</header>
            </div>
            <div class="column">
                <header>B</header>
            </div>
            <div class="column">
                <header>C</header>
            </div>
        </div>

        <script>
            // Using this polyfill for safety.
            Element.prototype.hasClassName = function (name) {
                return new RegExp("(?:^|\\s+)" + name + "(?:\\s+|$)").test(this.className);
            };

            Element.prototype.addClassName = function (name) {
                if (!this.hasClassName(name)) {
                    this.className = this.className ? [this.className, name].join(' ') : name;
                }
            };

            Element.prototype.removeClassName = function (name) {
                if (this.hasClassName(name)) {
                    var c = this.className;
                    this.className = c.replace(new RegExp("(?:^|\\s+)" + name + "(?:\\s+|$)", "g"), "");
                }
            };

            (function () {
                var id_ = 'columns';
                var cols_ = document.querySelectorAll('#' + id_ + ' .column');
                var dragSrcEl_ = null;

                this.handleDragStart = function (e) {
                    e.dataTransfer.effectAllowed = 'move';
                    e.dataTransfer.setData('text/html', this.innerHTML);

                    dragSrcEl_ = this;

                    this.style.opacity = '0.4';

                    // this/e.target is the source node.
                    this.addClassName('moving');
                };

                this.handleDragOver = function (e) {
                    if (e.preventDefault) {
                        e.preventDefault(); // Allows us to drop.
                    }

                    e.dataTransfer.dropEffect = 'move';

                    return false;
                };

                this.handleDragEnter = function (e) {
                    this.addClassName('over');
                };

                this.handleDragLeave = function (e) {
                    // this/e.target is previous target element.

                    this.removeClassName('over');
                };

                this.handleDrop = function (e) {
                    // this/e.target is current target element.

                    if (e.stopPropagation) {
                        e.stopPropagation(); // stops the browser from redirecting.
                    }

                    // Don't do anything if we're dropping on the same column we're dragging.
                    if (dragSrcEl_ != this) {
                        dragSrcEl_.innerHTML = this.innerHTML;
                        this.innerHTML = e.dataTransfer.getData('text/html');
                    }

                    return false;
                };

                this.handleDragEnd = function (e) {
                    // this/e.target is the source node.
                    this.style.opacity = '1';

                    [].forEach.call(cols_, function (col) {
                        col.removeClassName('over');
                        col.removeClassName('moving');
                    });
                };

                [].forEach.call(cols_, function (col) {
                    col.setAttribute('draggable', 'true');  // Enable columns to be draggable.
                    col.addEventListener('dragstart', this.handleDragStart, false);
                    col.addEventListener('dragenter', this.handleDragEnter, false);
                    col.addEventListener('dragover', this.handleDragOver, false);
                    col.addEventListener('dragleave', this.handleDragLeave, false);
                    col.addEventListener('drop', this.handleDrop, false);
                    col.addEventListener('dragend', this.handleDragEnd, false);
                });
            })();
        </script>
    </div>
</body>
</html>

http://www.html5rocks.com/en/tutorials/dnd/basics/

Monday, April 7, 2014

Change SP2013 Central Admin theme color

Changing the theme color for Central Admin can be a safe way to make Prod look different to give admins peace of mind knowing thy are not on prod or to keep them on there tows and extra careful.

Seems simple enough, however, Central Admin does not have the “change the look” button which Team Sites have.

You can still get there by typing the in the URL to launch Change The Look.

/_layouts/15/designgallery.aspx

Or alternatively

/_layouts/themeweb.aspx

Make your changes as per usual, click “try” and then “keep.”

To not confuse others one can always keep prod on the default look and feel and changing QA and Dev to perhaps yellow and green.

Thursday, March 27, 2014

SP2013, prerequisiteinstaller, the tool was unable to install Application Server Role, Web Server (IIS) Role.

The tool was unable to install Application Server Role, Web Server (IIS) Role.


Log:
Error: The tool was unable to install Application Server Role, Web Server (IIS) Role.

Last return code (2)

Options for further diagnostics: 1. Look up the return code value 2. Download the prerequisite manually and verify size downloaded by the prerequisite installer. 3. Install the prerequisite manually from the given location without any command line options.

Cannot retry

Issue/Cause :
When you use the PrerequisiteInstaller.exe, it will execute a Windows PowerShell command to install the necessary Roles and Features to configure Windows Server 2012 for SharePoint 2013. Part of the Windows PowerShell code for Add-WindowsFeature installation installs the Windows NET-Framework-Core feature that is the Microsoft .NET Framework 3.5. This feature installation requires binaries and other files that are not included in a default installation of Windows Server 2012. These binaries and other files will be downloaded by the PrerequisiteInstaller.exe application from Windows Update through an online connection.

Fix:
Make sure you have an active internet connection and that theirs no antivirus or anything else on the network preventing the installer from accessing the files and binaries.
 
If it is still not working as a last resort you can manually download all the prerequisites or use the following power shell command, provided that there's an internet connection on the server your going to install SP2013 on.

Import-Module ServerManager

Add-WindowsFeature NET-WCF-HTTP-Activation45,NET-WCF-TCP-Activation45,NET-WCF-Pipe-Activation45

Add-WindowsFeature Net-Framework-Features,Web-Server,Web-WebServer,Web-Common-Http,Web-Static-Content,Web-Default-Doc,Web-Dir-Browsing,Web-Http-Errors,Web-App-Dev,Web-Asp-Net,Web-Net-Ext,Web-ISAPI-Ext,Web-ISAPI-Filter,Web-Health,Web-Http-Logging,Web-Log-Libraries,Web-Request-Monitor,Web-Http-Tracing,Web-Security,Web-Basic-Auth,Web-Windows-Auth,Web-Filtering,Web-Digest-Auth,Web-Performance,Web-Stat-Compression,Web-Dyn-Compression,Web-Mgmt-Tools,Web-Mgmt-Console,Web-Mgmt-Compat,Web-Metabase,Application-Server,AS-Web-Support,AS-TCP-Port-Sharing,AS-WAS-Support, AS-HTTP-Activation,AS-TCP-Activation,AS-Named-Pipes,AS-Net-Framework,WAS,WAS-Process-Model,WAS-NET-Environment,WAS-Config-APIs,Web-Lgcy-Scripting,Windows-Identity-Foundation,Server-Media-Foundation,Xps-Viewer

Note:
After you complete the Microsoft SharePoint Products Preparation Tool, you must still install the following 4 updates:

Monday, March 17, 2014

SharePoint 2013 Management Shell. The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered.


So there I was opening SharePoint 2013 Management Shell, but what I was not expecting was this wonderful welcoming message:

The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered.

Cause :

SP 2013
The user you are using does not have admin rights, however even if you have launched the Shell with an account who is a farm admin, you can come across this error because there is a big difference between using your account in Central Admin and PowerShell. When you launch operations in the Central Admin, the pool account is used witch has all the required rights on the server and the databases, but when you run commands in PowerShell, your account is used which may not have all the rights.

SP 2010
Most likely Windows Management Framework 3.0 got installed, after installing it PowerShell will start loading .Net framework 4.0. and SharePoint 2010 does not like .Net 4.0 and starts failing.

Fix:
If this was the first time you had to work on an environment or if the farm got  migrated to another server and not all the access rights came with, I would suggest getting another administrator to either manually modify the rights associated to your account in SQL Server or run the Add-SPShellAdmin command.

Add-SPShellAdmin -username DOMAIN\UserName

If you are and admin and using Windows 8 or Windows Server 2012, with the Modern UI, it is really easy to miss the Run as Administrator option. you need to right click on the tile to open the apps charm bar at the bottom of the screen, where you can select run as administrator.



Friday, March 7, 2014

Add SharePoint column through CAMLXML

Working with SP2013 Apps I have added columns via the Visual Studio wizard, programmatically and now using xml, but I could not get the lookup columns to function 100% using xml until I found the following post:

http://blogs.msdn.com/b/joshuag/archive/2008/03/14/add-sharepoint-lookup-column-declaratively-through-caml-xml.aspx

To build a feature using only CAML that will create a list with a lookup column isn't really that difficult, but it did take some digging.

When you are doing this there are two places that you have to be concerned about.

The first is when defining the column as a site column. When you define content types and custom list schemas, you should first start with your site columns.

I usually place these in a file called fields.xml, this is also what you will see if you take a look through the out of the box list schemas.

Here is an example of one of my site columns of the Lookup type







There are three properties here that are not found on a standard site column definition.

The first is "List", this, as you might have guessed, points to the URL of the list in the site.  In this example I know I am looking for the Title column in a list that is found under Lists/Leaders.

The next property to pay attention to is "ShowField", you guessed it, this is the field that you want to show in your lookup column.

The last property is "PrependId".  I'm not 100% sure on this but I think this has something to do with whether the lookup column returns the id in front of the value. The out of the box columns set this to "TRUE" and I do like to get back my item ID with my value so I set it to TRUE as well. Disclaimer: I never tested what setting it to "FALSE" does.

The next thing you will want to do is add this column to a custom list schema that you define. If you aren't familiar with custom list schemas Ted Pattison's book Inside WSS 3.0 is a great place to get familiar with this.
Quickly summarized, whenever you create a custom list, there must be a schema.xml file in a folder that is the same name as the list name.
That sounds kind of confusing, but describing how to build custom list schemas is out of the scope of this post. Ted's book explains this really well, anyway in the custom list schema one of the first sections is called "Fields". In this section, if I wanted to add my custom lookup site column to my custom list I would use the following line of CAML.






Again, if you haven't worked with this stuff before this might seem kind of redundant.  Truthfully it is, but that is just how custom list schemas work, so get used to it.  Really, that is all there is to it, everything else you want to create (content types, list templates, list instances) is all the same for lookup columns as it is a standard text column.

Note:  That I discovered recently is that, in order for this to work, the URL specified in your schema.xml file MUST MATCH the List attribute on all your Field references in field.xml and schema.xml.  If these don’t match, it will not work.  Hope that helps the folks that were having trouble.