Permalink
Browse files

bug with handlebars and missing parent context with partials

  • Loading branch information...
1 parent 103296d commit 4454073b395be6c2f422047a0a73027ebec630f9 @raDiesle committed Apr 22, 2012
View
1 _attachments/Resources.js
@@ -47,6 +47,7 @@ $LAB
.script(localeFolder+"default.js") // i18n
.script(localeFolder+"locales.js") // i18n
.script(srcFolder+"/adventurio/utilies/Json.js")
+ .script(srcFolder+"/adventurio/utilies/Handlebars.js")
// .script(srcFolder+"/adventurio/application/jeditable/MarkItUpSettings.js")
.script(srcFolder+"/adventurio/models/StoryModel.js")
.script(srcFolder+"/adventurio/models/User.js")
View
44 _attachments/index.html
@@ -38,33 +38,34 @@
<script id="templates_formitems_text" type="text/x-handlebars-template">
- <li>
- <a class="edit_area">{{value}}</a>
- <a href="#" data-identity="{{formItemPos}}">{{I18n "message"}}</a>
- </li>
+ <li>
+ <a class="edit_area">{{$_.value}}</a>
+ <a href="#creator/stories/{{_id }}/{{horizontal}}/{{vertical}}/{{$_.formItemPos}}" data-identity="{{formItemPos}}">{{I18n "message"}}</a>
+ </li>
</script>
<script id="templates_formitems_textfield" type="text/x-handlebars-template">
<li>
<a href="#">
<span id="textid" placeholder="Enter character name" class="ui-input-text ui-body-c ui-corner-all ui-shadow-inset" style="padding: 7px; width: auto">
- {{value}}
+ {{$_.value}}
</span>
</a>
- <a href="#" class="setFormItemProperties" >PROPERTIES</a>
+ <a href="#creator/stories/{{_id }}/{{horizontal}}/{{vertical}}/{{$_.formItemPos}}" class="setFormItemProperties" >PROPERTIES</a>
</li>
</script>
<script id="templates_forms_dynamic" type="text/x-handlebars-template">
<ul data-role="listview" data-inset="true" data-split-theme="d">
- {{#each formItems}}
+ {{#formItems}}
+
{{#ifIsTypeOf this "text"}}
- {{> templates_formitems_text}}
+ {{#$ ../../props }}{{> templates_formitems_text}}{{/$}}
{{/ifIsTypeOf}}
{{#ifIsTypeOf this "textfield"}}
- {{> templates_formitems_textfield}}
+ {{#$ ../../props }}{{> templates_formitems_textfield}}{{/$}}
{{/ifIsTypeOf}}
- {{/each}}
+ {{/formItems}}
</ul>
</script>
@@ -286,19 +287,20 @@ <h1 class="storyname">Replaced</h1>
Footer
</div>
</div>
+
<!-- Creator: adventurio.creator.CreatePage -->
- <div data-role="page" id="createpage" data-url="createpage" data-position="inline" data-nobackbtn="true">
- <div data-role="header" id="createPage_header">
- <h2 class="storyname">Replaced</h2>
- <a id="cancelBackButton" href="#" data-icon="delete">Close</a>
- </div>
- <div data-role="content" id="createPage_content" data-identity="{{storyId}}" >
- <!-- templates_forms_dynamic -->
- </div>
- <div data-role="footer">
- Footer
- </div>
+<div data-role="page" id="createpage" data-url="createpage" data-position="inline" data-nobackbtn="true">
+ <div data-role="header" id="createPage_header">
+ <h2 class="storyname">Replaced</h2>
+ <a id="cancelBackButton" href="#" data-icon="delete">Close</a>
+ </div>
+ <div data-role="content" id="createPage_content" data-identity="{{storyId}}" >
+ <!-- templates_forms_dynamic -->
</div>
+ <div data-role="footer">
+ Footer
+ </div>
+</div>
<!-- CREATOR: adventurio.creator.EditPageFormItemOptions Dialog -->
<div data-role="page" id="creator_page_formitem_options" data-id="creator_page_formitem_options">
View
28 _attachments/src/adventurio/utilies/Handlebars.js
@@ -0,0 +1,28 @@
+// https://github.com/wycats/handlebars.js/issues/182
+Handlebars.registerHelper('$', function ( child, options ) {
+ if ( typeof child !== 'object' ) {
+ return '';
+ }
+ child['$_'] = this;
+ return options.fn( child );
+});
+
+
+Handlebars.registerHelper('whatis', function(param) {
+ console.log(param);
+});
+
+Handlebars.registerPartial("templates_formitems_text", $("#templates_formitems_text").html());
+ Handlebars.registerPartial("templates_formitems_textfield", $("#templates_formitems_textfield").html());
+
+ Handlebars.registerHelper('I18n',
+ function(str){
+ return (I18n != undefined ? I18n.t(str) : str);
+ }
+ );
+
+ Handlebars.registerHelper("ifIsTypeOf", function(actualFormItem, formItemTypeToCheck, fn, elseFn) {
+ if(actualFormItem.type === formItemTypeToCheck){
+ return fn(actualFormItem);
+ }
+ });
View
0 _attachments/src/adventurio/views/Util.js
No changes.
View
43 _attachments/src/adventurio/views/creator/CreatePage.js
@@ -19,40 +19,31 @@ adventurio.views.creator.CreatePage = adventurio.views.superClasses.Basic.extend
$('.edit_area').trigger('create');
$('input').textinput();
-
- Handlebars.registerPartial("templates_formitems_text", $("#templates_formitems_text").html());
- Handlebars.registerPartial("templates_formitems_textfield", $("#templates_formitems_textfield").html());
-
- Handlebars.registerHelper('I18n',
- function(str){
- return (I18n != undefined ? I18n.t(str) : str);
- }
- );
-
- Handlebars.registerHelper("ifIsTypeOf", function(actualFormItem, formItemTypeToCheck, fn, elseFn) {
- if(actualFormItem.type === formItemTypeToCheck){
- return fn(actualFormItem);
- }
- });
-
var html ="";
var context = {};
+ context.props = {};
+ context.props.vertical = 1;
+ context.props.horizontal = 1;
+ context.props._id = this.model.get("_id");
context.formItems = this.model.get("formItems");
+
html = adventurio.templates.forms.Dynamic.compile(context);
this._super("render", [html, "Story header"]);
},
events : {
"click .edit_area" : "triggerCreate",
- "click .saveButton" : "saveEditedValue",
- "click .setFormItemProperties" : "openFormItemProperties"
- },
- openFormItemProperties : function(clickEvent){
- var clickedFormItemPos = $(e.currentTarget).attr("data-identity");
- var urlToCurrentCreatePage = location.hash + clickedFormItemPos;
- //var urlToCurrentCreatePage = "creator/stories/"+this.model.get("_id")+"/"+this.model.get("vertical")+"/"+this.model.get("horizontal")+"?edit";
- adventurio.routers.MainRouter.singleton.navigate(urlToCurrentCreatePage, {trigger: true});
- },
- saveEditedValue : function(clickEvent) {
+ "click .saveButton" : "saveEditedValue"
+ // ,"click .setFormItemProperties" : "openFormItemProperties"
+ }
+ // ,
+ // openFormItemProperties : function(clickEvent){
+ // var clickedFormItemPos = $(e.currentTarget).attr("data-identity");
+ // var urlToCurrentCreatePage = location.hash + clickedFormItemPos;
+ // //var urlToCurrentCreatePage = "creator/stories/"+this.model.get("_id")+"/"+this.model.get("vertical")+"/"+this.model.get("horizontal")+"?edit";
+ // adventurio.routers.MainRouter.singleton.navigate(urlToCurrentCreatePage, {trigger: true});
+ // }
+
+ ,saveEditedValue : function(clickEvent) {
clickEvent.preventDefault();
this.attributes.editModeStatus.LEAVES_WRITE_MODE = true;
this.attributes.editModeStatus.READ_MODE = true;

0 comments on commit 4454073

Please sign in to comment.