sudojs-rails 0.5.2 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/generators/sudojs/class/class_generator.rb +11 -11
- data/lib/generators/sudojs/helpers.rb +4 -0
- data/lib/generators/sudojs/install/install_generator.rb +13 -8
- data/lib/generators/sudojs/install/templates/app_manifest.js +1 -1
- data/lib/generators/sudojs/install/templates/namespace.coffee +1 -2
- data/lib/generators/sudojs/install/templates/namespace.js +1 -2
- data/lib/generators/sudojs/install/templates/sudo_js.erb.yml +3 -0
- data/lib/sudojs/version.rb +1 -1
- data/vendor/assets/javascripts/sudojs/sudo.js +26 -300
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b335124bd3f573c78ba8b97c203fd8c22aa9bbd2
|
4
|
+
data.tar.gz: 4ddebbc8b02899b70b745f4f5283e679a004beac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 817e532d80a8fcaf0d1578946dca62aa3af61e3c3d54ec3572153751c4a602e9135473a3a48af3aa048ef2edc1fbfcaa800a4fde6c9da458cf79dc7b89757295
|
7
|
+
data.tar.gz: f9e95e817a8053c93bca274bc5637d5d15125002027794f1e2083a79ee0b25323b7515c256400c2d031c8c0e8ae0ebd849a1a1cb8d7afe9eea156dd2f84d3a1c
|
@@ -24,15 +24,15 @@ module Sudojs
|
|
24
24
|
'ViewController' => '_.ViewController'
|
25
25
|
}
|
26
26
|
|
27
|
-
@js_app_path =
|
28
|
-
@css_app_path =
|
29
|
-
@js_model_path =
|
30
|
-
@js_views_path =
|
31
|
-
@css_views_path =
|
27
|
+
@js_app_path = "#{path_prefix}app/assets/javascripts/views/application"
|
28
|
+
@css_app_path = "#{path_prefix}app/assets/stylesheets/views/application"
|
29
|
+
@js_model_path = "#{path_prefix}app/assets/javascripts/models"
|
30
|
+
@js_views_path = "#{path_prefix}app/assets/javascripts/views"
|
31
|
+
@css_views_path = "#{path_prefix}app/assets/stylesheets/views"
|
32
32
|
|
33
33
|
# was the js_dir option passed
|
34
34
|
if options[:js_dir] != ''
|
35
|
-
@js_dir = "app/assets/javascripts/#{options[:js_dir]}"
|
35
|
+
@js_dir = "#{path_prefix}app/assets/javascripts/#{options[:js_dir]}"
|
36
36
|
else
|
37
37
|
@js_dir = nil
|
38
38
|
end
|
@@ -70,7 +70,7 @@ module Sudojs
|
|
70
70
|
@js_req = 'models'
|
71
71
|
skip_css = true
|
72
72
|
namespace = 'lib.models'
|
73
|
-
when '_.View', '_.
|
73
|
+
when '_.View', '_.ViewManager', 'DataView'
|
74
74
|
@args = 'el, data'
|
75
75
|
@js_path = @js_views_path
|
76
76
|
@js_req = 'views'
|
@@ -127,8 +127,8 @@ module Sudojs
|
|
127
127
|
# user passed option can take precedence
|
128
128
|
req = "require #{@js_dir || @js_path}/#{@c_name}/#{@a_name}"
|
129
129
|
end
|
130
|
-
filename = "app/assets/javascripts/manifests/#{@c_name}.js"
|
131
|
-
css_filename = "app/assets/stylesheets/manifests/#{@c_name}.css"
|
130
|
+
filename = "#{path_prefix}app/assets/javascripts/manifests/#{@c_name}.js"
|
131
|
+
css_filename = "#{path_prefix}app/assets/stylesheets/manifests/#{@c_name}.css"
|
132
132
|
|
133
133
|
line = js_pre + req
|
134
134
|
css_line = css_pre + req + "\n"
|
@@ -156,7 +156,7 @@ module Sudojs
|
|
156
156
|
end
|
157
157
|
|
158
158
|
def modify_view_if_exists
|
159
|
-
filename = "app/views/#{@c_name}/#{@a_name}#{html_extension}"
|
159
|
+
filename = "#{path_prefix}app/views/#{@c_name}/#{@a_name}#{html_extension}"
|
160
160
|
if File.exist? filename
|
161
161
|
# TODO other pre-processors may need entries here
|
162
162
|
if js_extension == '.js.coffee'
|
@@ -164,7 +164,7 @@ module Sudojs
|
|
164
164
|
else
|
165
165
|
comment = '//'
|
166
166
|
end
|
167
|
-
note = "#{comment} Optional invocation of your new Class.\n#{comment} Place this into a
|
167
|
+
note = "#{comment} Optional invocation of your new Class.\n#{comment} Place this into a $ document ready block."
|
168
168
|
content = "\n#{note}\n#{comment} #{@path_to_object}.#{@a_camel} = new #{@path_to_object}.#{@a_pascal}(#{@args});"
|
169
169
|
append_to_file filename, content
|
170
170
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module Sudojs
|
2
2
|
module Generators
|
3
3
|
class InstallGenerator < Rails::Generators::Base
|
4
|
+
|
4
5
|
source_root File.expand_path('../templates', __FILE__)
|
5
6
|
|
6
7
|
class_option :html_extension, :type => :string, :aliases => '--html_extension', :default => '.erb',
|
@@ -11,9 +12,13 @@ module Sudojs
|
|
11
12
|
|
12
13
|
class_option :css_extension, :type => :string, :default => '.css', :aliases => '--css_extension',
|
13
14
|
:desc => 'Which css extension to use'
|
15
|
+
|
14
16
|
class_option :skip_css, :type => :boolean, :aliases => '--skip-css', :default => false,
|
15
17
|
:desc => 'Skip the generation of any css files along with js'
|
16
18
|
|
19
|
+
class_option :path_prefix, :type => :string, :aliases => '--path_prefix', :default => '',
|
20
|
+
:desc => 'prefix a path to the default rails app type `app/assets/...`'
|
21
|
+
|
17
22
|
def create_yaml
|
18
23
|
if options[:skip_css]
|
19
24
|
@skip_css = 'true'
|
@@ -25,8 +30,8 @@ module Sudojs
|
|
25
30
|
|
26
31
|
def create_dir_structure
|
27
32
|
%W{manifests models views}.each do |dir|
|
28
|
-
directory = "app/assets/javascripts/#{dir}"
|
29
|
-
css_directory = "app/assets/stylesheets/#{dir}"
|
33
|
+
directory = "#{options[:path_prefix]}app/assets/javascripts/#{dir}"
|
34
|
+
css_directory = "#{options[:path_prefix]}app/assets/stylesheets/#{dir}"
|
30
35
|
unless File.directory? directory
|
31
36
|
empty_directory directory
|
32
37
|
end
|
@@ -38,22 +43,22 @@ module Sudojs
|
|
38
43
|
end
|
39
44
|
end
|
40
45
|
# place the application/ in the views/
|
41
|
-
empty_directory
|
42
|
-
empty_directory
|
46
|
+
empty_directory "#{options[:path_prefix]}app/assets/javascripts/views/application"
|
47
|
+
empty_directory "#{options[:path_prefix]}app/assets/stylesheets/views/application"
|
43
48
|
end
|
44
49
|
|
45
50
|
def place_install_files
|
46
|
-
copy_file 'app_manifest.js',
|
51
|
+
copy_file 'app_manifest.js', "#{options[:path_prefix]}app/assets/javascripts/manifests/application.js"
|
47
52
|
unless options[:skip_css]
|
48
|
-
copy_file 'app_manifest.css',
|
53
|
+
copy_file 'app_manifest.css', "#{options[:path_prefix]}app/assets/stylesheets/manifests/application.css"
|
49
54
|
end
|
50
55
|
|
51
56
|
# TODO templates for other javascript pre-processors
|
52
57
|
if options[:js_extension] == '.coffee'
|
53
|
-
copy_file 'namespace.coffee', "app/assets/javascripts/views/application/page.js.coffee"
|
58
|
+
copy_file 'namespace.coffee', "#{options[:path_prefix]}app/assets/javascripts/views/application/page.js.coffee"
|
54
59
|
else
|
55
60
|
# for now any other js flavor gets the baseline .js
|
56
|
-
copy_file 'namespace.js', "app/assets/javascripts/views/application/page.js#{options[:js_extension] if options[:js_extension] != '.js'}"
|
61
|
+
copy_file 'namespace.js', "#{options[:path_prefix]}app/assets/javascripts/views/application/page.js#{options[:js_extension] if options[:js_extension] != '.js'}"
|
57
62
|
end
|
58
63
|
|
59
64
|
end
|
data/lib/sudojs/version.rb
CHANGED
@@ -519,7 +519,7 @@ sudo.Container.prototype.send = function send(/*args*/) {
|
|
519
519
|
else if(typeof args[0] === 'string') meth = args.shift();
|
520
520
|
// less common but viable options
|
521
521
|
if(!meth) {
|
522
|
-
// passed as a
|
522
|
+
// passed as a custom data attr bound in events
|
523
523
|
meth = 'data' in args[0] ? args[0].data.sendMethod :
|
524
524
|
// passed in a hash from something or not passed at all
|
525
525
|
args[0].sendMethod || void 0;
|
@@ -547,12 +547,12 @@ sudo.Container.prototype.send = function send(/*args*/) {
|
|
547
547
|
// based on the `tagName` (`div` by default). Specify `className`, `id` (or other attributes if desired)
|
548
548
|
// as an (optional) `attributes` object literal on the `data` arg.
|
549
549
|
//
|
550
|
-
// The view object uses
|
551
|
-
// and event delegation etc... A
|
550
|
+
// The view object uses zepto for dom manipulation
|
551
|
+
// and event delegation etc... A querified `this` reference is located
|
552
552
|
// at `this.$el` and `this.$` scopes queries to this objects `el`, i.e it's
|
553
553
|
// a shortcut for `this.$el.find(selector)`
|
554
554
|
//
|
555
|
-
// `param` {string|element|
|
555
|
+
// `param` {string|element|Query} `el`. Otional el for the View instance.
|
556
556
|
// `param` {Object} `data`. Optional data object-literal which becomes the initial state
|
557
557
|
// of a new model located at `this.model`. Also can be a reference to an existing sudo.Model instance
|
558
558
|
//
|
@@ -597,7 +597,7 @@ sudo.View.prototype._normalizedEl_ = function _normalizedEl_(el) {
|
|
597
597
|
if(typeof el === 'string') {
|
598
598
|
return $(el);
|
599
599
|
} else {
|
600
|
-
// Passed an already `
|
600
|
+
// Passed an already `querified` Element?
|
601
601
|
// It will have a length of 1 if so.
|
602
602
|
return el.length ? el : $(el);
|
603
603
|
}
|
@@ -623,7 +623,7 @@ sudo.View.prototype.resignPremier = function resignPremier(cb) {
|
|
623
623
|
sudo.View.prototype.role = 'view';
|
624
624
|
// ###setEl
|
625
625
|
// A view must have an element, set that here.
|
626
|
-
// Stores a
|
626
|
+
// Stores a querified object as `this.$el` the raw
|
627
627
|
// node is always then available as `this.$el[0]`.
|
628
628
|
//
|
629
629
|
// `param` {string=|element} `el`
|
@@ -644,135 +644,11 @@ sudo.View.prototype.setEl = function setEl(el) {
|
|
644
644
|
// Return a single Element matching `sel` scoped to this View's el.
|
645
645
|
// This is an alias to `this.$el.find(sel)`.
|
646
646
|
//
|
647
|
-
// `param` {string} `sel`. A
|
648
|
-
// `returns` {
|
647
|
+
// `param` {string} `sel`. A Query compatible selector
|
648
|
+
// `returns` {Query} A 'querified' result matching the selector
|
649
649
|
sudo.View.prototype.$ = function(sel) {
|
650
650
|
return this.$el.find(sel);
|
651
651
|
};
|
652
|
-
// ##ViewController Class Object
|
653
|
-
|
654
|
-
// ViewControllers were designed for Rails projects for 2 specific use-cases:
|
655
|
-
//
|
656
|
-
// 1. ViewControllers can instantiate any `descriptors` found in their model
|
657
|
-
// when constructing, adding them as `child` objects. Why? Sometimes a 'partial' will
|
658
|
-
// need to define a javascript object that should, by design, be the child of a parent View
|
659
|
-
// that is itself defined on the Rails view that owns the 'partial'. Since any JS introduced
|
660
|
-
// by a partial will be parsed before the JS on its parent Rails View this usually isn't possible.
|
661
|
-
// Our solution? Pushing `Descriptor objects` (see docs) into an array (somewhere in your namespace) from a
|
662
|
-
// 'partial' and then passing a reference to that array into the ViewController as 'descriptors'
|
663
|
-
// in its optional data argument when instantiated. The ViewController will then iterate over those
|
664
|
-
// and instantiate them, adding them as children as it goes (also setting up any stated observers)
|
665
|
-
//
|
666
|
-
// 2. ViewControllers also abstract away connecting UJS style events by allowing the developer to
|
667
|
-
// pass in the name(s) of any desired UJS events to observe: `ujsEvent: ajax:success` for example,
|
668
|
-
// and expect that a method named onAjaxSuccess, if present on the ViewController, will be called
|
669
|
-
// with the arguments returned by the UJS plugin*
|
670
|
-
//
|
671
|
-
// `param` {string|element} `el`. Otional el for the View instance.
|
672
|
-
// `param` {object} `data`. Optional data object.
|
673
|
-
//
|
674
|
-
// `see` sudo.View.
|
675
|
-
//
|
676
|
-
// `constructor`
|
677
|
-
sudo.ViewController = function(el, data) {
|
678
|
-
sudo.View.call(this, el, data);
|
679
|
-
// map the names of events to methods we expect to proxy to
|
680
|
-
this.eventMap = {
|
681
|
-
'ajax:before': 'onAjaxBefore',
|
682
|
-
'ajax:beforeSend': 'onAjaxBeforeSend',
|
683
|
-
'ajax:success': 'onAjaxSuccess',
|
684
|
-
'ajax:error': 'onAjaxError',
|
685
|
-
'ajax:complete': 'onAjaxComplete',
|
686
|
-
'ajax:aborted:required': 'onAjaxAbortedRequired',
|
687
|
-
'ajax:aborted:file': 'onAjaxAbortedFile'
|
688
|
-
};
|
689
|
-
// can be called again if mapping changes...
|
690
|
-
if(data) {
|
691
|
-
this.doMapping();
|
692
|
-
if('descriptor' in data) this.instantiateChildren([data.descriptor]);
|
693
|
-
else if('descriptors' in data) this.instantiateChildren();
|
694
|
-
}
|
695
|
-
if(this.role === 'viewController') this.init();
|
696
|
-
};
|
697
|
-
// ViewController inherits from View.
|
698
|
-
// `private`
|
699
|
-
sudo.inherit(sudo.View, sudo.ViewController);
|
700
|
-
// ###doMapping
|
701
|
-
//
|
702
|
-
// assign the proxy mapping for events. This can be called at any time
|
703
|
-
// if the listened for events change
|
704
|
-
//
|
705
|
-
// `returns` {Object} `this`
|
706
|
-
sudo.ViewController.prototype.doMapping = function() {
|
707
|
-
// either a single event or an array of them
|
708
|
-
var i,
|
709
|
-
toMap = this.model.data.ujsEvent || this.model.data.ujsEvents;
|
710
|
-
if(toMap) {
|
711
|
-
if(typeof toMap === 'string') this._mapEvent_(toMap);
|
712
|
-
else {
|
713
|
-
for(i = 0; i < toMap.length; i++) {
|
714
|
-
this._mapEvent_(toMap[i]);
|
715
|
-
}
|
716
|
-
}
|
717
|
-
}
|
718
|
-
return this;
|
719
|
-
};
|
720
|
-
// ###_handleObserve_
|
721
|
-
// Helper for instantiateChildren
|
722
|
-
// `private`
|
723
|
-
sudo.ViewController.prototype._handleObserve_ = function _handleObserve_(obs, c) {
|
724
|
-
var obj = obs.object ? this._objectForPath_(obs.object) : this.model;
|
725
|
-
obj.observe(c[obs.cb].bind(c));
|
726
|
-
};
|
727
|
-
// ###instantiateChildren
|
728
|
-
// instantiate the children described in the passed in array or the `descriptors` array
|
729
|
-
// set in this object's data store
|
730
|
-
//
|
731
|
-
// `returns` {object} `this`
|
732
|
-
sudo.ViewController.prototype.instantiateChildren = function instantiateChildren(ary) {
|
733
|
-
var i, j, curr, c, d = ary || this.model.data.descriptors;
|
734
|
-
for(i = 0; i < d.length; i++) {
|
735
|
-
curr = d[i];
|
736
|
-
c = new curr.is_a(curr.el, curr.data);
|
737
|
-
this.addChild(c, curr.name);
|
738
|
-
// handle any observe(s)
|
739
|
-
if('observe' in curr) {
|
740
|
-
this._handleObserve_(curr.observe, c);
|
741
|
-
}
|
742
|
-
else if('observes' in curr) {
|
743
|
-
for(j = 0; j < curr.observes.length; j++) {
|
744
|
-
this._handleObserve_(curr.observes[j], c);
|
745
|
-
}
|
746
|
-
}
|
747
|
-
}
|
748
|
-
return this;
|
749
|
-
};
|
750
|
-
// ###_mapEvent_
|
751
|
-
// Maps the ajax:event names to methods
|
752
|
-
// `private`
|
753
|
-
sudo.ViewController.prototype._mapEvent_ = function _mapEvent_(name) {
|
754
|
-
// because the signatures vary we need specific methods
|
755
|
-
this.$el.on(name, this[this.eventMap[name]].bind(this));
|
756
|
-
};
|
757
|
-
// ###_objectForPath_
|
758
|
-
// The objects used for callbacks and connections need to be
|
759
|
-
// looked-up via a key-path like address as they likely will not exist
|
760
|
-
// when viewController's are instantiated.
|
761
|
-
// `private`
|
762
|
-
sudo.ViewController.prototype._objectForPath_ = function _objectForPath_(path) {
|
763
|
-
return sudo.getPath(path, window);
|
764
|
-
};
|
765
|
-
// Virtual methods to override in your child classes for
|
766
|
-
// any events you chose to listen for
|
767
|
-
sudo.ViewController.prototype.onAjaxAbortedFile = $.noop;
|
768
|
-
sudo.ViewController.prototype.onAjaxAbortedRequired = $.noop;
|
769
|
-
sudo.ViewController.prototype.onAjaxBefore = $.noop;
|
770
|
-
sudo.ViewController.prototype.onAjaxBeforeSend = $.noop;
|
771
|
-
sudo.ViewController.prototype.onAjaxComplete = $.noop;
|
772
|
-
sudo.ViewController.prototype.onAjaxSuccess = $.noop;
|
773
|
-
sudo.ViewController.prototype.onAjaxError = $.noop;
|
774
|
-
// `private`
|
775
|
-
sudo.ViewController.prototype.role = 'viewController';
|
776
652
|
// ###Templating
|
777
653
|
|
778
654
|
// Allow the default {{ js code }}, {{= key }}, and {{- escape stuff }}
|
@@ -925,7 +801,7 @@ sudo.DataView.prototype.addedToParent = function(parent) {
|
|
925
801
|
// there may not be yet as some get added later by a ViewController
|
926
802
|
sudo.DataView.prototype.build = function build() {
|
927
803
|
var t;
|
928
|
-
if(!(t = this.model.data.template)) return;
|
804
|
+
if(!(t = this.model.data.template)) return this;
|
929
805
|
if(typeof t === 'string') t = sudo.template(t);
|
930
806
|
this.$el.html(t(this.model.data));
|
931
807
|
this.built = true;
|
@@ -1387,165 +1263,6 @@ sudo.extensions.observable = {
|
|
1387
1263
|
return this.deliverChangeRecords();
|
1388
1264
|
}
|
1389
1265
|
};
|
1390
|
-
// ##Bindable Extension Object
|
1391
|
-
|
1392
|
-
// Bindable methods allow various properties and attributes of
|
1393
|
-
// a sudo Class Object to be synchronized with the data contained
|
1394
|
-
// in a changeRecord recieved via observe().
|
1395
|
-
//
|
1396
|
-
// `namespace`
|
1397
|
-
sudo.extensions.bindable = {
|
1398
|
-
// List of attributes - $.attr() to be used.
|
1399
|
-
//
|
1400
|
-
// `private`
|
1401
|
-
_attr_: {
|
1402
|
-
accesskey: true,
|
1403
|
-
align: true,
|
1404
|
-
alt: true,
|
1405
|
-
contenteditable: true,
|
1406
|
-
draggable: true,
|
1407
|
-
href: true,
|
1408
|
-
label: true,
|
1409
|
-
name: true,
|
1410
|
-
rel: true,
|
1411
|
-
src: true,
|
1412
|
-
tabindex: true,
|
1413
|
-
title: true
|
1414
|
-
},
|
1415
|
-
// Some bindings defer to jQuery.css() to be bound.
|
1416
|
-
//
|
1417
|
-
// `private`
|
1418
|
-
_css_: {
|
1419
|
-
display: true,
|
1420
|
-
visibility: true
|
1421
|
-
},
|
1422
|
-
// ###_handleAttr_
|
1423
|
-
// bind the jQuery prop() method to this object, now exposed
|
1424
|
-
// by this name, matching passed `bindings` arguments.
|
1425
|
-
//
|
1426
|
-
// `param` {string} `meth` The name of the method to be bound
|
1427
|
-
// `returns` {Object} `this`
|
1428
|
-
// `private`
|
1429
|
-
_handleAttr_: function _handleAttr_(meth) {
|
1430
|
-
this[meth] = function(obj) {
|
1431
|
-
if(obj.name === meth) this.$el.attr(meth, obj.object[obj.name]);
|
1432
|
-
return this;
|
1433
|
-
};
|
1434
|
-
return this;
|
1435
|
-
},
|
1436
|
-
// ###_handleCss_
|
1437
|
-
// bind the jQuery css() method to this object, now exposed
|
1438
|
-
// by this name, matching passed `bindings` arguments.
|
1439
|
-
//
|
1440
|
-
// `param` {string} `meth` The name of the method to be bound
|
1441
|
-
// `returns` {Object} `this`
|
1442
|
-
// `private`
|
1443
|
-
_handleCss_: function _handleCss_(meth) {
|
1444
|
-
this[meth] = function(obj) {
|
1445
|
-
if(obj.name === meth) this.$el.css(meth, obj.object[obj.name]);
|
1446
|
-
return this;
|
1447
|
-
};
|
1448
|
-
return this;
|
1449
|
-
},
|
1450
|
-
// ###_handleData_
|
1451
|
-
// bind the jQuery data() method to this object, now exposed
|
1452
|
-
// by this name, matching passed `bindings` arguments.
|
1453
|
-
//
|
1454
|
-
// `param` {string} `meth` The name of the method to be bound
|
1455
|
-
// `returns` {Object} `this`
|
1456
|
-
// `private`
|
1457
|
-
_handleData_: function _handleData_(meth) {
|
1458
|
-
this[meth] = function(obj) {
|
1459
|
-
if(obj.name === meth) {
|
1460
|
-
this.$el.data(obj.object[obj.name].key, obj.object[obj.name].value);
|
1461
|
-
return this;
|
1462
|
-
}
|
1463
|
-
};
|
1464
|
-
return this;
|
1465
|
-
},
|
1466
|
-
// ###_handleProp_
|
1467
|
-
// bind the jQuery attr() method to this object, now exposed
|
1468
|
-
// by this name, matching passed `bindings` arguments.
|
1469
|
-
//
|
1470
|
-
// NOTE: If more than 1 data-* attribute is desired you must
|
1471
|
-
// set those up manually as <obj>.data({..}) is what will be
|
1472
|
-
// constructed via this method.
|
1473
|
-
//
|
1474
|
-
// `param` {string} `meth` The name of the method to be bound.
|
1475
|
-
// `returns` {Object} `this`
|
1476
|
-
// `private`
|
1477
|
-
_handleProp_: function _handleProp_(meth) {
|
1478
|
-
this[meth] = function(obj) {
|
1479
|
-
if(obj.name === meth) this.$el.prop(meth, obj.object[obj.name]);
|
1480
|
-
return this;
|
1481
|
-
};
|
1482
|
-
return this;
|
1483
|
-
},
|
1484
|
-
// ###_handleSpec_
|
1485
|
-
// bind the jQuery shorthand methods to this object matching
|
1486
|
-
// passed `bindings` arguments.
|
1487
|
-
//
|
1488
|
-
// `param` {string} `meth` The name of the method to be bound.
|
1489
|
-
// `returns` {Object} `this`
|
1490
|
-
// `private`
|
1491
|
-
_handleSpec_: function _handleSpec_(meth) {
|
1492
|
-
this[meth] = function(obj) {
|
1493
|
-
if(obj.name === meth) this.$el[meth](obj.object[obj.name]);
|
1494
|
-
return this;
|
1495
|
-
};
|
1496
|
-
return this;
|
1497
|
-
},
|
1498
|
-
// List of properties - $.prop() to be used.
|
1499
|
-
//
|
1500
|
-
// `private`
|
1501
|
-
_prop_: {
|
1502
|
-
checked: true,
|
1503
|
-
defaultValue: true,
|
1504
|
-
disabled: true,
|
1505
|
-
location: true,
|
1506
|
-
multiple: true,
|
1507
|
-
readOnly: true,
|
1508
|
-
selected: true
|
1509
|
-
},
|
1510
|
-
// ###_setBinding_
|
1511
|
-
// Given a single explicit binding, create it. Called from
|
1512
|
-
// _setbindings_ as a convenience for normalizing the
|
1513
|
-
// single vs. multiple bindings scenario
|
1514
|
-
//
|
1515
|
-
// `param` {string} `b` The binding.
|
1516
|
-
// `private`
|
1517
|
-
_setBinding_: function _setBinding_(b) {
|
1518
|
-
if(b in this._spec_) return this[this._spec_[b]](b);
|
1519
|
-
if(b in this._css_) return this._handleCss_(b);
|
1520
|
-
if(b in this._attr_) return this._handleAttr_(b);
|
1521
|
-
if(b in this._prop_) return this._handleProp_(b);
|
1522
|
-
},
|
1523
|
-
// ###setBindings
|
1524
|
-
// Inspect the binding (in the single-bound use case), or the
|
1525
|
-
// bindings Array in this Object's data store and
|
1526
|
-
// create the bound functions expected.
|
1527
|
-
//
|
1528
|
-
// `returns` {Object} `this`
|
1529
|
-
setBindings: function setBindings() {
|
1530
|
-
var d = this.model.data, b, i;
|
1531
|
-
// handle the single binding use case
|
1532
|
-
if((b = d.binding)) return this._setBinding_(b);
|
1533
|
-
if(!(b = d.bindings)) return this;
|
1534
|
-
for(i = 0; i < b.length; i++) {
|
1535
|
-
this._setBinding_(b[i]);
|
1536
|
-
}
|
1537
|
-
return this;
|
1538
|
-
},
|
1539
|
-
// `Special` binding cases. jQuery shorthand methods to be used.
|
1540
|
-
//
|
1541
|
-
// `private`
|
1542
|
-
_spec_: {
|
1543
|
-
data: '_handleData_',
|
1544
|
-
html: '_handleSpec_',
|
1545
|
-
text: '_handleSpec_',
|
1546
|
-
val: '_handleSpec_'
|
1547
|
-
}
|
1548
|
-
};
|
1549
1266
|
// ##Listener Extension Object
|
1550
1267
|
|
1551
1268
|
// Handles event binding/unbinding via an events array in the form:
|
@@ -1644,7 +1361,7 @@ sudo.extensions.persistable = {
|
|
1644
1361
|
// state of the model on the server and set it here (via a success callback).
|
1645
1362
|
//
|
1646
1363
|
// `param` {object} `params` Hash of options for the XHR call
|
1647
|
-
// `returns` {object} The
|
1364
|
+
// `returns` {object} The XHR object
|
1648
1365
|
create: function create(params) {
|
1649
1366
|
return this._sendData_('POST', params);
|
1650
1367
|
},
|
@@ -1653,7 +1370,7 @@ sudo.extensions.persistable = {
|
|
1653
1370
|
// Delete this model on the server
|
1654
1371
|
//
|
1655
1372
|
// `param` {object} `params` Optional hash of options for the XHR
|
1656
|
-
// `returns` {object}
|
1373
|
+
// `returns` {object} Xhr
|
1657
1374
|
destroy: function destroy(params) {
|
1658
1375
|
return this._sendData_('DELETE', params);
|
1659
1376
|
},
|
@@ -1670,10 +1387,15 @@ sudo.extensions.persistable = {
|
|
1670
1387
|
opts.url || (opts.url = this.url(opts.baseUrl));
|
1671
1388
|
opts.type || (opts.type = meth);
|
1672
1389
|
opts.dataType || (opts.dataType = 'json');
|
1390
|
+
var isJson = opts.dataType === 'json';
|
1391
|
+
// by default turn off the global ajax triggers as all data
|
1392
|
+
// should flow thru the models to their observers
|
1393
|
+
opts.global || (opts.global = false);
|
1673
1394
|
// the default success callback is to set the data returned from the server
|
1674
1395
|
// or just the status as `ajaxStatus` if no data was returned
|
1675
|
-
opts.success || (opts.success = function(data, status,
|
1676
|
-
data ? this.sets(data)
|
1396
|
+
opts.success || (opts.success = function(data, status, xhr) {
|
1397
|
+
data ? this.sets((isJson && typeof data === 'string') ? JSON.parse(data) : data) :
|
1398
|
+
this.set('ajaxStatus', status);
|
1677
1399
|
}.bind(this));
|
1678
1400
|
// allow the passed in params to override any set in this model's `ajax` options
|
1679
1401
|
return params ? $.extend(opts, params) : opts;
|
@@ -1689,7 +1411,7 @@ sudo.extensions.persistable = {
|
|
1689
1411
|
//
|
1690
1412
|
// `param` {object} `params`. Optional info for the XHR call. If
|
1691
1413
|
// present will override any set in this model's `ajax` options object.
|
1692
|
-
// `returns` {object} The
|
1414
|
+
// `returns` {object} The XHR object
|
1693
1415
|
read: function read(params) {
|
1694
1416
|
return $.ajax(this._normalizeParams_('GET', null, params));
|
1695
1417
|
},
|
@@ -1699,7 +1421,7 @@ sudo.extensions.persistable = {
|
|
1699
1421
|
// or has been loaded/refreshed from the server.
|
1700
1422
|
//
|
1701
1423
|
// `param` {object} `params` Hash of options for the XHR call
|
1702
|
-
// `returns` {object} The
|
1424
|
+
// `returns` {object} The XHR object
|
1703
1425
|
save: function save(params) {
|
1704
1426
|
return ('id' in this.data) ? this.update(params) : this.create(params);
|
1705
1427
|
},
|
@@ -1707,11 +1429,15 @@ sudo.extensions.persistable = {
|
|
1707
1429
|
// The Create, Update and Patch methods all send data to the server,
|
1708
1430
|
// varying only in their HTTP method. Abstracted logic is here.
|
1709
1431
|
//
|
1710
|
-
// `returns` {object}
|
1432
|
+
// `returns` {object} Xhr
|
1711
1433
|
_sendData_: function _sendData_(meth, params) {
|
1712
1434
|
opts = $.extend({}, this.data.ajax);
|
1713
1435
|
opts.contentType || (opts.contentType = 'application/json');
|
1714
1436
|
opts.data || (opts.data = this.data);
|
1437
|
+
// assure that, in the default json case, opts.data is json
|
1438
|
+
if(opts.contentType === 'application/json' && (typeof opts.data !== 'string')) {
|
1439
|
+
opts.data = JSON.stringify(opts.data);
|
1440
|
+
}
|
1715
1441
|
// non GET requests do not 'processData'
|
1716
1442
|
if(!('processData' in opts)) opts.processData = false;
|
1717
1443
|
return $.ajax(this._normalizeParams_(meth, opts, params));
|
@@ -1727,7 +1453,7 @@ sudo.extensions.persistable = {
|
|
1727
1453
|
// or use the `save()` method (that does check).
|
1728
1454
|
//
|
1729
1455
|
// `param` {object} `params` Optional hash of options for the XHR
|
1730
|
-
// `returns` {object|bool} the
|
1456
|
+
// `returns` {object|bool} the Xhr if called false if not
|
1731
1457
|
update: function update(params) {
|
1732
1458
|
return this._sendData_((this.data.ajax.patch || params && params.patch) ?
|
1733
1459
|
'PATCH' : 'PUT', params);
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sudojs-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- robrobbins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Install the latest versions of sudo.js and provide generators for fast
|
14
14
|
and easy use.
|