These are chat archives for canjs/canjs

9th
Nov 2017
Pavel Rezunenko
@supar
Nov 09 2017 09:31

Hi. I'm trying to migrate from canjs2. I used global ajaxSetup to add Authorization header with JWT

can.ajaxSetup({
      beforeSend: function(xhr) {
            ...
            xhr.setRequestHeader('Authorization', 'Bearer ' + key);
      }
});

Now in the index.js

import ajax from 'can-ajax';
ajax.ajaxSetup({
      beforeSend: function(xhr) {
            ...
            xhr.setRequestHeader('Authorization', 'Bearer ' + key);
      }
});

and it doesn't take any effect in components where i use can-cannect. May be there is more elegant way how to add header to all requests for can-connect

Mohamed Cherif Bouchelaghem
@cherifGsoul
Nov 09 2017 09:34
@supar you can use $.ajax in can-connect and put the header like you did it before
Pavel Rezunenko
@supar
Nov 09 2017 09:58

@cherifGsoul Good example, thx.
It means that i need to set to all models ajax: $.ajax and there is no global ajaxSetup options?

All requests to the server should be with Authorization JWT header, except login

Mohamed Cherif Bouchelaghem
@cherifGsoul
Nov 09 2017 09:59
@supar I dont know what you mean, but you if you need to send authentication header you put it like you did it before with just jquery
Pavel Rezunenko
@supar
Nov 09 2017 11:26
thx
Julian
@pYr0x
Nov 09 2017 21:55
is there described what is truthy on can-stache?
is "1" true?
Julian
@pYr0x
Nov 09 2017 22:54
is there a way to reflect the content of a contenteditable with the stache variable?
<div contenteditable="true">{{mieterCompare[0][this]}}</div>
how can i two-way bind the content with the variable?
Kevin Phillips
@phillipskevin
Nov 09 2017 22:55
two-way bind?
or do you just want contenteditable="{{var}}"?
Julian
@pYr0x
Nov 09 2017 22:56
contenteditable is a boolean
set it to true it will editable
the div
so i want to 2-way bind the innerHTML
Kevin Phillips
@phillipskevin
Nov 09 2017 22:58
oh, two-way bind the content
sorry, I understand your question now
Julian
@pYr0x
Nov 09 2017 22:58
;)
Brad Momberger
@bmomberger-bitovi
Nov 09 2017 22:59
Should be textContent:bind="myScopeProperty"
Julian
@pYr0x
Nov 09 2017 23:00
sorry?
Kevin Phillips
@phillipskevin
Nov 09 2017 23:00
or <div contenteditable="true" innerHTML:bind="val"></div>
Brad Momberger
@bmomberger-bitovi
Nov 09 2017 23:00
I'd probably prefer innerText over innerHTML in that case.
Julian
@pYr0x
Nov 09 2017 23:00
what is val?
Brad Momberger
@bmomberger-bitovi
Nov 09 2017 23:00
But any should work
Kevin Phillips
@phillipskevin
Nov 09 2017 23:00
your viewModel property
Julian
@pYr0x
Nov 09 2017 23:03
i have <div contenteditable="true" innerHTML:bind="mieterCompare[0][this]">{{mieterCompare[0][this]}}</div>
but i think with brackets syntax it is not working
Brad Momberger
@bmomberger-bitovi
Nov 09 2017 23:03
Hmm. So innerHTML works but it looks like we never set up listeners for innerText or textContent. That's kind of disappointing.
Julian
@pYr0x
Nov 09 2017 23:03
{{#each (mieterCompare.getKeys())}}
                        <tr>
                            <th scope="row">{{.}}</th>
                            <td><div contenteditable="true" innerHTML:bind="mieterCompare[0][this]"></div></td>
                            <td><div contenteditable="true">{{mieterCompare[1][this]}}</div></td>
                        </tr>
                    {{/each}}
so i think that would not work like i expect
Kevin Phillips
@phillipskevin
Nov 09 2017 23:05
it works with one bracket at least
Julian
@pYr0x
Nov 09 2017 23:05
i think [this] is to wired
for the 2-way binding
Kevin Phillips
@phillipskevin
Nov 09 2017 23:06
i can try that too
Julian
@pYr0x
Nov 09 2017 23:07
my getKeys() looks like this
const MieterList = DefineList.extend({
  getKeys: function () {
    if(this.length > 0){
      return canReflect.getOwnEnumerableKeys(this[0]);
    }
    return [];
  }
});
and mieterCompare is a new MieterList
Kevin Phillips
@phillipskevin
Nov 09 2017 23:08
seems to be working...
not sure what the difference is from your app
var vm = new can.DefineMap({
  val: {
    foo: 'hello',
    bar: 'world'
  },

  keys: [ 'foo', 'bar' ]
});

var view = can.stache(`
  <h2>val['foo']: {{val['foo']}}</h2>
  <h2>val['bar']: {{val['bar']}}</h2>
  {{#each(keys, key=value)}}
    <div contenteditable="true" innerHTML:bind="val[this]"></div>
  {{/each}}
`);
that's working for me
Julian
@pYr0x
Nov 09 2017 23:10
can i install a list
val is a defineList
with a list of definemaps
Julian
@pYr0x
Nov 09 2017 23:24
so it works for me too
but not on my app
:/
Julian
@pYr0x
Nov 09 2017 23:41
@phillipskevin my stache template gets converted to: <div contenteditable="true" el:inner:u:h:u:t:u:m:u:l:bind="mieterCompare[0][this]">Hansfdgdfg</div>
in my stache-file i had <div contenteditable="true" el:innerHTML:bind="mieterCompare[0][this]"></div>
is this right?