source: trunk/prototype/modules/mail/js/label.js @ 5562

Revision 5562, 18.3 KB checked in by thiago, 12 years ago (diff)

Ticket #2486 - correção da tradução.

  • Property svn:executable set to *
Line 
1function configureLabel(event, ui){
2        var idmarkernow = $(this).find('[name="labelItemId"]').val();
3        winElement.find('.edit-label').val(idmarkernow);
4        winElement.find('.input-nome').val($(this).find("span").text());
5       
6        var colorpicker = winElement.find('.lebals-colorpicker');
7        colorpicker.find('input[name="backgroundColor"]').val(rgb2hex($(this).css("backgroundColor")))
8        .css("background-color", $(this).css("backgroundColor")).focus().end()
9        .find('input[name="fontColor"]').val(rgb2hex($(this).css("color"))).css("background-color", $(this).css("color")).focus().end()
10        .find('input[name="borderColor"]').val(rgb2hex($(this).css("border-left-color"))).css("background-color", $(this).css("border-left-color")).focus().end()
11        .find('.preview-label-outer').css({
12                'background-color':$(this).css("backgroundColor"),
13                'color':$(this).css("color"),
14                'border-color':$(this).css("border-left-color")
15        })             
16        winElement.find(".preview-label-inner").text($(this).text());
17}
18function editLabel(){   
19        var conteudoSpan = $(this).parent().find(".text-list").text();
20        var span = $(this).parent().find(".text-list");
21        $(this).parent().trigger('click').unbind('click', configureLabel).find("span.text-list")
22        .html('<input name="edit-value-list" class="edit-value-list" type="text" value="'+conteudoSpan+'">').find("input[name='edit-value-list']").keydown(function(event){
23                event.stopPropagation();
24                $("input.edit-value-list").keyup(function () {
25                        var value = $(this).val();
26                        winElement.find('.input-nome').val(value);
27                }).keyup();
28                if(event.keyCode == 13){
29                        $(span).html($(".label-list").find(".edit-value-list").val())
30                        .parent().find('.edit').removeClass("hidden").parents("li").click(configureLabel).trigger("click");
31                        winElement.find(".buttons .save-label").click(save_editLabel());       
32                        winElement.find(".buttons .save-label").trigger("click");
33                       
34                }else if( event.keyCode == 27){
35                        $(this).trigger("focusout");
36                }
37        }).focusout(function(){
38                $(span).html(conteudoSpan)
39                .parent().find('.edit').removeClass("hidden").parents("li").click(configureLabel);
40        }).focus();
41        $(this).addClass("hidden");
42}
43function deleteLabel(event){
44        var id = $(this).parents(".label-item").attr("class").match(/label-item-([\d]+[()a-zA-Z]*)/)[1];
45        confirmDelete(id);
46        event.stopImmediatePropagation();
47}
48function save_editLabel(){
49                $(".save-label").button("disable");
50                var labelEdited = {
51                        id : winElement.find(".edit-label").val(),
52                        uid: User.me.id,
53                        name : winElement.find('.input-nome').val(),
54                        backgroundColor : winElement.find("input[name='backgroundColor']").val(),
55                        fontColor : winElement.find("input[name='fontColor']").val(),
56                        borderColor : winElement.find("input[name='borderColor']").val()
57                }
58                var qtdLi = $(".label-list-container ul").find("li").not(".empty-item").length;
59                // salvar marcador
60                if(qtdLi > 0){
61                        $(".label-list-container .label-list li").each(function(){
62                                var regex_match_2 = $(this).attr("class").match(/label-item-([\d]+[()a-zA-Z]*)/);
63                               
64                                 if(regex_match_2 && regex_match_2[1] && regex_match_2[1] == labelEdited.id){
65                                   $(this).html("<input type='hidden' name='labelItemId' class='id-item-list' value='"+labelEdited.id+"'>"+"<span class='text-list'>"+labelEdited.name+"</span><div class='button close tiny' style='float: right'></div><div class='button edit tiny' style='float: right'></div>").css({
66                                        "background" : labelEdited.backgroundColor,
67                                        "color" : labelEdited.fontColor,
68                                        "border-color" : labelEdited.borderColor       
69                                   });
70                                 }     
71                        });
72                       
73                        $("#MyMarckersList .label-list li").each(function(){
74                                var regex_match_2 = $(this).attr("class").match(/label-item-([\d]+[()a-zA-Z]*)/);
75                               
76                                if(regex_match_2 && regex_match_2[1] && regex_match_2[1] == labelEdited.id){
77                                        $(this).html("<input type='hidden' name='labelItemId' class='id-item-list' value='"+labelEdited.id+"'>"+"<span>"+labelEdited.name+"</span>");
78                                        $(this).find(".square-color").css('background', labelEdited.backgroundColor);
79                                }       
80                        });
81                        DataLayer.put('label', labelEdited.id, labelEdited);
82                        DataLayer.commit(false, false, function(){
83                                $("#MyMarckersList")
84                                .html(
85                                        "<div class='my-labels'>" +
86                                                "<img src='../prototype/modules/mail/img/tag.png'/>" +
87                                                "<a class='title-my-labels' tabindex='0' role='button' aria-expanded='false' title='Meus marcadores'>Meus marcadores</a>" +
88                                               
89                                                "<span class='status-list-labels ui-icon ui-icon-triangle-1-s'></span>" +
90                                        "</div>"
91                                )
92                                .append(DataLayer.render("../prototype/modules/mail/templates/label_list.ejs", {labels:DataLayer.get('label', true)} ))
93                                .find("li.label-item").css({"background-color":"#ffffff", "border-color":"#CCCCCC", "color":"#444444"})
94                                .find(".square-color").css("display","").click(function(){
95                                        $(this).parent(".label-item").each(function(){
96                                                configureLabels({selectedItem: $(this).attr('class').match(/label-item-([\d]+[()a-zA-Z]*)/)[1]});
97                                                var id_label_item = $(this).attr('class').match(/label-item-([\d]+[()a-zA-Z]*)/)[1];
98                                                $(".label-list-container .label-list").find(".label-item-"+id_label_item).trigger("click");
99                                        });
100                                });
101                               
102                                $("#MyMarckersList a.title-my-labels").click(function() {
103                                        $("#MyMarckersList ul.label-list").toggleClass("hidden")
104                                        $('#MyMarckersList .status-list-labels').toggleClass("ui-icon-triangle-1-s");
105                                        $('#MyMarckersList .status-list-labels').toggleClass("ui-icon-triangle-1-n");
106                                 });
107         
108                               
109                                winElement.find(".insert-label").val("");
110                                $.Watermark.ShowAll();
111                                $(".label-list-container .label-list li").find('.button').button()
112                                        .filter('.edit').button({icons:{primary:'ui-icon-pencil'}, text:false}).end()
113                                        .filter('.close').button({icons:{primary:'ui-icon-close'}, text:false});
114                                winElement.find('.edit').unbind("click").click(editLabel);
115                               
116                                winElement.find('.close').click(deleteLabel);
117                        });
118                // criar marcador
119                } else{
120                        var nameLabel = winElement.find(".input-nome").val();
121                        if(nameLabel.length >= 2){
122                                new_label(nameLabel, false);                           
123                                winElement.find(".insert-label").val("");
124                                $.Watermark.ShowAll();                         
125                        } else {
126                                alert("Mínimo 2 caracteres");
127                        }               
128                }               
129                /**
130                * Atualiza menu remove o menu presente em cada mensagem listada em uma pasta
131                * e carrega novamente para que os dados sejam atualizados
132                */
133                $.contextMenu( 'destroy', ".table_box tbody tr");
134                loadMenu();
135               
136                $(".label-list-container .label-list").find(".label-item-"+labelEdited.id).trigger("click");
137
138}
139function colors_suggestions(){
140        return [
141                                {name:'Padrão', border:'#3366cc', font:'#ffffff', background:'#3366cc'},
142                                {name:'Coala', border:'#123456', font:'#ffffff', background:'#385c80'},
143                                {name:'Tomate', border:'#d5130b', font:'#111111', background:'#e36d76'},
144                                {name:'Limão', border:'#32ed21', font:'#1f3f1c', background:'#b2f1ac'},
145                                {name:'Alto contraste', border:'#000000', font:'#ffffff', background:'#222222'}
146                        ]               
147}
148function rgb2hex(rgb){
149 rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
150 return "#" +
151  ("0" + parseInt(rgb[1],10).toString(16)).slice(-2) +
152  ("0" + parseInt(rgb[2],10).toString(16)).slice(-2) +
153  ("0" + parseInt(rgb[3],10).toString(16)).slice(-2);
154}
155
156function confirmDelete(id){
157        $.Zebra_Dialog('<strong>Deseja excluir esse marcador?</strong>', {
158                'type':     'question',
159                'title':    'Atenção',
160                'buttons': ['Sim','Não'],       
161                'onClose':  function(caption) {
162                        if(caption == 'Sim'){
163                                delete_label(id);
164                        }
165                }
166        });     
167}                       
168function delete_label(id){
169        $(".label-list li").each(function () {
170                var regex_match = $(this).attr("class").match(/label-item-([\d]+[()a-zA-Z]*)/);
171                if (regex_match && regex_match[1] && regex_match[1] == id) {   
172                        $(this).remove();
173                }
174        });
175        DataLayer.remove('label', id);
176        DataLayer.commit();
177        winElement.find(".label-list li:first").trigger("click");
178       
179        if($(".label-list li").length == 0){
180                winElement.find(".label-list-container").html('<ul class="label-list"><li class="empty-item">Nenhum Marcador Cadastrado.</li></ul>');                   
181        }
182        var qtdLi = $(".label-list-container ul").find("li").not(".empty-item").length;
183        if (qtdLi == 0){
184                $(".my-labels").addClass("hidden");
185                $(".label-list-container ul").find(".empty-item").css("display","");
186                winElement.find(".buttons .save-label .ui-button-text").text('Criar');
187                $(".delete-label").button("disable");   
188                               
189                winElement.find('.input-nome').val("");
190                winElement.find(".preview-label-inner").text("");
191       
192                var colorpicker = winElement.find('.lebals-colorpicker');
193                colorpicker.find('input[name="backgroundColor"]').val("#ebebeb")
194                .css("background-color", "#ebebeb").focus().end()
195                .find('input[name="fontColor"]').val("#000000").css("background-color", "#000000").focus().end()
196                .find('input[name="borderColor"]').val("#000000").css("background-color", "#000000").focus().end()
197                .find('.preview-label-outer').css({
198                        'background-color':"#ebebeb",
199                        'color':"#000000",
200                        'border-color':"#000000"
201                });
202                $(".input-nome").keyup(function () {
203                        var value = $(this).val();
204                        winElement.find('.preview-label-inner').text(value);
205                }).keyup();                             
206        }               
207}
208function new_label(nameLabel, isNew){
209        var labelCreated = {
210                uid: User.me.id,
211                name : nameLabel,
212                backgroundColor : !!isNew ? '#ebebeb' : winElement.find("input[name='backgroundColor']").val(),
213                fontColor : !!isNew ? '#000000' : winElement.find("input[name='fontColor']").val(),
214                borderColor :!!isNew ? '#000000' : winElement.find("input[name='borderColor']").val()
215        }
216        DataLayer.put('label', labelCreated);
217       
218        $(".add-label-button").removeClass("ui-icon ui-icon-plus")
219        .html('<img alt="Carregando" title="Carregando" style="margin-left:10px;" src="../prototype/modules/mail/img/loader.gif" />');
220       
221        DataLayer.commit(false, false, function(){
222
223                labels = DataLayer.get('label',{criteria:{order: 'id'}}, true);
224                newLabel = {
225                        id: labels[labels.length - 1].id,
226                        name : labels[labels.length- 1].name,
227                        uid: User.me.id,
228                        bgColor : !!isNew ? '#ebebeb' : winElement.find("input[name='backgroundColor']").val(),
229                        fontColor : !!isNew ? '#000000' : winElement.find("input[name='fontColor']").val(),
230                        borderColor : !!isNew ? '#000000' : winElement.find("input[name='borderColor']").val()
231                };
232
233                $(".label-list-container ul").find(".empty-item").css("display","none");
234                $(".label-list-container ul")
235                .prepend(DataLayer.render("../prototype/modules/mail/templates/label_listitem.ejs", newLabel))
236                .find("li:first")
237                .fadeIn("slow").click(configureLabel);
238               
239                $("#MyMarckersList")
240                .html(
241                        "<div class='my-labels'>" +
242                                "<img src='../prototype/modules/mail/img/tag.png'/>" +
243                                "<a class='title-my-labels' tabindex='0' role='button' aria-expanded='false' title='Meus marcadores'>Meus marcadores</a>" +
244                               
245                                "<span class='status-list-labels ui-icon ui-icon-triangle-1-s'></span>" +
246                        "</div>"
247                )               
248                .append(DataLayer.render("../prototype/modules/mail/templates/label_list.ejs", {labels:DataLayer.get('label', true)} ))
249                .find("li.label-item").css({"background-color":"#ffffff", "border-color":"#CCCCCC", "color":"#444444"})
250                .find(".square-color").css("display","").click(function(){
251                        $(this).parent(".label-item").each(function(){
252                                configureLabels({selectedItem: $(this).attr('class').match(/label-item-([\d]+[()a-zA-Z]*)/)[1]});
253                        });
254                });
255                $("#MyMarckersList a.title-my-labels").click(function() {
256                        $("#MyMarckersList ul.label-list").toggleClass("hidden")
257                        $('#MyMarckersList .status-list-labels').toggleClass("ui-icon-triangle-1-s");
258                        $('#MyMarckersList .status-list-labels').toggleClass("ui-icon-triangle-1-n");
259                 });
260
261                $(".label-list-container .label-list li").not(".empty-item").click(function(){
262                        $(".label-list-container .label-list li").find("img").remove();
263                        $(".label-list-container .label-list li.label-item").removeClass("selected");
264                        $(this).prepend("<img src='../prototype/modules/mail/img/triangle.png' style='margin: 0 5px 0 -5px;'>");
265                        $(this).addClass("selected");
266                });
267               
268                $(".label-list-container .label-list li").find('.button').button()
269                .filter('.edit').button({icons:{primary:'ui-icon-pencil'}, text:false}).end()
270                .filter('.close').button({icons:{primary:'ui-icon-close'}, text:false});
271               
272                //posiciona para edição o label inserido                       
273                winElement.find("ul.label-list li:first").trigger("click");                     
274                winElement.find(".buttons .save-label .ui-button-text").text('Salvar');
275                $(".delete-label").button("enable");
276               
277                winElement.find('.edit').unbind("click").click(editLabel);                             
278                winElement.find('.close').click(deleteLabel);
279               
280                $(".my-labels").removeClass("hidden");
281               
282                $.contextMenu( 'destroy', ".table_box tbody tr");
283                loadMenu();
284               
285                $(".add-label-button").empty()
286                .addClass("ui-icon ui-icon-plus");
287        });
288
289}
290function init_label(data){
291
292        winElement = data.window;
293       
294        //TODO Mudar quando API abstrair atualizações no cache
295        DataLayer.remove('label',false);
296        labels = DataLayer.get('label',{criteria:{order: 'name'}});
297       
298        if(labels){
299                Label_List = winElement
300                .find(".label-list-container").html(DataLayer.render("../prototype/modules/mail/templates/label_list.ejs", {labels: labels}));
301               
302        }else{
303                //Exibe a mensagem informando o usuário de que não há nenhum marcador cadastrado.
304                Label_List = winElement
305                .find(".label-list-container").html('<ul class="label-list"><li class="empty-item">'+get_lang("Label None")+'.</li></ul>');
306               
307        }
308        Label_List.end()
309        .find('.button').button()
310        .filter('.edit').button({icons:{primary:'ui-icon-pencil'}, text:false}).end()
311        .filter('.close').button({icons:{primary:'ui-icon-close'}, text:false});       
312       
313        winElement.find('.edit').click(editLabel);
314        winElement.find('.close').click(deleteLabel);
315       
316        //marca 'd agua
317        winElement.find(".insert-label").Watermark(winElement.find(".insert-label").val());
318       
319        $("input.insert-label").keyup(function () {
320                $.Watermark.HideAll();
321                var value = $(this).val();
322                winElement.find('.input-nome').val(value);
323        }).keyup();
324       
325        if (!(labels)){
326                winElement.find(".buttons .save-label .ui-button-text").text('Criar');
327                $(".delete-label").button("disable");
328        }else{
329                winElement.find(".label-list li:first").addClass("selected").prepend("<img src='../prototype/modules/mail/img/triangle.png' style='margin: 0 5px 0 -5px;'>");
330        }
331        $(".save-label").button("disable");
332        /**
333        * seta a ação de click para os marcadores listados na tela
334        */
335        winElement.find(".label-list li").not(".empty-item").click(configureLabel);
336       
337        if (data.selectedItem)
338                winElement.find(".label-list li.label-item-"+data.selectedItem).trigger("click");
339        else
340                winElement.find(".label-list li:first").trigger("click");
341               
342        var dataColorPicker = {
343                colorsSuggestions: colors_suggestions()
344        };
345       
346        winElement.find('select.color-suggestions').change(function() {
347                $(".save-label").button("enable");
348                var colorpicker = winElement.find('.lebals-colorpicker');
349                var colors;
350                if(colors = dataColorPicker.colorsSuggestions[$(this).val()]) {
351                        colorpicker
352                        .find('input[name="fontColor"]').val(colors.font).focus().end()
353                        .find('input[name="backgroundColor"]').val(colors.background).focus().end()
354                        .find('input[name="borderColor"]').val(colors.border).focus().end()
355
356                        .find('.preview-label-outer').css({
357                                'background-color':dataColorPicker.colorsSuggestions[$(this).val()].background,
358                                'border-color':dataColorPicker.colorsSuggestions[$(this).val()].border,
359                                'color':dataColorPicker.colorsSuggestions[$(this).val()].font
360                        });
361                }                                       
362        });
363        var colorpickerPreviewChange = function(color) {
364                       
365                var pickedup = winElement.find('.colorwell-selected').val(color).css('background-color', color);
366
367                $(".save-label").button("enable");
368               
369                var colorpicker = winElement.find('.lebals-colorpicker');                       
370
371                if (pickedup.is('input[name="backgroundColor"]')) {
372                        colorpicker.find('.preview-label-outer').css('background-color',color);
373                } else if (pickedup.is('input[name="fontColor"]')) {
374                        colorpicker.find('.preview-label-outer').css('color',color);
375                } else if (pickedup.is('input[name="borderColor"]')) {
376                        colorpicker.find('.preview-label-outer').css('border-color',color);
377                }               
378        }
379               
380        var f = $.farbtastic(winElement.find('.colorpicker'), colorpickerPreviewChange);
381        var selected;
382                               
383        winElement.find('.colorwell').each(function () {
384                f.linkTo(this);
385        })
386        .focus(function() {
387                if (selected) {
388                        $(selected).removeClass('colorwell-selected');
389                }
390                $(selected = this).addClass('colorwell-selected');
391                f.linkTo(this, colorpickerPreviewChange);
392                f.linkTo(colorpickerPreviewChange);
393        });
394       
395        winElement.find(".add-label-button").click(function (event) {
396                $.Watermark.HideAll();
397                var nameLabel = winElement.find(".insert-label").val();
398                if(nameLabel.length >= 2){
399                        new_label(nameLabel, true);
400                        $.Watermark.ShowAll();
401                        winElement.find(".insert-label").val("");
402                        } else {
403                                alert("Mínimo 2 caracteres");
404                        }
405                event.stopImmediatePropagation();
406        });
407       
408        winElement.find('.insert-label').keydown(function(event, ui) {
409                if (event.keyCode == 13)
410                        winElement.find(".add-label-button").trigger('click');
411        });
412       
413        //excluir marcador {deve ser para o botão grande na janela de edição e nao o pequeno da lista}
414        winElement.find(".buttons .delete-label").click(function(event){
415                var id = winElement.find(".edit-label").val();
416                confirmDelete(id);
417                event.stopImmediatePropagation();
418        });
419       
420        $(".label-list-container .label-list li").not(".empty-item").click(function(){
421                $(".label-list-container .label-list li").find("img").remove();
422                $(".label-list-container .label-list li.label-item").removeClass("selected");
423                $(this).prepend("<img src='../prototype/modules/mail/img/triangle.png' style='margin: 0 5px 0 -5px;'>");
424                $(this).addClass("selected");
425        });
426               
427        //salvar/criar marcador
428        winElement.find(".buttons .save-label").click(save_editLabel());       
429        //desfazer marcador
430        winElement.find(".buttons .undo-label").click(function(event){
431                var edit = winElement.find(".edit-label").val();               
432                $(".label-list-container .label-list li").each(function(){
433                        var regex_match_3 = $(this).attr("class").match(/label-item-([\d]+[()a-zA-Z]*)/);
434                        if(regex_match_3 && regex_match_3[1] && regex_match_3[1] == edit){
435                                $(this).trigger("click");
436                        }
437                });
438        });
439       
440        //fechar
441        $(".button-close-window .close-window").click(function(){
442                $(".label-configure-win").dialog("close");
443        });     
444                       
445        $(".configure-label-content").find("input[type='text']").focus(function () {
446                $(this).keyup(function(){
447                        var value = $(this).val();
448                        if(value){
449                                $(".save-label").button("enable");     
450                        }else{
451                                $(".save-label").button("disable");     
452                        }
453                });
454        });     
455       
456        $(".input-nome").keyup(function () {
457                                var value = $(this).val();
458                                winElement.find('.preview-label-inner').text(value);
459        }).keyup();     
460}
461
462/**
463 * TODO:
464 * * Qunado excluir um marcador deve ser removido das mensagens sem que seja necessario atualizar o Expresso.
465 * *
466 */
Note: See TracBrowser for help on using the repository browser.