webstaff: add angular-location-update dependency
authorGalen Charlton <gmc@esilibrary.com>
Mon, 28 Sep 2015 21:20:46 +0000 (21:20 +0000)
committerKathy Lussier <klussier@masslnc.org>
Tue, 2 Feb 2016 19:58:47 +0000 (14:58 -0500)
This module adds a $location.update_path() routine to
allow changing the URL without forcing a controller reload.

This module is copyright (c) 2015 anglibs and released under
the MIT license and is taken from
https://github.com/anglibs/angular-location-update.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Open-ILS/src/templates/staff/base_js.tt2
Open-ILS/web/js/ui/default/staff/Gruntfile.js
Open-ILS/web/js/ui/default/staff/bower.json
Open-ILS/web/js/ui/default/staff/extern/angular-location-update/.bower.json [new file with mode: 0644]
Open-ILS/web/js/ui/default/staff/extern/angular-location-update/LICENSE [new file with mode: 0644]
Open-ILS/web/js/ui/default/staff/extern/angular-location-update/README.md [new file with mode: 0644]
Open-ILS/web/js/ui/default/staff/extern/angular-location-update/angular-location-update.js [new file with mode: 0644]
Open-ILS/web/js/ui/default/staff/extern/angular-location-update/angular-location-update.min.js [new file with mode: 0644]
Open-ILS/web/js/ui/default/staff/extern/angular-location-update/bower.json [new file with mode: 0644]
Open-ILS/web/js/ui/default/staff/extern/angular-location-update/package.json [new file with mode: 0644]

index 97a2ce0..4601e9c 100644 (file)
@@ -8,6 +8,7 @@
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/build/js/angular-route.min.js"></script>
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/build/js/ui-bootstrap-tpls.min.js"></script>
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/build/js/hotkeys.min.js"></script>
+<script src="[% ctx.media_prefix %]/js/ui/default/staff/build/js/angular-location-update.min.js"></script>
 
 <!-- IDL / opensrf (network) -->
 <script src="[% ctx.media_prefix %]/js/dojo/opensrf/JSON_v1.js"></script>
index 8dcd3c1..087f0ff 100644 (file)
@@ -22,6 +22,7 @@ module.exports = function(grunt) {
             'bower_components/angular-bootstrap/ui-bootstrap.min.js',
             'bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js',
             'bower_components/angular-hotkeys/build/hotkeys.min.js',
+            'bower_components/angular-location-update/angular-location-update.min.js',
             'bower_components/jquery/dist/jquery.min.js',
           ]
         }]
index dc44126..d31ec5c 100644 (file)
@@ -26,6 +26,7 @@
     "angular-bootstrap": "~0.11.0"
   },
   "dependencies": {
-    "angular-hotkeys": "chieffancypants/angular-hotkeys#~1.2.0"
+    "angular-hotkeys": "chieffancypants/angular-hotkeys#~1.2.0",
+    "angular-location-update": "./extern/angular-location-update/"
   }
 }
diff --git a/Open-ILS/web/js/ui/default/staff/extern/angular-location-update/.bower.json b/Open-ILS/web/js/ui/default/staff/extern/angular-location-update/.bower.json
new file mode 100644 (file)
index 0000000..c31aaa7
--- /dev/null
@@ -0,0 +1,31 @@
+{
+  "name": "angular-location-update",
+  "homepage": "https://github.com/anglibs/angular-location-update",
+  "authors": [
+    "garmoshka-mo <dan@dub.ink>"
+  ],
+  "main": "angular-location-update.js",
+  "description": "Updates location path without reloading of controller",
+  "ignore": [
+    "**/.*",
+    "*.yml",
+    "*.xml",
+    "node_modules",
+    "bower_components",
+    "test",
+    "tests"
+  ],
+  "dependencies": {
+    "angular": "*"
+  },
+  "_release": "103e945c53",
+  "_resolution": {
+    "type": "branch",
+    "branch": "master",
+    "commit": "103e945c535f9c0e3479c4faf77930404c823f21"
+  },
+  "_source": "git://github.com/anglibs/angular-location-update.git",
+  "_target": "*",
+  "_originalSource": "angular-location-update",
+  "_direct": true
+}
\ No newline at end of file
diff --git a/Open-ILS/web/js/ui/default/staff/extern/angular-location-update/LICENSE b/Open-ILS/web/js/ui/default/staff/extern/angular-location-update/LICENSE
new file mode 100644 (file)
index 0000000..037a52f
--- /dev/null
@@ -0,0 +1,22 @@
+The MIT License (MIT)
+
+Copyright (c) 2015 anglibs
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
diff --git a/Open-ILS/web/js/ui/default/staff/extern/angular-location-update/README.md b/Open-ILS/web/js/ui/default/staff/extern/angular-location-update/README.md
new file mode 100644 (file)
index 0000000..1996b3a
--- /dev/null
@@ -0,0 +1,52 @@
+# angular-location-update
+
+Updates location path without reloading of controller
+
+## Install
+
+1 `bower install angular-location-update --save` or [download](http://anglibs.github.io/angular-location-update/angular-location-update.min.js) or include hosted from github.io
+````
+    <script src="//anglibs.github.io/angular-location-update/angular-location-update.min.js"></script>
+````
+
+2 Add module to your app:
+````
+  angular.module('your_app', ['ngLocationUpdate']);
+````
+
+## Usage
+
+````
+$location.update_path('/notes/1');
+$location.update_path('/notes/1/wysiwyg', true);
+````
+Parameters:
+ 1. New path
+ 1. Keep old path in browser history (By default it will be **replaced** by new one)
+
+## When it's needed?
+
+For example you have route `/notes/new` which shows form for new note.
+
+In modern web app you may have no "Save" button - note created and saved to database once user made any change.
+Then you would like to change route to `/notes/1` showing to user, that here is URL of his new document.
+Also if he will refresh page or go back and forward using browser buttons - he will see what he expects.
+
+## FYI
+
+Did you know, that you can easily change your URLs  
+
+from `http://mysite.com/#/notes/1` to `http://mysite.com/notes/1`
+
+For this: 
+ 1. Config app: `angular.module('your_app').config(function($locationProvider) { $locationProvider.html5Mode(true); });`
+ 2. Add in your HTML `<base href="/">`
+
+More info: https://docs.angularjs.org/guide/$location 
+
+## Credits
+
+Solution invented by guys in these threads:
+ 1. https://github.com/angular/angular.js/issues/1699
+ 1. https://github.com/angular-ui/ui-router/issues/427
+ 1. http://stackoverflow.com/questions/14974271/can-you-change-a-path-without-reloading-the-controller-in-angularjs
diff --git a/Open-ILS/web/js/ui/default/staff/extern/angular-location-update/angular-location-update.js b/Open-ILS/web/js/ui/default/staff/extern/angular-location-update/angular-location-update.js
new file mode 100644 (file)
index 0000000..454f3cc
--- /dev/null
@@ -0,0 +1,22 @@
+!function(angular, undefined) { 'use strict';
+
+  angular.module('ngLocationUpdate', [])
+      .run(['$route', '$rootScope', '$location', function ($route, $rootScope, $location) {
+        // todo: would be proper to change this to decorators of $location and $route
+        $location.update_path = function (path, keep_previous_path_in_history) {
+          if ($location.path() == path) return;
+
+          var routeToKeep = $route.current;
+          $rootScope.$on('$locationChangeSuccess', function () {
+            if (routeToKeep) {
+              $route.current = routeToKeep;
+              routeToKeep = null;
+            }
+          });
+
+          $location.path(path);
+          if (!keep_previous_path_in_history) $location.replace();
+        };
+      }]);
+
+}(window.angular);
diff --git a/Open-ILS/web/js/ui/default/staff/extern/angular-location-update/angular-location-update.min.js b/Open-ILS/web/js/ui/default/staff/extern/angular-location-update/angular-location-update.min.js
new file mode 100644 (file)
index 0000000..1639d3f
--- /dev/null
@@ -0,0 +1 @@
+!function(n){"use strict";n.module("ngLocationUpdate",[]).run(["$route","$rootScope","$location",function(n,t,o){o.update_path=function(c,u){if(o.path()!=c){var a=n.current;t.$on("$locationChangeSuccess",function(){a&&(n.current=a,a=null)}),o.path(c),u||o.replace()}}}])}(window.angular);
\ No newline at end of file
diff --git a/Open-ILS/web/js/ui/default/staff/extern/angular-location-update/bower.json b/Open-ILS/web/js/ui/default/staff/extern/angular-location-update/bower.json
new file mode 100644 (file)
index 0000000..5592a6d
--- /dev/null
@@ -0,0 +1,22 @@
+{
+  "name": "angular-location-update",
+  "version": "0.0.2",
+  "homepage": "https://github.com/anglibs/angular-location-update",
+  "authors": [
+    "garmoshka-mo <dan@dub.ink>"
+  ],
+  "main": "angular-location-update.js",
+  "description": "Updates location path without reloading of controller",
+  "ignore": [
+    "**/.*",
+    "*.yml",
+    "*.xml",
+    "node_modules",
+    "bower_components",
+    "test",
+    "tests"
+  ],
+  "dependencies": {
+    "angular": "*"
+  }
+}
diff --git a/Open-ILS/web/js/ui/default/staff/extern/angular-location-update/package.json b/Open-ILS/web/js/ui/default/staff/extern/angular-location-update/package.json
new file mode 100644 (file)
index 0000000..2dbebf5
--- /dev/null
@@ -0,0 +1,25 @@
+{
+  "name": "angular-location-update",
+  "version": "0.0.2",
+  "main": "angular-location-update.js",
+  "description": "Updates location path without reloading of controller",
+  "homepage": "https://github.com/anglibs/angular-location-update",
+  "bugs": "https://github.com/anglibs/angular-location-update/issues",
+  "author": {
+    "name": "garmoshka-mo",
+    "email": "dan@dub.ink"
+  },
+  "repository": {
+    "type": "git",
+    "url": "git@github.com:anglibs/angular-location-update.git"
+  },
+  "licenses": [
+    {
+      "type": "MIT"
+    }
+  ],
+  "dependencies": {
+  },
+  "devDependencies": {
+  }
+}