How to use entry method in Best

Best JavaScript code snippet using best

regs_gen.py

Source:regs_gen.py Github

copy

Full Screen

1#! /usr/bin/env python2# Copyright (c) 2015 Noa Zilberman3# All rights reserved.4#5# This software was developed by Stanford University and the University of Cambridge Computer Laboratory6# under National Science Foundation under Grant No. CNS-0855268,7# the University of Cambridge Computer Laboratory under EPSRC INTERNET Project EP/H040536/1 and8# by the University of Cambridge Computer Laboratory under DARPA/AFRL contract FA8750-11-C-0249 (),9# as part of the DARPA MRC research programme.10#11# @NETFPGA_LICENSE_HEADER_START@12#13# Licensed to NetFPGA C.I.C. (NetFPGA) under one or more contributor14# license agreements. See the NOTICE file distributed with this work for15# additional information regarding copyright ownership. NetFPGA licenses this16# file to you under the NetFPGA Hardware-Software License, Version 1.0 (the17# ); you may not use this file except in compliance with the18# License. You may obtain a copy of the License at:19#20# http://www.netfpga-cic.org21#22# Unless required by applicable law or agreed to in writing, Work distributed23# under the License is distributed on an ``AS IS'' BASIS, WITHOUT WARRANTIES OR24# CONDITIONS OF ANY KIND, either express or implied. See the License for the25# specific language governing permissions and limitations under the License.26#27# @NETFPGA_LICENSE_HEADER_END@28#29##################################################################30#Define the list of registers (busses) and their characteristics31##################################################################32 33module_name='crypto'34block_name=module_name.upper()35 36def create_regs_list():37 regsDict=[38{'reg':"ID",'type':"RO",'endian':"little", 'name':"id",'bits':"31:0",'width':"32",'addr':"32'h0",'default':"32'h0000DA01"},39{'reg':"Version",'type':"RO",'endian':"little", 'name':"version",'bits':"31:0",'width':"32",'addr':"32'h4",'default':"32'h1"},40{'reg':"Reset",'type':"WOE",'endian':"little", 'name':"reset",'bits':"15:0",'width':"16",'addr':"32'h8",'default':"16'h0"},41{'reg':"Flip",'type':"RWA",'endian':"little", 'name':"flip",'bits':"31:0",'width':"32",'addr':"32'hC",'default':"32'h0"},42{'reg':"Debug",'type':"RWA",'endian':"little", 'name':"debug",'bits':"31:0",'width':"32",'addr':"32'h10",'default':"32'h0"},43{'reg':"PktIn",'type':"ROC",'endian':"little", 'name':"pktin",'bits':"31:0",'width':"32",'addr':"32'h14",'default':"32'h0"},44{'reg':"PktOut",'type':"ROC",'endian':"little", 'name':"pktout",'bits':"31:0",'width':"32",'addr':"32'h18",'default':"32'h0"},45{'reg':"key",'type':"RWS",'endian':"big", 'name':"key",'bits':"31:0",'width':"32",'addr':"32'h1C",'default':"32'hF"},46]47 return(regsDict)48 49def create_mems_list():50 memsDict=[ 51]52 return(memsDict)53#54# Copyright (c) 2015 Noa Zilberman, Jingyun Zhang, Salvator Galea55# All rights reserved.56#57# This software was developed by Stanford University and the University of Cambridge Computer Laboratory 58# under National Science Foundation under Grant No. CNS-0855268,59# the University of Cambridge Computer Laboratory under EPSRC INTERNET Project EP/H040536/1 and60# by the University of Cambridge Computer Laboratory under DARPA/AFRL contract FA8750-11-C-0249 ("MRC2"), 61# as part of the DARPA MRC research programme.62#63# @NETFPGA_LICENSE_HEADER_START@64#65# Licensed to NetFPGA C.I.C. (NetFPGA) under one or more contributor66# license agreements. See the NOTICE file distributed with this work for67# additional information regarding copyright ownership. NetFPGA licenses this68# file to you under the NetFPGA Hardware-Software License, Version 1.0 (the69# "License"); you may not use this file except in compliance with the70# License. You may obtain a copy of the License at:71#72# http://www.netfpga-cic.org73#74# Unless required by applicable law or agreed to in writing, Work distributed75# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR76# CONDITIONS OF ANY KIND, either express or implied. See the License for the77# specific language governing permissions and limitations under the License.78#79# @NETFPGA_LICENSE_HEADER_END@80#81##################################################################82# a function that writes the header of regs file83##################################################################84def write_regs_header(regsFile):85 regsFile.write('\86//\n\87// Copyright (c) 2015 University of Cambridge\n\88// All rights reserved.\n\89//\n\90//\n\91// File:\n\92// '+module_name+'_cpu_regs.v\n\93//\n\94// Module:\n\95// '+module_name+'_cpu_regs\n\96//\n\97// Description:\n\98// This file is automatically generated with the registers towards the CPU/Software\n\99//\n\100// This software was developed by Stanford University and the University of Cambridge Computer Laboratory\n\101// under National Science Foundation under Grant No. CNS-0855268,\n\102// the University of Cambridge Computer Laboratory under EPSRC INTERNET Project EP/H040536/1 and\n\103// by the University of Cambridge Computer Laboratory under DARPA/AFRL contract FA8750-11-C-0249 ("MRC2"),\n\104// as part of the DARPA MRC research programme.\n\105//\n\106// @NETFPGA_LICENSE_HEADER_START@\n\107//\n\108// Licensed to NetFPGA C.I.C. (NetFPGA) under one or more contributor\n\109// license agreements. See the NOTICE file distributed with this work for\n\110// additional information regarding copyright ownership. NetFPGA licenses this\n\111// file to you under the NetFPGA Hardware-Software License, Version 1.0 (the\n\112// "License"); you may not use this file except in compliance with the\n\113// License. You may obtain a copy of the License at:\n\114//\n\115// http://www.netfpga-cic.org\n\116//\n\117// Unless required by applicable law or agreed to in writing, Work distributed\n\118// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR\n\119// CONDITIONS OF ANY KIND, either express or implied. See the License for the\n\120// specific language governing permissions and limitations under the License.\n\121//\n\122// @NETFPGA_LICENSE_HEADER_END@\n\123//\n\124\n')125#end of write_regs_headerdefault126##################################################################127# a function that writes the header of regs defines file128##################################################################129def write_defs_header(defsFile):130 defsFile.write('\131//\n\132// Copyright (c) 2015 University of Cambridge\n\133// All rights reserved.\n\134//\n\135//\n\136// File:\n\137// '+module_name+'_cpu_regs_defines.v\n\138//\n\139// Module:\n\140// '+module_name+'_cpu_regs_defines\n\141//\n\142// Description:\n\143// This file is automatically generated with the registers defintions towards the CPU/Software\n\144//\n\145// This software was developed by Stanford University and the University of Cambridge Computer Laboratory\n\146// under National Science Foundation under Grant No. CNS-0855268,\n\147// the University of Cambridge Computer Laboratory under EPSRC INTERNET Project EP/H040536/1 and\n\148// by the University of Cambridge Computer Laboratory under DARPA/AFRL contract FA8750-11-C-0249 ("MRC2"),\n\149// as part of the DARPA MRC research programme.\n\150//\n\151// @NETFPGA_LICENSE_HEADER_START@\n\152//\n\153// Licensed to NetFPGA C.I.C. (NetFPGA) under one or more contributor\n\154// license agreements. See the NOTICE file distributed with this work for\n\155// additional information regarding copyright ownership. NetFPGA licenses this\n\156// file to you under the NetFPGA Hardware-Software License, Version 1.0 (the\n\157// "License"); you may not use this file except in compliance with the\n\158// License. You may obtain a copy of the License at:\n\159//\n\160// http://www.netfpga-cic.org\n\161//\n\162// Unless required by applicable law or agreed to in writing, Work distributed\n\163// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR\n\164// CONDITIONS OF ANY KIND, either express or implied. See the License for the\n\165// specific language governing permissions and limitations under the License.\n\166//\n\167// @NETFPGA_LICENSE_HEADER_END@\n\168//\n\169\n')170#end of write_defs_header171##################################################################172# a function that writes the header of regs tcl file173##################################################################174def write_tcl_header(tclFile):175 tclFile.write('\176#\n\177# Copyright (c) 2015 University of Cambridge\n\178# All rights reserved.\n\179#\n\180#\n\181# File:\n\182# '+module_name+'_regs_defines.tcl\n\183#\n\184# Description:\n\185# This file is automatically generated with tcl defines for the software\n\186#\n\187# This software was developed by Stanford University and the University of Cambridge Computer Laboratory\n\188# under National Science Foundation under Grant No. CNS-0855268,\n\189# the University of Cambridge Computer Laboratory under EPSRC INTERNET Project EP/H040536/1 and\n\190# by the University of Cambridge Computer Laboratory under DARPA/AFRL contract FA8750-11-C-0249 ("MRC2"),\n\191# as part of the DARPA MRC research programme.\n\192#\n\193# @NETFPGA_LICENSE_HEADER_START@\n\194#\n\195# Licensed to NetFPGA C.I.C. (NetFPGA) under one or more contributor\n\196# license agreements. See the NOTICE file distributed with this work for\n\197# additional information regarding copyright ownership. NetFPGA licenses this\n\198# file to you under the NetFPGA Hardware-Software License, Version 1.0 (the\n\199# "License"); you may not use this file except in compliance with the\n\200# License. You may obtain a copy of the License at:\n\201#\n\202# http://www.netfpga-cic.org\n\203#\n\204# Unless required by applicable law or agreed to in writing, Work distributed\n\205# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR\n\206# CONDITIONS OF ANY KIND, either express or implied. See the License for the\n\207# specific language governing permissions and limitations under the License.\n\208#\n\209# @NETFPGA_LICENSE_HEADER_END@\n\210#\n\211\n')212#end of write_tcl_header213##################################################################214# a function that writes the header of regs tcl file215##################################################################216def write_hFile_header(hFile):217 hFile.write('\218//\n\219// Copyright (c) 2015 University of Cambridge\n\220// All rights reserved.\n\221//\n\222//\n\223// File:\n\224// '+module_name+'_regs_defines.h\n\225//\n\226// Description:\n\227// This file is automatically generated with header defines for the software\n\228//\n\229// This software was developed by Stanford University and the University of Cambridge Computer Laboratory\n\230// under National Science Foundation under Grant No. CNS-0855268,\n\231// the University of Cambridge Computer Laboratory under EPSRC INTERNET Project EP/H040536/1 and\n\232// by the University of Cambridge Computer Laboratory under DARPA/AFRL contract FA8750-11-C-0249 ("MRC2"),\n\233// as part of the DARPA MRC research programme.\n\234//\n\235// @NETFPGA_LICENSE_HEADER_START@\n\236//\n\237// Licensed to NetFPGA C.I.C. (NetFPGA) under one or more contributor\n\238// license agreements. See the NOTICE file distributed with this work for\n\239// additional information regarding copyright ownership. NetFPGA licenses this\n\240// file to you under the NetFPGA Hardware-Software License, Version 1.0 (the\n\241// "License"); you may not use this file except in compliance with the\n\242// License. You may obtain a copy of the License at:\n\243//\n\244// http://www.netfpga-cic.org\n\245//\n\246// Unless required by applicable law or agreed to in writing, Work distributed\n\247// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR\n\248// CONDITIONS OF ANY KIND, either express or implied. See the License for the\n\249// specific language governing permissions and limitations under the License.\n\250//\n\251// @NETFPGA_LICENSE_HEADER_END@\n\252//\n\253\n')254#end of write_h_header255##################################################################256# a function that writes the header of regs table file257##################################################################258def write_tbFile_header(tbFile):259 tbFile.write('\260//\n\261// Copyright (c) 2015 University of Cambridge\n\262// All rights reserved.\n\263//\n\264//\n\265// File:\n\266// '+module_name+'_regs_defines.txt\n\267//\n\268// Description:\n\269// This file is automatically generated with header defines for the software\n\270//\n\271// This software was developed by Stanford University and the University of Cambridge Computer Laboratory\n\272// under National Science Foundation under Grant No. CNS-0855268,\n\273// the University of Cambridge Computer Laboratory under EPSRC INTERNET Project EP/H040536/1 and\n\274// by the University of Cambridge Computer Laboratory under DARPA/AFRL contract FA8750-11-C-0249 ("MRC2"),\n\275// as part of the DARPA MRC research programme.\n\276//\n\277// @NETFPGA_LICENSE_HEADER_START@\n\278//\n\279// Licensed to NetFPGA C.I.C. (NetFPGA) under one or more contributor\n\280// license agreements. See the NOTICE file distributed with this work for\n\281// additional information regarding copyright ownership. NetFPGA licenses this\n\282// file to you under the NetFPGA Hardware-Software License, Version 1.0 (the\n\283// "License"); you may not use this file except in compliance with the\n\284// License. You may obtain a copy of the License at:\n\285//\n\286// http://www.netfpga-cic.org\n\287//\n\288// Unless required by applicable law or agreed to in writing, Work distributed\n\289// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR\n\290// CONDITIONS OF ANY KIND, either express or implied. See the License for the\n\291// specific language governing permissions and limitations under the License.\n\292//\n\293// @NETFPGA_LICENSE_HEADER_END@\n\294//\n\295\n')296##################################################################297#A funtion that writes the ports of the regs moduledefault298##################################################################299def write_regs_ports(regsFile,regsDict, memsDict):300 regsFile.write('`include "'+module_name+'_cpu_regs_defines.v"\n\301\302module '+module_name+'_cpu_regs #\n\303(\n\304parameter C_BASE_ADDRESS = 32\'h00000000,\n\305parameter C_S_AXI_DATA_WIDTH = 32,\n\306parameter C_S_AXI_ADDR_WIDTH = 32\n\307)\n\308(\n\309 // General ports\n\310 input clk,\n\311 input resetn,\n\312 // Global Registers\n\313 input cpu_resetn_soft,\n\314 output reg resetn_soft,\n\315 output reg resetn_sync,\n\316\n\317 // Register ports\n')318 for entry in regsDict:319 if entry['type']=="RO" :320 regsFile.write(' input [`REG_'+(entry['name']).upper()+'_BITS] '+entry['name']+'_reg,\n')321 if entry['type']=="ROC" :322 regsFile.write(' input [`REG_'+(entry['name']).upper()+'_BITS] '+entry['name']+'_reg,\n')323 regsFile.write(' output reg '+entry['name']+'_reg_clear,\n')324 if entry['type']=="RWS" :325 regsFile.write(' output reg [`REG_'+(entry['name']).upper()+'_BITS] '+entry['name']+'_reg,\n')326 if entry['type']=="WO" :327 regsFile.write(' output reg [`REG_'+(entry['name']).upper()+'_BITS] '+entry['name']+'_reg,\n')328 if entry['type']=="WOE" :329 regsFile.write(' output reg [`REG_'+(entry['name']).upper()+'_BITS] '+entry['name']+'_reg,\n')330 if entry['type']=="RWA" :331 regsFile.write(' input [`REG_'+(entry['name']).upper()+'_BITS] ip2cpu_'+entry['name']+'_reg,\n')332 regsFile.write(' output reg [`REG_'+(entry['name']).upper()+'_BITS] cpu2ip_'+entry['name']+'_reg,\n')333 if entry['type']=="RWCR" :334 regsFile.write(' input [`REG_'+(entry['name']).upper()+'_BITS] ip2cpu_'+entry['name']+'_reg,\n')335 regsFile.write(' output reg [`REG_'+(entry['name']).upper()+'_BITS] cpu2ip_'+entry['name']+'_reg,\n')336 regsFile.write(' output reg cpu2ip_'+entry['name']+'_reg_clear,\n')337 if entry['type']=="RWCW" :338 regsFile.write(' input [`REG_'+(entry['name']).upper()+'_BITS] ip2cpu_'+entry['name']+'_reg,\n')339 regsFile.write(' output reg [`REG_'+(entry['name']).upper()+'_BITS] cpu2ip_'+entry['name']+'_reg,\n')340 regsFile.write(' output reg cpu2ip_'+entry['name']+'_reg_clear,\n')341 for entry in memsDict:342 regsFile.write(' output reg [`MEM_'+(entry['name']).upper()+'_ADDR_BITS] '+entry['name']+'_addr,\n')343 regsFile.write(' output reg [`MEM_'+(entry['name']).upper()+'_DATA_BITS] '+entry['name']+'_data,\n')344 regsFile.write(' output reg '+entry['name']+'_rd_wrn,\n')345 regsFile.write(' output reg '+entry['name']+'_cmd_valid,\n')346 regsFile.write(' input [`MEM_'+(entry['name']).upper()+'_DATA_BITS] '+entry['name']+'_reply,\n')347 regsFile.write(' input '+entry['name']+'_reply_valid,\n') 348 349 regsFile.write('\n\350 // AXI Lite ports\n\351 input S_AXI_ACLK,\n\352 input S_AXI_ARESETN,\n\353 input [C_S_AXI_ADDR_WIDTH-1 : 0] S_AXI_AWADDR,\n\354 input S_AXI_AWVALID,\n\355 input [C_S_AXI_DATA_WIDTH-1 : 0] S_AXI_WDATA,\n\356 input [C_S_AXI_DATA_WIDTH/8-1 : 0] S_AXI_WSTRB,\n\357 input S_AXI_WVALID,\n\358 input S_AXI_BREADY,\n\359 input [C_S_AXI_ADDR_WIDTH-1 : 0] S_AXI_ARADDR,\n\360 input S_AXI_ARVALID,\n\361 input S_AXI_RREADY,\n\362 output S_AXI_ARREADY,\n\363 output [C_S_AXI_DATA_WIDTH-1 : 0] S_AXI_RDATA,\n\364 output [1 : 0] S_AXI_RRESP,\n\365 output S_AXI_RVALID,\n\366 output S_AXI_WREADY,\n\367 output [1 :0] S_AXI_BRESP,\n\368 output S_AXI_BVALID,\n\369 output S_AXI_AWREADY\n\370\n\371);\n');372#end of write_regs_ports373##################################################################374#A funtion that writes the wires and regs of the registers module375##################################################################376def write_regs_wires(regsFile,regsDict,memsDict):377 regsFile.write('\n\378 // AXI4LITE signals\n\379 reg [C_S_AXI_ADDR_WIDTH-1 : 0] axi_awaddr;\n\380 reg axi_awready;\n\381 reg axi_wready;\n\382 reg [1 : 0] axi_bresp;\n\383 reg axi_bvalid;\n\384 reg [C_S_AXI_ADDR_WIDTH-1 : 0] axi_araddr;\n\385 reg axi_arready;\n\386 reg [C_S_AXI_DATA_WIDTH-1 : 0] axi_rdata;\n\387 reg [1 : 0] axi_rresp;\n\388 reg axi_rvalid;\n\389\n\390 reg resetn_sync_d;\n\391 wire reg_rden;\n\392 wire reg_wren;\n\393 reg [C_S_AXI_DATA_WIDTH-1:0] reg_data_out;\n\394 integer byte_index;\n');395 for entry in regsDict:396 if entry['type']=="RWCW" :397 regsFile.write('\398 reg cpu2ip_'+entry['name']+'_reg_clear_d;\n')399 for entry in regsDict:400 if entry['type']=="ROC" :401 regsFile.write('\402 reg '+entry['name']+'_reg_clear_d;\n')403 for entry in regsDict:404 if entry['type']=="RWSI" or entry['type']=="ROI" :405 regsFile.write('\406 reg [`REG_'+(entry['name']).upper()+'_BITS] '+entry['name']+'_reg;\n')407 for entry in regsDict:408 if entry['type']=="RWI" :409 regsFile.write('\410 reg [`REG_'+(entry['name']).upper()+'_BITS] '+entry['name']+'_reg;\n\411 reg [`REG_'+(entry['name']).upper()+'_BITS] '+entry['name']+'_reg_internal;\n\412 reg '+entry['name']+'_reg_update;\n') 413 414 for entry in regsDict:415 if entry['endian']=="big" :416 regsFile.write('\n\417 // assign default little endian\n');418 regsFile.write('\419 wire [C_S_AXI_DATA_WIDTH-1 : 0] reg_'+entry['name']+'_default_little;\n');420 for entry in regsDict:421 if entry['endian']=="big" :422 regsFile.write('\423 assign reg_'+entry['name']+'_default_little = `REG_'+entry['name'].upper()+'_DEFAULT;\n');424 regsFile.write('\n\425 // I/O Connections assignments\n\426 assign S_AXI_AWREADY = axi_awready;\n\427 assign S_AXI_WREADY = axi_wready;\n\428 assign S_AXI_BRESP = axi_bresp;\n\429 assign S_AXI_BVALID = axi_bvalid;\n\430 assign S_AXI_ARREADY = axi_arready;\n\431 assign S_AXI_RDATA = axi_rdata;\n\432 assign S_AXI_RRESP = axi_rresp;\n\433 assign S_AXI_RVALID = axi_rvalid;\n\434\n');435#end of write_regs_wires436##################################################################437#sync reset signal for better timing438##################################################################439def sync_reset(regsFile):440 regsFile.write('\n\441 //Sample reset (not mandatory, but good practice)\n\442 always @ (posedge clk) begin\n\443 if (~resetn) begin\n\444 resetn_sync_d <= 1\'b0;\n\445 resetn_sync <= 1\'b0;\n\446 end\n\447 else begin\n\448 resetn_sync_d <= resetn;\n\449 resetn_sync <= resetn_sync_d;\n\450 end\n\451 end\n\452\n');453# for now, only global reset is supported, to demonstrate usage454 regsFile.write('\n\455 //global registers, sampling\n\456 always @(posedge clk) resetn_soft <= #1 cpu_resetn_soft;\n');457#end of sync_reset458##################################################################459# a function that writes the logic behind the registers access460##################################################################461def write_logic(regsFile,regsDict):462# boolean first_item;463# axi protocol generation464 regsFile.write('\n\465 // Implement axi_awready generation\n\466\n\467 always @( posedge S_AXI_ACLK )\n\468 begin\n\469 if ( S_AXI_ARESETN == 1\'b0 )\n\470 begin\n\471 axi_awready <= 1\'b0;\n\472 end\n\473 else\n\474 begin\n\475 if (~axi_awready && S_AXI_AWVALID && S_AXI_WVALID)\n\476 begin\n\477 // slave is ready to accept write address when\n\478 // there is a valid write address and write data\n\479 // on the write address and data bus. This design\n\480 // expects no outstanding transactions.\n\481 axi_awready <= 1\'b1;\n\482 end\n\483 else\n\484 begin\n\485 axi_awready <= 1\'b0;\n\486 end\n\487 end\n\488 end\n\489\n\490 // Implement axi_awaddr latching\n\491\n\492 always @( posedge S_AXI_ACLK )\n\493 begin\n\494 if ( S_AXI_ARESETN == 1\'b0 )\n\495 begin\n\496 axi_awaddr <= 0;\n\497 end\n\498 else\n\499 begin\n\500 if (~axi_awready && S_AXI_AWVALID && S_AXI_WVALID)\n\501 begin\n\502 // Write Address latching\n\503 axi_awaddr <= S_AXI_AWADDR ^ C_BASE_ADDRESS;\n\504 end\n\505 end\n\506 end\n\507\n\508 // Implement axi_wready generation\n\509\n\510 always @( posedge S_AXI_ACLK )\n\511 begin\n\512 if ( S_AXI_ARESETN == 1\'b0 )\n\513 begin\n\514 axi_wready <= 1\'b0;\n\515 end\n\516 else\n\517 begin\n\518 if (~axi_wready && S_AXI_WVALID && S_AXI_AWVALID)\n\519 begin\n\520 // slave is ready to accept write data when\n\521 // there is a valid write address and write data\n\522 // on the write address and data bus. This design\n\523 // expects no outstanding transactions.\n\524 axi_wready <= 1\'b1;\n\525 end\n\526 else\n\527 begin\n\528 axi_wready <= 1\'b0;\n\529 end\n\530 end\n\531 end\n\532\n\533 // Implement write response logic generation\n\534\n\535 always @( posedge S_AXI_ACLK )\n\536 begin\n\537 if ( S_AXI_ARESETN == 1\'b0 )\n\538 begin\n\539 axi_bvalid <= 0;\n\540 axi_bresp <= 2\'b0;\n\541 end\n\542 else\n\543 begin\n\544 if (axi_awready && S_AXI_AWVALID && ~axi_bvalid && axi_wready && S_AXI_WVALID)\n\545 begin\n\546 // indicates a valid write response is available\n\547 axi_bvalid <= 1\'b1;\n\548 axi_bresp <= 2\'b0; // OKAY response\n\549 end // work error responses in future\n\550 else\n\551 begin\n\552 if (S_AXI_BREADY && axi_bvalid)\n\553 //check if bready is asserted while bvalid is high)\n\554 //(there is a possibility that bready is always asserted high)\n\555 begin\n\556 axi_bvalid <= 1\'b0;\n\557 end\n\558 end\n\559 end\n\560 end\n\561\n\562 // Implement axi_arready generation\n\563\n\564 always @( posedge S_AXI_ACLK )\n\565 begin\n\566 if ( S_AXI_ARESETN == 1\'b0 )\n\567 begin\n\568 axi_arready <= 1\'b0;\n\569 axi_araddr <= 32\'b0;\n\570 end\n\571 else\n\572 begin\n\573 if (~axi_arready && S_AXI_ARVALID)\n\574 begin\n\575 // indicates that the slave has acceped the valid read address\n\576 // Read address latching\n\577 axi_arready <= 1\'b1;\n\578 axi_araddr <= S_AXI_ARADDR ^ C_BASE_ADDRESS;\n\579 end\n\580 else\n\581 begin\n\582 axi_arready <= 1\'b0;\n\583 end\n\584 end\n\585 end\n\586\n\587\n\588 // Implement axi_rvalid generation\n\589\n\590 always @( posedge S_AXI_ACLK )\n\591 begin\n\592 if ( S_AXI_ARESETN == 1\'b0 )\n\593 begin\n\594 axi_rvalid <= 0;\n\595 axi_rresp <= 0;\n\596 end\n\597 else\n\598 begin\n\599 if (axi_arready && S_AXI_ARVALID && ~axi_rvalid)\n\600 begin\n\601 // Valid read data is available at the read data bus\n\602 axi_rvalid <= 1\'b1;\n\603 axi_rresp <= 2\'b0; // OKAY response\n\604 end\n\605 else if (axi_rvalid && S_AXI_RREADY)\n\606 begin\n\607 // Read data is accepted by the master\n\608 axi_rvalid <= 1\'b0;\n\609 end\n\610 end\n\611 end\n\612\n\613\n');614 regsFile.write('\615 // Implement memory mapped register select and write logic generation\n\616\n\617 assign reg_wren = axi_wready && S_AXI_WVALID && axi_awready && S_AXI_AWVALID;\n\618\n\619//////////////////////////////////////////////////////////////\n\620// write registers\n\621//////////////////////////////////////////////////////////////\n\622\n');623#Handle write only registers624 first_item=True; 625 for entry in regsDict:626 if entry['type']=="WO" :627 if first_item:628 regsFile.write('\n\629//Write only register, not cleared\n\630 //static\n\631 always @(posedge clk)\n\632 if (!resetn_sync) begin\n');633 first_item=False;634 if entry['endian']=="little" :635 regsFile.write('\636 '+entry['name']+'_reg <= #1 `REG_'+entry['name'].upper()+'_DEFAULT;\n');637 if entry['endian']=="big" :638 regsFile.write('\639 for (byte_index = 0; byte_index <= (`REG_'+entry['name'].upper()+'_WIDTH/8-1); byte_index = byte_index +1)\n\640 '+entry['name']+'_reg[byte_index*8 +: 8] <= reg_'+entry['name']+'_default_little[(C_S_AXI_DATA_WIDTH/8-byte_index-1)*8 +: 8];\n');641 if not(first_item):642 regsFile.write(' end\n\643 else begin\n\644 if (reg_wren) begin //write event\n\645 case (axi_awaddr)\n');646 for entry in regsDict:647 if entry['type']=="WO" :648 if entry['endian']=="little" :649 regsFile.write(' //'+entry['name'].capitalize()+' Register\n\650 `REG_'+entry['name'].upper()+'_ADDR : begin\n\651 for ( byte_index = 0; byte_index <= (`REG_'+entry['name'].upper()+'_WIDTH/8-1); byte_index = byte_index +1)\n\652 if (S_AXI_WSTRB[byte_index] == 1) begin\n\653 '+entry['name']+'_reg[byte_index*8 +: 8] <= S_AXI_WDATA[byte_index*8 +: 8];\n\654 end\n\655 end\n');656 if entry['endian']=="big" :657 regsFile.write(' //'+entry['name'].capitalize()+' Register\n\658 `REG_'+entry['name'].upper()+'_ADDR : begin\n\659 for (byte_index = 0; byte_index <= (`REG_'+entry['name'].upper()+'_WIDTH/8-1); byte_index = byte_index +1)\n\660 if (S_AXI_WSTRB[byte_index] == 1) begin\n\661 '+entry['name']+'_reg[byte_index*8 +: 8] <= S_AXI_WDATA[(C_S_AXI_DATA_WIDTH/8-byte_index-1)*8 +: 8]; //dynamic register;\n\662 end\n\663 end\n');664 if not(first_item):665 regsFile.write('\666 endcase\n\667 end\n\668 end\n');669#Handle write only event registers670 first_item=True; 671 for entry in regsDict:672 if entry['type']=="WOE" :673 if first_item:674 first_item= False;675 regsFile.write('\n\676//Write only register, clear on write (i.e. event)\n\677 always @(posedge clk) begin\n\678 if (!resetn_sync) begin\n');679 if entry['endian']=="little" :680 regsFile.write('\681 '+entry['name']+'_reg <= #1 `REG_'+entry['name'].upper()+'_DEFAULT;\n');682 if entry['endian']=="big" :683 regsFile.write('\684 for (byte_index = 0; byte_index <= (`REG_'+entry['name'].upper()+'_WIDTH/8-1); byte_index = byte_index +1)\n\685 '+entry['name']+'_reg[byte_index*8 +: 8] <= reg_'+entry['name']+'_default_little[(C_S_AXI_DATA_WIDTH/8-byte_index-1)*8 +: 8];\n');686 if not(first_item):687 regsFile.write(' end\n\688 else begin\n\689 if (reg_wren) begin\n\690 case (axi_awaddr)\n');691 for entry in regsDict:692 if entry['type']=="WOE" :693 if entry['endian']=="little" :694 regsFile.write('\695 //'+entry['name'].capitalize()+' Register\n\696 `REG_'+entry['name'].upper()+'_ADDR : begin\n\697 for ( byte_index = 0; byte_index <= (`REG_'+entry['name'].upper()+'_WIDTH/8-1); byte_index = byte_index +1)\n\698 if (S_AXI_WSTRB[byte_index] == 1) begin\n\699 '+entry['name']+'_reg[byte_index*8 +: 8] <= S_AXI_WDATA[byte_index*8 +: 8];\n\700 end\n\701 end\n');702 if entry['endian']=="big" :703 regsFile.write('\704 //'+entry['name'].capitalize()+' Register\n\705 `REG_'+entry['name'].upper()+'_ADDR : begin\n\706 for (byte_index = 0; byte_index <= (`REG_'+entry['name'].upper()+'_WIDTH/8-1); byte_index = byte_index +1)\n\707 if (S_AXI_WSTRB[byte_index] == 1) begin\n\708 '+entry['name']+'_reg[byte_index*8 +: 8] <= S_AXI_WDATA[(C_S_AXI_DATA_WIDTH/8-byte_index-1)*8 +: 8]; //dynamic register;\n\709 end\n\710 end\n');711 if not(first_item):712 regsFile.write('\713 endcase\n\714 end\n\715 else begin\n');716 717 for entry in regsDict:718 if entry['type']=="WOE" :719 if entry['endian']=="little" :720 regsFile.write('\721 '+entry['name']+'_reg <= #1 `REG_'+entry['name'].upper()+'_DEFAULT;\n');722 if entry['endian']=="big" :723 regsFile.write('\724 for (byte_index = 0; byte_index <= (`REG_'+entry['name'].upper()+'_WIDTH/8-1); byte_index = byte_index +1)\n\725 '+entry['name']+'_reg[byte_index*8 +: 8] <= reg_'+entry['name']+'_default_little[(C_S_AXI_DATA_WIDTH/8-byte_index-1)*8 +: 8];\n');726 regsFile.write('\727 end\n\728 end\n\729 end\n');730#Handle Read/write registers, not cleared731 first_item=True;732 for entry in regsDict:733 if first_item and (entry['type']=="RWS" or entry['type']=="RWA"):734 first_item = False;735 regsFile.write('\n\736//R/W register, not cleared\n\737 always @(posedge clk) begin\n\738 if (!resetn_sync) begin\n\739\n');740 if entry['type']=="RWS" :741 if entry['endian']=="little" :742 regsFile.write('\743 '+entry['name']+'_reg <= #1 `REG_'+entry['name'].upper()+'_DEFAULT;\n');744 if entry['endian']=="big" :745 regsFile.write('\746 for (byte_index = 0; byte_index <= (`REG_'+entry['name'].upper()+'_WIDTH/8-1); byte_index = byte_index +1)\n\747 '+entry['name']+'_reg[byte_index*8 +: 8] <= reg_'+entry['name']+'_default_little[(C_S_AXI_DATA_WIDTH/8-byte_index-1)*8 +: 8];\n');748 if entry['type']=="RWA" :749 if entry['endian']=="little" :750 regsFile.write('\751 cpu2ip_'+entry['name']+'_reg <= #1 `REG_'+entry['name'].upper()+'_DEFAULT;\n');752 if entry['endian']=="big" :753 regsFile.write('\754 for (byte_index = 0; byte_index <= (`REG_'+entry['name'].upper()+'_WIDTH/8-1); byte_index = byte_index +1)\n\755 cpu2ip_'+entry['name']+'_reg[byte_index*8 +: 8] <= reg_'+entry['name']+'_default_little[(C_S_AXI_DATA_WIDTH/8-byte_index-1)*8 +: 8];\n');756 if entry['type']=="RWSI" :757 if entry['endian']=="little" :758 regsFile.write('\759 '+entry['name']+'_reg <= #1 `REG_'+entry['name'].upper()+'_DEFAULT;\n');760 761 if entry['endian']=="big" :762 regsFile.write('\763 for (byte_index = 0; byte_index <= (`REG_'+entry['name'].upper()+'_WIDTH/8-1); byte_index = byte_index +1)\n\764 '+entry['name']+'_reg[byte_index*8 +: 8] <= reg_'+entry['name']+'_default_little[(C_S_AXI_DATA_WIDTH/8-byte_index-1)*8 +: 8];\n');765 766 if entry['type']=="RWI" : 767 if entry['endian']=="little" :768 regsFile.write('\769 '+entry['name']+'_reg_internal <= #1 `REG_'+entry['name'].upper()+'_DEFAULT;\n');770 if entry['endian']=="big" :771 regsFile.write('\772 for (byte_index = 0; byte_index <= (`REG_'+entry['name'].upper()+'_WIDTH/8-1); byte_index = byte_index +1)\n\773 '+entry['name']+'_reg_internal[byte_index*8 +: 8] <= reg_'+entry['name']+'_default_little[(C_S_AXI_DATA_WIDTH/8-byte_index-1)*8 +: 8];\n');774 if not(first_item):775 regsFile.write('\776 end\n\777 else begin\n\778 if (reg_wren) //write event\n\779 case (axi_awaddr)\n');780 for entry in regsDict:781 if entry['type']=="RWS" :782 if entry['endian']=="little" :783 regsFile.write('\784 //'+entry['name'].capitalize()+' Register\n\785 `REG_'+entry['name'].upper()+'_ADDR : begin\n\786 for ( byte_index = 0; byte_index <= (`REG_'+entry['name'].upper()+'_WIDTH/8-1); byte_index = byte_index +1)\n\787 if (S_AXI_WSTRB[byte_index] == 1) begin\n\788 '+entry['name']+'_reg[byte_index*8 +: 8] <= S_AXI_WDATA[byte_index*8 +: 8]; //static register;\n\789 end\n\790 end\n');791 if entry['endian']=="big" :792 regsFile.write('\793 //'+entry['name'].capitalize()+' Register\n\794 `REG_'+entry['name'].upper()+'_ADDR : begin\n\795 for (byte_index = 0; byte_index <= (`REG_'+entry['name'].upper()+'_WIDTH/8-1); byte_index = byte_index +1)\n\796 if (S_AXI_WSTRB[byte_index] == 1) begin\n\797 '+entry['name']+'_reg[byte_index*8 +: 8] <= S_AXI_WDATA[(C_S_AXI_DATA_WIDTH/8-byte_index-1)*8 +: 8]; //dynamic register;\n\798 end\n\799 end\n');800 801 if entry['type']=="RWA" :802 if entry['endian']=="little" :803 regsFile.write('\804 //'+entry['name'].capitalize()+' Register\n\805 `REG_'+entry['name'].upper()+'_ADDR : begin\n\806 for ( byte_index = 0; byte_index <= (`REG_'+entry['name'].upper()+'_WIDTH/8-1); byte_index = byte_index +1)\n\807 if (S_AXI_WSTRB[byte_index] == 1) begin\n\808 cpu2ip_'+entry['name']+'_reg[byte_index*8 +: 8] <= S_AXI_WDATA[byte_index*8 +: 8]; //dynamic register;\n\809 end\n\810 end\n');811 if entry['endian']=="big" :812 regsFile.write('\813 //'+entry['name'].capitalize()+' Register\n\814 `REG_'+entry['name'].upper()+'_ADDR : begin\n\815 for (byte_index = 0; byte_index <= (`REG_'+entry['name'].upper()+'_WIDTH/8-1); byte_index = byte_index +1)\n\816 if (S_AXI_WSTRB[byte_index] == 1) begin\n\817 cpu2ip_'+entry['name']+'_reg[byte_index*8 +: 8] <= S_AXI_WDATA[(C_S_AXI_DATA_WIDTH/8-byte_index-1)*8 +: 8]; //dynamic register;\n\818 end\n\819 end\n');820 if entry['type']=="RWSI" :821 if entry['endian']=="little" :822 regsFile.write('\823 //'+entry['name'].capitalize()+' Register\n\824 `REG_'+entry['name'].upper()+'_ADDR : begin\n\825 for ( byte_index = 0; byte_index <= (`REG_'+entry['name'].upper()+'_WIDTH/8-1); byte_index = byte_index +1)\n\826 if (S_AXI_WSTRB[byte_index] == 1) begin\n\827 '+entry['name']+'_reg[byte_index*8 +: 8] <= S_AXI_WDATA[byte_index*8 +: 8]; //static register;\n\828 end\n\829 end\n');830 if entry['endian']=="big" :831 regsFile.write('\832 //'+entry['name'].capitalize()+' Register\n\833 `REG_'+entry['name'].upper()+'_ADDR : begin\n\834 for (byte_index = 0; byte_index <= (`REG_'+entry['name'].upper()+'_WIDTH/8-1); byte_index = byte_index +1)\n\835 if (S_AXI_WSTRB[byte_index] == 1) begin\n\836 '+entry['name']+'_reg[byte_index*8 +: 8] <= S_AXI_WDATA[(C_S_AXI_DATA_WIDTH/8-byte_index-1)*8 +: 8]; //dynamic register;\n\837 end\n\838 end\n');839 if entry['type']=="RWI" :840 if entry['endian']=="little" :841 regsFile.write('\842 //'+entry['name'].capitalize()+' Register\n\843 `REG_'+entry['name'].upper()+'_ADDR : begin\n\844 for ( byte_index = 0; byte_index <= (`REG_'+entry['name'].upper()+'_WIDTH/8-1); byte_index = byte_index +1)\n\845 if (S_AXI_WSTRB[byte_index] == 1) begin\n\846 '+entry['name']+'_reg_internal[byte_index*8 +: 8] <= S_AXI_WDATA[byte_index*8 +: 8]; //static register;\n\847 end\n\848 end\n');849 if entry['endian']=="big" :850 regsFile.write('\851 //'+entry['name'].capitalize()+' Register\n\852 `REG_'+entry['name'].upper()+'_ADDR : begin\n\853 for (byte_index = 0; byte_index <= (`REG_'+entry['name'].upper()+'_WIDTH/8-1); byte_index = byte_index +1)\n\854 if (S_AXI_WSTRB[byte_index] == 1) begin\n\855 '+entry['name']+'_reg_internal[byte_index*8 +: 8] <= S_AXI_WDATA[(C_S_AXI_DATA_WIDTH/8-byte_index-1)*8 +: 8]; //dynamic register;\n\856 end\n\857 end\n');858 if not (first_item):859 regsFile.write('\860 default: begin\n\861 end\n\862\n\863 endcase\n\864 end\n');865 866 for entry in regsDict:867 if entry['type']=="RWI" :868 regsFile.write(' '+entry['name']+'_reg_update <= reg_wren && (axi_awaddr == `REG_'+entry['name'].upper()+'_ADDR);\n');869 870 if not (first_item):871 regsFile.write(' end\n');872 873#Handle Read/write registers, clear on read874 first_item=True;875 for entry in regsDict:876 if entry['type']=="RWCR" :877 if first_item:878 first_item = False;879 regsFile.write('\n\880//R/W register, clear on read\n\881 always @(posedge clk) begin\n\882 if (!resetn_sync) begin\n\883\n');884 if entry['endian']=="little" :885 regsFile.write('\886 cpu2ip_'+entry['name']+'_reg <= #1 `REG_'+entry['name'].upper()+'_DEFAULT;\n');887 if entry['endian']=="big" :888 regsFile.write('\889 for (byte_index = 0; byte_index <= (`REG_'+entry['name'].upper()+'_WIDTH/8-1); byte_index = byte_index +1)\n\890 cpu2ip_'+entry['name']+'_reg[byte_index*8 +: 8] <= reg_'+entry['name']+'_default_little[(C_S_AXI_DATA_WIDTH/8-byte_index-1)*8 +: 8];\n');891 if not (first_item):892 regsFile.write('\893 end\n\894 else begin\n\895 if (reg_wren)\n\896 case (axi_awaddr)\n');897 for entry in regsDict:898 if entry['type']=="RWCR" :899 if entry['endian']=="little" :900 regsFile.write('\901 //'+entry['name'].capitalize()+' Register\n\902 `REG_'+entry['name'].upper()+'_ADDR : begin\n\903 for ( byte_index = 0; byte_index <= (`REG_'+entry['name'].upper()+'_WIDTH/8-1); byte_index = byte_index +1)\n\904 if (S_AXI_WSTRB[byte_index] == 1) begin\n\905 cpu2ip_'+entry['name']+'_reg[byte_index*8 +: 8] <= S_AXI_WDATA[byte_index*8 +: 8];\n\906 end\n\907 end\n');908 if entry['endian']=="big" :909 regsFile.write('\910 //'+entry['name'].capitalize()+' Register\n\911 `REG_'+entry['name'].upper()+'_ADDR : begin\n\912 for (byte_index = 0; byte_index <= (`REG_'+entry['name'].upper()+'_WIDTH/8-1); byte_index = byte_index +1)\n\913 if (S_AXI_WSTRB[byte_index] == 1) begin\n\914 cpu2ip_'+entry['name']+'_reg[byte_index*8 +: 8] <= S_AXI_WDATA[(C_S_AXI_DATA_WIDTH/8-byte_index-1)*8 +: 8]; //dynamic register;\n\915 end\n\916 end\n');917 if not(first_item):918 regsFile.write('\919 endcase\n\920 end\n\921 end\n\922\n\923\n\924//clear assertions\n\925 always @(posedge clk) begin\n\926 if (!resetn_sync) begin\n');927 for entry in regsDict:928 if entry['type']=="RWCR" :929 regsFile.write('\930 cpu2ip_'+entry['name']+'_reg_clear <= #1 1\'b0;\n');931 if not(first_item):932 regsFile.write('\933 end\n\934 else begin\n');935 for entry in regsDict:936 if entry['type']=="RWCR" :937 regsFile.write('\938 cpu2ip_'+entry['name']+'_reg_clear <= #1 reg_rden && (axi_awaddr==`REG_'+entry['name'].upper()+'_ADDR) ? 1\'b1 : 1\'b0;\n');939 940 if not(first_item):941 regsFile.write('\n\942 end\n\943 end\n');944#Handle Read/write registers, clear on write945 first_item= True;946 for entry in regsDict:947 if entry['type']=="RWCW" :948 first_item = False;949 regsFile.write('\n\950//R/W register, clear on write, dynamic\n\951// i.e. on write - write, next clock - write default value\n\952 always @(posedge clk) begin\n\953 if (!resetn_sync) begin\n');954 if entry['endian']=="little" :955 regsFile.write('\956 cpu2ip_'+entry['name']+'_reg <= #1 `REG_'+entry['name'].upper()+'_DEFAULT;\n');957 if entry['endian']=="big" :958 regsFile.write('\959 for (byte_index = 0; byte_index <= (`REG_'+entry['name'].upper()+'_WIDTH/8-1); byte_index = byte_index +1)\n\960 cpu2ip_'+entry['name']+'_reg[byte_index*8 +: 8] <= reg_'+entry['name']+'_default_little[(C_S_AXI_DATA_WIDTH/8-byte_index-1)*8 +: 8];\n');961 regsFile.write('\962 cpu2ip_'+entry['name']+'_reg_clear_d <= #1 1\'b0;\n\963 cpu2ip_'+entry['name']+'_reg_clear <= #1 1\'b0;\n');964 if not(first_item):965 regsFile.write('\966 end\n\967 else begin\n');968 for entry in regsDict:969 if entry['type']=="RWCW" :970 regsFile.write('\971 cpu2ip_'+entry['name']+'_reg_clear <= cpu2ip_'+entry['name']+'_reg_clear_d;\n\972 cpu2ip_'+entry['name']+'_reg_clear_d <= reg_wren && (axi_awaddr==`REG_'+entry['name'].upper()+'_ADDR) ? 1\'b1 : 1\'b0;\n');973 if not(first_item):974 regsFile.write('\975 if (reg_wren) begin\n');976 for entry in regsDict:977 if entry['type']=="RWCW" :978 if entry['endian']=="little" :979 regsFile.write('\980 if (axi_awaddr==`REG_'+entry['name'].upper()+'_ADDR) begin\n\981 for ( byte_index = 0; byte_index <= (`REG_'+entry['name'].upper()+'_WIDTH/8-1); byte_index = byte_index+1 )\n\982 if ( S_AXI_WSTRB[byte_index] == 1 ) begin\n\983 cpu2ip_'+entry['name']+'_reg[byte_index*8 +: 8] <= S_AXI_WDATA[byte_index*8 +: 8];\n\984 end\n\985 end\n');986 if entry['endian']=="big" :987 regsFile.write('\988 if (axi_awaddr==`REG_'+entry['name'].upper()+'_ADDR) begin\n\989 for (byte_index = 0; byte_index <= (`REG_'+entry['name'].upper()+'_WIDTH/8-1); byte_index = byte_index +1)\n\990 if (S_AXI_WSTRB[byte_index] == 1) begin\n\991 cpu2ip_'+entry['name']+'_reg[byte_index*8 +: 8] <= S_AXI_WDATA[(C_S_AXI_DATA_WIDTH/8-byte_index-1)*8 +: 8]; //dynamic register;\n\992 end\n\993 end\n');994 if not(first_item):995 regsFile.write('\996 end\n\997 end\n\998 end\n');999 regsFile.write('\1000\n\1001\n\1002\n\1003/////////////////////////\n\1004//// end of write\n\1005/////////////////////////\n');1006 regsFile.write('\n\1007 // Implement memory mapped register select and read logic generation\n\1008 // Slave register read enable is asserted when valid address is available\n\1009 // and the slave is ready to accept the read address.\n\1010\n\1011 // reg_rden control logic\n\1012 // temperary no extra logic here\n\1013 assign reg_rden = axi_arready & S_AXI_ARVALID & ~axi_rvalid;\n');1014#return read data 1015 regsFile.write('\n\1016 always @(*)\n\1017 begin\n\1018\n\1019 case ( axi_araddr /*S_AXI_ARADDR ^ C_BASE_ADDRESS*/)\n');1020 1021 for entry in regsDict:1022 if entry['type']=="RO" or entry['type']=="ROC" or entry['type']=="RWS" or entry['type']=="RWI" or entry['type']=="RWSI" or entry['type']=="ROI":1023 if entry['endian']=="little" :1024 regsFile.write('\1025 //'+entry['name'].capitalize()+' Register\n\1026 `REG_'+entry['name'].upper()+'_ADDR : begin\n\1027 reg_data_out [`REG_'+entry['name'].upper()+'_BITS] = '+entry['name']+'_reg;\n');1028 1029 if entry['endian']=="big" :1030 regsFile.write('\1031 //'+entry['name'].capitalize()+' Register\n\1032 `REG_'+entry['name'].upper()+'_ADDR : begin\n\1033 for (byte_index = 0; byte_index <= (`REG_'+entry['name'].upper()+'_WIDTH/8-1); byte_index = byte_index +1)\n\1034 reg_data_out [byte_index*8 +: 8] = '+entry['name']+'_reg [(C_S_AXI_DATA_WIDTH/8-byte_index-1)*8 +: 8];\n');1035 if int(entry['width'])<32:1036 regsFile.write('\1037 reg_data_out [31:`REG_'+entry['name'].upper()+'_WIDTH] = \'b0;\n');1038 1039 regsFile.write('\1040 end\n');1041 1042 if entry['type']=="RWCW" or entry['type']=="RWA" or entry['type']=="RWCR":1043 if entry['endian']=="little" :1044 regsFile.write('\1045 //'+entry['name'].capitalize()+' Register\n\1046 `REG_'+entry['name'].upper()+'_ADDR : begin\n\1047 reg_data_out [`REG_'+entry['name'].upper()+'_BITS] = ip2cpu_'+entry['name']+'_reg;\n');1048 1049 if entry['endian']=="big" :1050 regsFile.write('\1051 //'+entry['name'].capitalize()+' Register\n\1052 `REG_'+entry['name'].upper()+'_ADDR : begin\n\1053 for (byte_index = 0; byte_index <= (`REG_'+entry['name'].upper()+'_WIDTH/8-1); byte_index = byte_index +1)\n\1054 reg_data_out [byte_index*8 +: 8] = ip2cpu_'+entry['name']+'_reg[(C_S_AXI_DATA_WIDTH/8-byte_index-1)*8 +: 8];\n');1055 1056 if int(entry['width']) < 32 :1057 regsFile.write('\1058 reg_data_out [31:`REG_'+entry['name'].upper()+'_WIDTH] = \'b0;\n');1059 1060 regsFile.write('\1061 end\n');1062 1063 regsFile.write('\1064 //Default return value\n\1065 default: begin\n\1066 reg_data_out [31:0] = 32\'hDEADBEEF;\n\1067 end\n\1068\n\1069 endcase\n\1070\n\1071 end//end of assigning data to IP2Bus_Data bus\n');1072#Handle read only registers1073 first_item=True;1074 for entry in regsDict:1075 if entry['type']=="ROC" :1076 if first_item:1077 first_item=False;1078 regsFile.write('\n\1079 //Read only registers, not cleared\n\1080 //Nothing to do here....\n\1081\n\1082//Read only registers, cleared on read (e.g. counters)\n\1083 always @(posedge clk)\n\1084 if (!resetn_sync) begin\n');1085 regsFile.write('\1086 '+entry['name']+'_reg_clear <= #1 1\'b0;\n\1087 '+entry['name']+'_reg_clear_d <= #1 1\'b0;\n');1088 if not(first_item):1089 regsFile.write(' end\n\1090 else begin\n');1091 for entry in regsDict:1092 if entry['type']=="ROC" :1093 regsFile.write('\1094 '+entry['name']+'_reg_clear <= #1 '+entry['name']+'_reg_clear_d;\n\1095 '+entry['name']+'_reg_clear_d <= #1(reg_rden && (axi_araddr==`REG_'+entry['name'].upper()+'_ADDR)) ? 1\'b1 : 1\'b0;\n');1096 if not(first_item):1097 regsFile.write(' end\n\n');1098 regsFile.write('\n\1099// Output register or memory read data\n\1100 always @( posedge S_AXI_ACLK )\n\1101 begin\n\1102 if ( S_AXI_ARESETN == 1\'b0 )\n\1103 begin\n\1104 axi_rdata <= 0;\n\1105 end\n\1106 else\n\1107 begin\n\1108 // When there is a valid read address (S_AXI_ARVALID) with\n\1109 // acceptance of read address by the slave (axi_arready),\n\1110 // output the read dada\n\1111 if (reg_rden)\n\1112 begin\n\1113 axi_rdata <= reg_data_out/*ip2bus_data*/; // register read data /* some new changes here */\n\1114 end\n\1115 end\n\1116 end\n');1117# end of write_logic1118##################################################################1119# a function that writes the logic behind the indirect registers access1120##################################################################1121def write_indirect(regsFile,memsDict):1122 regsFile.write('\n\1123 //////////////////////////////////\n\1124 // Implement Indirect Access\n\1125 //////////////////////////////////\n\1126 \n');1127 1128 regsFile.write('\n\1129 //--------------------- Internal Parameters-------------------------\n\1130 localparam NUM_INDIRECT_STATES = 6;\n\1131 localparam IDLE_INDIRECT_STATE = 1;\n\1132 localparam WRITE_INDIRECT_STATE = 2;\n\1133 localparam WRITE_WAIT_INDIRECT_STATE = 4;\n\1134 localparam READ_INDIRECT_STATE = 8;\n\1135 localparam READ_WAIT_INDIRECT_STATE = 16;\n\1136 localparam INDIRECT_DONE_STATE = 32;\n\1137 localparam INDIRECT_WRITE = 0;\n\1138 localparam INDIRECT_READ = 1;\n\1139 localparam INDIRECT_WRITE_TA = 1;\n\1140 localparam INDIRECT_WRITE_WS = 0;\n\1141 //------------------------------------------------------------------\n\1142 \n\1143 reg [NUM_INDIRECT_STATES-1:0] indirect_state, indirect_state_next, indirect_state_last;\n\1144 wire indirect_trigger;\n\1145 wire indirect_type;\n\1146 reg indirect_status, indirect_status_next;\n\1147 wire [3:0] indirect_address_increment;\n\1148 wire indirect_write_type;\n\1149 wire [10:0] indirect_timeout;\n\1150 wire [15:0] indirect_repeat_count;\n\1151 reg [15:0] indirect_remaining,indirect_remaining_next;\n\1152 reg [10:0] indirect_timeout_count, indirect_timeout_count_next;\n\1153 reg indirect_reply_valid;\n\1154 reg [31:0] indirect_address,indirect_address_next;\n\1155 reg [3:0] indirect_memory_select,indirect_memory_select_next;\n\1156 wire indirect_command_done;\n\1157 \n\1158 assign indirect_trigger = indirectcommand_reg[0];\n\1159 assign indirect_type = indirectcommand_reg[4];\n\1160 assign indirect_address_increment = indirectconfig_reg[3:0];\n\1161 assign indirect_write_type = indirectconfig_reg[4];\n\1162 assign indirect_timeout = indirectconfig_reg[15:5];\n\1163 assign indirect_repeat_count = indirectconfig_reg[31:16];\n\1164 \n\1165 always @(*) begin\n\1166 indirect_state_next = indirect_state;\n\1167 indirect_status_next = indirect_status;\n\1168 indirect_remaining_next = indirect_remaining;\n\1169 indirect_timeout_count_next = indirect_timeout_count;\n\1170 indirect_address_next = indirect_address;\n\1171 indirect_memory_select_next = indirect_memory_select;\n\1172 case(indirect_state)\n\1173 IDLE_INDIRECT_STATE: begin\n\1174 if(indirect_trigger) begin\n\1175 indirect_state_next= (indirect_type == INDIRECT_WRITE) ? WRITE_INDIRECT_STATE : READ_INDIRECT_STATE;\n\1176 indirect_remaining_next = (indirect_repeat_count == 0) ? 16\'h1 : indirect_repeat_count;\n\1177 indirect_timeout_count_next = indirect_timeout;\n\1178 indirect_address_next = indirectaddress_reg; //This is the address in the user register\n\1179 indirect_memory_select_next = indirectaddress_reg[31:28];\n\1180 end\n\1181 end\n\1182 \n\1183 READ_INDIRECT_STATE: begin\n\1184 indirect_state_next = READ_WAIT_INDIRECT_STATE;\n\1185 end\n\1186 READ_WAIT_INDIRECT_STATE: begin\n\1187 if (indirect_reply_valid) begin\n\1188 indirect_state_next = INDIRECT_DONE_STATE;\n\1189 indirect_status_next =0;\n\1190 end\n\1191 if (indirect_timeout_count==0) begin\n\1192 indirect_state_next = INDIRECT_DONE_STATE;\n\1193 indirect_status_next = 1; \n\1194 end\n\1195 indirect_timeout_count_next = indirect_timeout_count-1;\n\1196 end\n\1197 WRITE_INDIRECT_STATE: begin\n\1198 indirect_state_next = WRITE_WAIT_INDIRECT_STATE;\n\1199 end\n\1200 WRITE_WAIT_INDIRECT_STATE: begin\n\1201 if (((indirect_write_type == INDIRECT_WRITE_TA) && (indirect_reply_valid)) || ((indirect_write_type == INDIRECT_WRITE_WS) && (indirect_timeout_count==0))) begin\n\1202 indirect_remaining_next = indirect_remaining - 1;\n\1203 indirect_address_next = indirect_address+indirect_address_increment;\n\1204 if (indirect_remaining==1) begin\n\1205 indirect_state_next = INDIRECT_DONE_STATE;\n\1206 end\n\1207 end\n\1208 else \n\1209 if (indirect_timeout_count==0) begin\n\1210 indirect_state_next = INDIRECT_DONE_STATE;\n\1211 indirect_status_next = 1; \n\1212 end\n\1213 indirect_timeout_count_next = indirect_timeout_count==0 ? 0 : indirect_timeout_count-1;\n\1214 end\n\1215 INDIRECT_DONE_STATE: begin\n\1216 indirect_state_next= IDLE_INDIRECT_STATE;\n\1217 end\n\1218 default: begin\n\1219 indirect_state_next= IDLE_INDIRECT_STATE;\n\1220 end\n\1221 endcase // case(state)\n\1222 end // always @ (*)\n\1223 \n\1224 assign indirect_command_done = (indirect_state==INDIRECT_DONE_STATE);\n\1225 \n\1226 always @(posedge clk) begin\n\1227 if(~resetn_sync) begin\n\1228 indirect_state <= #1 IDLE_INDIRECT_STATE;\n\1229 indirect_state_last <= #1 IDLE_INDIRECT_STATE;\n\1230 indirect_status <= #1 1\'b0;\n\1231 indirect_remaining <= #1 0;\n\1232 indirect_timeout_count <= #1 0;\n\1233 indirect_address <= #1 0;\n\1234 indirect_memory_select <= #1 0;\n\1235 indirectcommand_reg <= #1 `REG_INDIRECTCOMMAND_DEFAULT;\n\1236 end\n\1237 else begin\n\1238 indirect_state <= #1 indirect_state_next;\n\1239 indirect_state_last <= #1 indirect_state;\n\1240 indirect_status <= #1 indirect_status_next;\n\1241 indirect_remaining <= #1 indirect_remaining_next;\n\1242 indirect_timeout_count <= #1 indirect_timeout_count_next;\n\1243 indirect_address <= #1 indirect_address_next;\n\1244 indirect_memory_select <= #1 indirect_memory_select_next;\n\1245 indirectcommand_reg <= #1 indirect_command_done ? {indirect_status,indirectcommand_reg[7:4],4\'h0} : \n\1246 indirectcommand_reg_update ? indirectcommand_reg_internal: \n\1247 indirectcommand_reg;\n\1248 end\n\1249 end \n\1250 \n');1251 for entry in memsDict:1252 regsFile.write('\n\1253 \n\1254 always @(posedge clk) begin\n\1255 if (~resetn_sync) begin\n\1256 '+entry['name']+'_addr <= #1 0;\n\1257 '+entry['name']+'_data <= #1 0;\n\1258 '+entry['name']+'_rd_wrn<= #1 0;\n\1259 '+entry['name']+'_cmd_valid <= #1 0;\n\1260 end \n\1261 else begin\n\1262 '+entry['name']+'_addr <= #1 indirect_address;\n\1263 '+entry['name']+'_data <= #1 indirectwrdata_reg;\n\1264 '+entry['name']+'_rd_wrn<= #1 indirect_type;\n\1265 '+entry['name']+'_cmd_valid <= #1 ('+entry['address']+'==(indirect_memory_select<<28)) && ((indirect_state == WRITE_INDIRECT_STATE) || (indirect_state == READ_INDIRECT_STATE));\n\1266 end \n\1267 end\n');1268 1269 regsFile.write('\n\1270 always @(posedge clk) begin\n\1271 if (~resetn_sync) begin\n\1272 indirectreply_reg <= #1 0;\n\1273 indirect_reply_valid <= #1 0; \n\1274 end \n\1275 else begin \n\1276 indirectreply_reg <= #1 ' );1277 for entry in memsDict:1278 regsFile.write(entry['address']+'==(indirect_memory_select<<28) ? '+entry['name']+'_reply :');1279 regsFile.write(' 0;\n\1280 indirect_reply_valid <= #1 ');1281 for entry in memsDict:1282 regsFile.write(entry['address']+'==(indirect_memory_select<<28) ? '+entry['name']+'_reply_valid :');1283 regsFile.write(' 0;\n\1284 end \n\1285 end\n\1286 \n');1287# end of write_indirect1288##################################################################1289#write all the defines to the defs module1290##################################################################1291def write_defines(defsFile,regsDict, memsDict):1292 for entry in regsDict:1293 defsFile.write( '\n`define REG_'+entry['name'].upper()+'_BITS\t\t\t\t'+entry['bits']+1294 '\n`define REG_'+entry['name'].upper()+'_WIDTH\t\t\t\t'+entry['width']+1295 '\n`define REG_'+entry['name'].upper()+'_DEFAULT\t\t\t\t'+entry['default']+1296 '\n`define REG_'+entry['name'].upper()+'_ADDR\t\t\t\t'+entry['addr']+'\n');1297 for entry in memsDict:1298 defsFile.write( '\n`define MEM_'+entry['name'].upper()+'_DATA_BITS\t\t\t\t'+entry['data_bits']+1299 '\n`define MEM_'+entry['name'].upper()+'_ADDR_BITS\t\t\t\t'+entry['addr_bits']+1300 '\n`define MEM_'+entry['name'].upper()+'_WIDTH\t\t\t\t'+entry['width']+1301 '\n`define MEM_'+entry['name'].upper()+'_DEPTH\t\t\t\t'+str(2**(int(entry['addr_bits'].split(':')[0])+1))+1302 '\n`define MEM_'+entry['name'].upper()+'_ADDR\t\t\t\t'+entry['address']+'\n');1303 1304#end of write_defines1305##################################################################1306#write all the register offsets to the h template (to be included)1307##################################################################1308def write_h(hFile,regsDict,memsDict):1309 hFile.write('##########This text should be copied to the head file #############\n\1310 #Registers offset definitions\n\n');1311 1312 for entry in regsDict:1313 hFile.write('#define SUME_'+block_name+'_'+entry['name'].upper()+'_0_OFFSET 0x'+entry['addr'][4:]+'\n');1314 hFile.write('#define SUME_'+block_name+'_'+entry['name'].upper()+'_0_DEFAULT 0x'+entry['default'].split("'h")[-1]+'\n');1315 hFile.write('#define SUME_'+block_name+'_'+entry['name'].upper()+'_0_WIDTH '+entry['width']+'\n');1316 for entry in memsDict:1317 hFile.write('#define SUME_'+block_name+'_MEM_'+entry['name'].upper()+'_0_WIDTH '+entry['width']+'\n');1318 hFile.write('#define SUME_'+block_name+'_MEM_'+entry['name'].upper()+'_0_DEPTH '+str(2**(int(entry['addr_bits'].split(':')[0])+1))+'\n');1319 hFile.write('#define SUME_'+block_name+'_MEM_'+entry['name'].upper()+'_0_ADDRESS 0x'+entry['address'].split("'h")[-1]+'\n');1320#end of write_h1321##################################################################1322#write all the register offsets to the tcl file1323##################################################################1324def write_tcl(tclFile,regsDict,memsDict):1325 for entry in regsDict:1326 tclFile.write('set '+block_name+'_REGS_'+entry['name'].upper()+'_0_OFFSET 0x'+entry['addr'][4:]+'\n');1327 tclFile.write('set '+block_name+'_REGS_'+entry['name'].upper()+'_0_DEFAULT 0x'+entry['default'].split("'h")[-1]+'\n');1328 tclFile.write('set '+block_name+'_REGS_'+entry['name'].upper()+'_0_WIDTH '+entry['width']+'\n');1329 for entry in memsDict:1330 tclFile.write('set '+block_name+'_MEM_'+entry['name'].upper()+'_0_WIDTH '+entry['width']+'\n');1331 tclFile.write('set '+block_name+'_MEM_'+entry['name'].upper()+'_0_DEPTH '+str(2**(int(entry['addr_bits'].split(':')[0])+1))+'\n');1332 tclFile.write('set '+block_name+'_MEM_'+entry['name'].upper()+'_0_ADDRESS 0x'+entry['address'].split("'h")[-1]+'\n');1333 1334#end of write_tcl1335##################################################################1336#write all the register offsets to table1337##################################################################1338def write_tb(tbFile,regsDict,memsDict):1339 for entry in regsDict:1340 tbFile.write('#define SUME '+block_name+' '+entry['name'].upper()+' OFFSET 0x'+entry['addr'][4:]+'\n');1341 tbFile.write('#define SUME '+block_name+' '+entry['name'].upper()+' DEFAULT 0x'+entry['default'].split("'h")[-1]+'\n');1342 tbFile.write('#define SUME '+block_name+' '+entry['name'].upper()+' WIDTH '+entry['width']+'\n');1343 for entry in memsDict:1344 tbFile.write('#define SUME '+block_name+' MEM_'+entry['name'].upper()+' WIDTH '+entry['width']+'\n');1345 tbFile.write('#define SUME '+block_name+' MEM_'+entry['name'].upper()+' DEPTH '+str(2**(int(entry['addr_bits'].split(':')[0])+1))+'\n');1346 tbFile.write('#define SUME '+block_name+' MEM_'+entry['name'].upper()+' ADDRESS 0x'+entry['address'].split("'h")[-1]+'\n');1347#end of write_tb1348##################################################################1349#write top module's template (i.e. include this in your module)1350##################################################################1351def write_module_template(moduleFile,regsDict,memsDict):1352#first write static inclusions....1353 moduleFile.write('`include "'+module_name+'_cpu_regs_defines.v"\n\1354\n\1355//parameters to be added to the top module parameters\n\1356#(\n\1357 // AXI Registers Data Width\n\1358 parameter C_S_AXI_DATA_WIDTH = 32,\n\1359 parameter C_S_AXI_ADDR_WIDTH = 32\n\1360)\n\1361//ports to be added to the top module ports\n\1362(\n\1363// Signals for AXI_IP and IF_REG (Added for debug purposes)\n\1364 // Slave AXI Ports\n\1365 input S_AXI_ACLK,\n\1366 input S_AXI_ARESETN,\n\1367 input [C_S_AXI_ADDR_WIDTH-1 : 0] S_AXI_AWADDR,\n\1368 input S_AXI_AWVALID,\n\1369 input [C_S_AXI_DATA_WIDTH-1 : 0] S_AXI_WDATA,\n\1370 input [C_S_AXI_DATA_WIDTH/8-1 : 0] S_AXI_WSTRB,\n\1371 input S_AXI_WVALID,\n\1372 input S_AXI_BREADY,\n\1373 input [C_S_AXI_ADDR_WIDTH-1 : 0] S_AXI_ARADDR,\n\1374 input S_AXI_ARVALID,\n\1375 input S_AXI_RREADY,\n\1376 output S_AXI_ARREADY,\n\1377 output [C_S_AXI_DATA_WIDTH-1 : 0] S_AXI_RDATA,\n\1378 output [1 : 0] S_AXI_RRESP,\n\1379 output S_AXI_RVALID,\n\1380 output S_AXI_WREADY,\n\1381 output [1 :0] S_AXI_BRESP,\n\1382 output S_AXI_BVALID,\n\1383 output S_AXI_AWREADY\n\1384)\n\n');1385 first_item = True;1386 for entry in regsDict:1387 if first_item and (entry['endian']=="big") :1388 first_item = False;1389 moduleFile.write('\n\1390 // define and assign default little endian\n');1391 for entry in regsDict:1392 if entry['endian']=="big" :1393 moduleFile.write('\1394 wire reg_'+entry['name']+'_default_little;\n');1395 for entry in regsDict:1396 if entry['endian']=="big" :1397 moduleFile.write('\1398 assign reg_'+entry['name']+'_default_little = `REG_'+entry['name'].upper()+'_DEFAULT;\n');1399#then add design specific wires/regs:1400 moduleFile.write('\n\1401 // define registers\n');1402 for entry in regsDict:1403 if entry['type']=="RO" :1404 moduleFile.write(' reg [`REG_'+(entry['name']).upper()+'_BITS] '+entry['name']+'_reg;\n')1405 if entry['type']=="ROC" :1406 moduleFile.write(' reg [`REG_'+(entry['name']).upper()+'_BITS] '+entry['name']+'_reg;\n')1407 moduleFile.write(' wire '+entry['name']+'_reg_clear;\n')1408 if entry['type']=="RWS" :1409 moduleFile.write(' wire [`REG_'+(entry['name']).upper()+'_BITS] '+entry['name']+'_reg;\n')1410 if entry['type']=="WO" :1411 moduleFile.write(' wire [`REG_'+(entry['name']).upper()+'_BITS] '+entry['name']+'_reg;\n')1412 if entry['type']=="WOE" :1413 moduleFile.write(' wire [`REG_'+(entry['name']).upper()+'_BITS] '+entry['name']+'_reg;\n')1414 if entry['type']=="RWA" :1415 moduleFile.write(' reg [`REG_'+(entry['name']).upper()+'_BITS] ip2cpu_'+entry['name']+'_reg;\n')1416 moduleFile.write(' wire [`REG_'+(entry['name']).upper()+'_BITS] cpu2ip_'+entry['name']+'_reg;\n')1417 if entry['type']=="RWCR" :1418 moduleFile.write(' reg [`REG_'+(entry['name']).upper()+'_BITS] ip2cpu_'+entry['name']+'_reg;\n')1419 moduleFile.write(' wire [`REG_'+(entry['name']).upper()+'_BITS] cpu2ip_'+entry['name']+'_reg;\n')1420 moduleFile.write(' wire cpu2ip_'+entry['name']+'_reg_clear;\n')1421 if entry['type']=="RWCW" :1422 moduleFile.write(' reg [`REG_'+(entry['name']).upper()+'_BITS] ip2cpu_'+entry['name']+'_reg;\n')1423 moduleFile.write(' wire [`REG_'+(entry['name']).upper()+'_BITS] cpu2ip_'+entry['name']+'_reg;\n')1424 moduleFile.write(' wire cpu2ip_'+entry['name']+'_reg_clear;\n')1425 moduleFile.write(' wire cpu2ip_'+entry['name']+'_reg_clear_d;\n')1426 for entry in memsDict:1427 moduleFile.write(' wire [`MEM_'+(entry['name']).upper()+'_ADDR_BITS] '+entry['name']+'_addr;\n')1428 moduleFile.write(' wire [`MEM_'+(entry['name']).upper()+'_DATA_BITS] '+entry['name']+'_data;\n')1429 moduleFile.write(' wire '+entry['name']+'_rd_wrn;\n')1430 moduleFile.write(' wire '+entry['name']+'_cmd_valid;\n')1431 moduleFile.write(' reg [`MEM_'+(entry['name']).upper()+'DATA_BITS] '+entry['name']+'_reply;\n')1432 moduleFile.write(' reg '+entry['name']+'_reply_valid;\n') 1433#instantiate registers module1434 moduleFile.write('\n//Registers section\n\1435 '+module_name+'_cpu_regs\n\1436 #(\n\1437 .C_BASE_ADDRESS (C_BASEADDR ),\n\1438 .C_S_AXI_DATA_WIDTH (C_S_AXI_DATA_WIDTH),\n\1439 .C_S_AXI_ADDR_WIDTH (C_S_AXI_ADDR_WIDTH)\n\1440 ) '+module_name+'_cpu_regs_inst\n\1441 (\n\1442 // General ports\n\1443 .clk (axis_aclk),\n\1444 .resetn (axis_resetn),\n\1445 // AXI Lite ports\n\1446 .S_AXI_ACLK (S_AXI_ACLK),\n\1447 .S_AXI_ARESETN (S_AXI_ARESETN),\n\1448 .S_AXI_AWADDR (S_AXI_AWADDR),\n\1449 .S_AXI_AWVALID (S_AXI_AWVALID),\n\1450 .S_AXI_WDATA (S_AXI_WDATA),\n\1451 .S_AXI_WSTRB (S_AXI_WSTRB),\n\1452 .S_AXI_WVALID (S_AXI_WVALID),\n\1453 .S_AXI_BREADY (S_AXI_BREADY),\n\1454 .S_AXI_ARADDR (S_AXI_ARADDR),\n\1455 .S_AXI_ARVALID (S_AXI_ARVALID),\n\1456 .S_AXI_RREADY (S_AXI_RREADY),\n\1457 .S_AXI_ARREADY (S_AXI_ARREADY),\n\1458 .S_AXI_RDATA (S_AXI_RDATA),\n\1459 .S_AXI_RRESP (S_AXI_RRESP),\n\1460 .S_AXI_RVALID (S_AXI_RVALID),\n\1461 .S_AXI_WREADY (S_AXI_WREADY),\n\1462 .S_AXI_BRESP (S_AXI_BRESP),\n\1463 .S_AXI_BVALID (S_AXI_BVALID),\n\1464 .S_AXI_AWREADY (S_AXI_AWREADY),\n\1465\n\1466 // Register ports\n');1467 for entry in regsDict:1468 if entry['type']=="RO" :1469 moduleFile.write(' .'+entry['name']+'_reg ('+entry['name']+'_reg),\n')1470 if entry['type']=="ROC" :1471 moduleFile.write(' .'+entry['name']+'_reg ('+entry['name']+'_reg),\n')1472 moduleFile.write(' .'+entry['name']+'_reg_clear ('+entry['name']+'_reg_clear),\n')1473 if entry['type']=="RWS" :1474 moduleFile.write(' .'+entry['name']+'_reg ('+entry['name']+'_reg),\n')1475 if entry['type']=="WO" :1476 moduleFile.write(' .'+entry['name']+'_reg ('+entry['name']+'_reg),\n')1477 if entry['type']=="WOE" :1478 moduleFile.write(' .'+entry['name']+'_reg ('+entry['name']+'_reg),\n')1479 if entry['type']=="RWA" :1480 moduleFile.write(' .ip2cpu_'+entry['name']+'_reg (ip2cpu_'+entry['name']+'_reg),\n')1481 moduleFile.write(' .cpu2ip_'+entry['name']+'_reg (cpu2ip_'+entry['name']+'_reg),\n')1482 if entry['type']=="RWCR" :1483 moduleFile.write(' .ip2cpu_'+entry['name']+'_reg (ip2cpu_'+entry['name']+'_reg),\n')1484 moduleFile.write(' .cpu2ip_'+entry['name']+'_reg (cpu2ip_'+entry['name']+'_reg),\n')1485 moduleFile.write(' .cpu2ip_'+entry['name']+'_reg_clear (cpu2ip_'+entry['name']+'_reg_clear),\n')1486 if entry['type']=="RWCW" :1487 moduleFile.write(' .ip2cpu_'+entry['name']+'_reg (ip2cpu_'+entry['name']+'_reg),\n')1488 moduleFile.write(' .cpu2ip_'+entry['name']+'_reg (cpu2ip_'+entry['name']+'_reg),\n')1489 moduleFile.write(' .cpu2ip_'+entry['name']+'_reg_clear (cpu2ip_'+entry['name']+'_reg_clear),\n')1490 for entry in memsDict:1491 moduleFile.write(' .'+entry['name']+'_addr ('+entry['name']+'_addr),\n')1492 moduleFile.write(' .'+entry['name']+'_data ('+entry['name']+'_data),\n')1493 moduleFile.write(' .'+entry['name']+'_rd_wrn ('+entry['name']+'_rd_wrn),\n')1494 moduleFile.write(' .'+entry['name']+'_cmd_valid ('+entry['name']+'_cmd_valid ),\n')1495 moduleFile.write(' .'+entry['name']+'_reply ('+entry['name']+'_reply),\n')1496 moduleFile.write(' .'+entry['name']+'_reply_valid ('+entry['name']+'_reply_valid),\n') 1497 moduleFile.write(' // Global Registers - user can select if to use\n\1498 .cpu_resetn_soft(),//software reset, after cpu module\n\1499 .resetn_soft (),//software reset to cpu module (from central reset management)\n\1500 .resetn_sync (resetn_sync)//synchronized reset, use for better timing\n\1501);\n\1502//registers logic, current logic is just a placeholder for initial compil, required to be changed by the user\n');1503#registers logic1504 moduleFile.write('always @(posedge axis_aclk)\n\1505 if (~resetn_sync) begin\n');1506 for entry in regsDict:1507 if entry['type']=="RO" :1508 if entry['endian']=="little":1509 moduleFile.write('\1510 '+entry['name']+'_reg <= #1 `REG_'+entry['name'].upper()+'_DEFAULT;\n');1511 if entry['endian']=="big":1512 moduleFile.write('\1513 for (byte_index = 0; byte_index <= (`REG_'+entry['name'].upper()+'_WIDTH/8-1); byte_index = byte_index +1)\n\1514 '+entry['name']+'_reg[byte_index*8 +: 8] <= reg_'+entry['name']+'_default_little[(C_S_AXI_DATA_WIDTH/8-byte_index-1)*8 +: 8];\n');1515 if entry['type']=="ROC" :1516 if entry['endian']=="little":1517 moduleFile.write('\1518 '+entry['name']+'_reg <= #1 `REG_'+entry['name'].upper()+'_DEFAULT;\n');1519 if entry['endian']=="big":1520 moduleFile.write('\1521 for (byte_index = 0; byte_index <= (`REG_'+entry['name'].upper()+'_WIDTH/8-1); byte_index = byte_index +1)\n\1522 '+entry['name']+'_reg[byte_index*8 +: 8] <= reg_'+entry['name']+'_default_little[(C_S_AXI_DATA_WIDTH/8-byte_index-1)*8 +: 8];\n');1523 if entry['type']=="RWA" :1524 if entry['endian']=="little":1525 moduleFile.write('\1526 ip2cpu_'+entry['name']+'_reg <= #1 `REG_'+entry['name'].upper()+'_DEFAULT;\n');1527 if entry['endian']=="big":1528 moduleFile.write('\1529 for (byte_index = 0; byte_index <= (`REG_'+entry['name'].upper()+'_WIDTH/8-1); byte_index = byte_index +1)\n\1530 ip2cpu_'+entry['name']+'_reg[byte_index*8 +: 8] <= reg_'+entry['name']+'_default_little[(C_S_AXI_DATA_WIDTH/8-byte_index-1)*8 +: 8];\n');1531 if entry['type']=="RWCR" :1532 if entry['endian']=="little":1533 moduleFile.write('\1534 ip2cpu_'+entry['name']+'_reg <= #1 `REG_'+entry['name'].upper()+'_DEFAULT;\n');1535 if entry['endian']=="big":1536 moduleFile.write('\1537 for (byte_index = 0; byte_index <= (`REG_'+entry['name'].upper()+'_WIDTH/8-1); byte_index = byte_index +1)\n\1538 ip2cpu_'+entry['name']+'_reg[byte_index*8 +: 8] <= reg_'+entry['name']+'_default_little[(C_S_AXI_DATA_WIDTH/8-byte_index-1)*8 +: 8];\n');1539 if entry['type']=="RWCW" :1540 if entry['endian']=="little":1541 moduleFile.write('\1542 ip2cpu_'+entry['name']+'_reg <= #1 `REG_'+entry['name'].upper()+'_DEFAULT;\n');1543 if entry['endian']=="big":1544 moduleFile.write('\1545 for (byte_index = 0; byte_index <= (`REG_'+entry['name'].upper()+'_WIDTH/8-1); byte_index = byte_index +1)\n\1546 ip2cpu_'+entry['name']+'_reg[byte_index*8 +: 8] <= reg_'+entry['name']+'_default_little[(C_S_AXI_DATA_WIDTH/8-byte_index-1)*8 +: 8];\n');1547 moduleFile.write(' cpu_'+entry['name']+'_reg_clear_d <= #1 \'h0\n;')1548 1549 moduleFile.write(' end\n\1550 else begin\n')1551 for entry in regsDict:1552 if entry['type']=="RO" :1553 if entry['endian']=="little":1554 moduleFile.write('\1555 '+entry['name']+'_reg <= #1 `REG_'+entry['name'].upper()+'_DEFAULT;\n');1556 if entry['endian']=="big":1557 moduleFile.write('\1558 for (byte_index = 0; byte_index <= (`REG_'+entry['name'].upper()+'_WIDTH/8-1); byte_index = byte_index +1)\n\1559 '+entry['name']+'_reg[byte_index*8 +: 8] <= reg_'+entry['name']+'_default_little[(C_S_AXI_DATA_WIDTH/8-byte_index-1)*8 +: 8];\n');1560 if entry['type']=="ROC" :1561 if entry['endian']=="little":1562 moduleFile.write('\1563 '+entry['name']+'_reg <= #1 '+entry['name']+'_reg_clear ? \'h0 : `REG_'+entry['name'].upper()+'_DEFAULT;\n');1564 if entry['endian']=="big":1565 moduleFile.write('\1566 if ('+entry['name']+'_reg_clear == 1\'b1) \n\1567 '+entry['name']+'_reg <= #1 \'h0;\n\1568 else\n\1569 for (byte_index = 0; byte_index <= (`REG_'+entry['name'].upper()+'_WIDTH/8-1); byte_index = byte_index +1)\n\1570 '+entry['name']+'_reg[byte_index*8 +: 8] <= reg_'+entry['name']+'_default_little[(C_S_AXI_DATA_WIDTH/8-byte_index-1)*8 +: 8];\n');1571 if entry['type']=="RWA" :1572 moduleFile.write(' ip2cpu_'+entry['name']+'_reg <= #1 cpu2ip_'+entry['name']+'_reg;\n')1573 if entry['type']=="RWCR" :1574 if entry['endian']=="little":1575 moduleFile.write('\1576 ip2cpu_'+entry['name']+'_reg <= #1 '+entry['name']+'_reg_clear ? \'h0 : `REG_'+entry['name'].upper()+'_DEFAULT;\n');1577 if entry['endian']=="big":1578 moduleFile.write('\1579 if ('+entry['name']+'_reg_clear == 1\'b1) \n\1580 '+entry['name']+'_reg <= #1 \'h0;\n\1581 else\n\1582 ip2cpu_'+entry['name']+'_reg <= #1 cpu2ip_'+entry['name']+'_reg;');1583 if entry['type']=="RWCW" :1584 if entry['endian']=="little":1585 moduleFile.write('\1586 ip2cpu_'+entry['name']+'_reg <= #1 '+entry['name']+'_reg_clear ? \'h0 : `REG_'+entry['name'].upper()+'_DEFAULT;\n');1587 if entry['endian']=="big":1588 moduleFile.write('\1589 if ('+entry['name']+'_reg_clear_d == 1\'b1) \n\1590 ip2cpu_'+entry['name']+'_reg <= #1 \'h0;\n\1591 else\n\1592 ip2cpu_'+entry['name']+'_reg <= #1 cpu2ip_'+entry['name']+'_reg;');1593 moduleFile.write(' cpu_'+entry['name']+'_reg_clear_d <= #1 cpu_'+entry['name']+'_reg_clear;\n')1594 moduleFile.write('\1595 end\n\n')1596#end of write_module_template1597########################################################################################1598#1599# Main function body1600#1601########################################################################################1602# List of files to be generated.1603filename_regs=''+module_name+'_cpu_regs.v'1604filename_defs=''+module_name+'_cpu_regs_defines.v'1605filename_template=''+module_name+'_cpu_template.v'1606filename_h=''+module_name+'_regs_defines.h' 1607filename_tcl=''+module_name+'_regs_defines.tcl'1608filename_tb=''+module_name+'_regs_defines.txt'1609# Open the files for writing1610regsFile = open(filename_regs, 'w')1611defsFile = open(filename_defs, 'w')1612moduleFile = open(filename_template, 'w')1613hFile = open(filename_h, 'w')1614tclFile = open(filename_tcl, 'w')1615tbFile = open(filename_tb, 'w')1616# Write the header of each file1617write_regs_header(regsFile)1618write_defs_header(defsFile)1619write_tcl_header(tclFile)1620write_hFile_header(hFile)1621write_tbFile_header(tbFile)1622#Write the regs module1623#first the ports...1624regsDict=create_regs_list()1625memsDict=create_mems_list()1626write_regs_ports(regsFile,regsDict, memsDict)1627#then the wires...1628write_regs_wires(regsFile,regsDict, memsDict)1629#resets etc.....1630sync_reset(regsFile)1631#registers logic...1632write_logic(regsFile,regsDict)1633#indirect access...1634if memsDict:1635 write_indirect(regsFile,memsDict)1636#tables...1637#close module.....1638regsFile.write('endmodule\n')1639#write the defs module1640write_defines(defsFile,regsDict, memsDict)1641#write the tcl module1642write_tcl(tclFile,regsDict, memsDict)1643#write the default text to be copied to the h module1644write_h(hFile,regsDict, memsDict)1645#write the default text to table file1646write_tb(tbFile,regsDict, memsDict)1647#writes the default text to be copied to the top module1648write_module_template(moduleFile,regsDict, memsDict)1649# Close the output files1650regsFile.close()1651defsFile.close()1652tclFile.close()1653moduleFile.close()1654hFile.close()...

Full Screen

Full Screen

FeedEntryViewer.js.uncompressed.js

Source:FeedEntryViewer.js.uncompressed.js Github

copy

Full Screen

1require({cache:{2'url:dojox/atom/widget/templates/EntryHeader.html':"<span dojoAttachPoint=\"entryHeaderNode\" class=\"entryHeaderNode\"></span>\n",3'url:dojox/atom/widget/templates/FeedEntryViewer.html':"<div class=\"feedEntryViewer\">\n <table border=\"0\" width=\"100%\" class=\"feedEntryViewerMenuTable\" dojoAttachPoint=\"feedEntryViewerMenu\" style=\"display: none;\">\n <tr width=\"100%\" dojoAttachPoint=\"entryCheckBoxDisplayOptions\">\n <td align=\"right\">\n <span class=\"feedEntryViewerMenu\" dojoAttachPoint=\"displayOptions\" dojoAttachEvent=\"onclick:_toggleOptions\"></span>\n </td>\n </tr>\n <tr class=\"feedEntryViewerDisplayCheckbox\" dojoAttachPoint=\"entryCheckBoxRow\" width=\"100%\" style=\"display: none;\">\n <td dojoAttachPoint=\"feedEntryCelltitle\">\n <input type=\"checkbox\" name=\"title\" value=\"Title\" dojoAttachPoint=\"feedEntryCheckBoxTitle\" dojoAttachEvent=\"onclick:_toggleCheckbox\"/>\n\t\t\t\t<label for=\"title\" dojoAttachPoint=\"feedEntryCheckBoxLabelTitle\"></label>\n </td>\n <td dojoAttachPoint=\"feedEntryCellauthors\">\n <input type=\"checkbox\" name=\"authors\" value=\"Authors\" dojoAttachPoint=\"feedEntryCheckBoxAuthors\" dojoAttachEvent=\"onclick:_toggleCheckbox\"/>\n\t\t\t\t<label for=\"title\" dojoAttachPoint=\"feedEntryCheckBoxLabelAuthors\"></label>\n </td>\n <td dojoAttachPoint=\"feedEntryCellcontributors\">\n <input type=\"checkbox\" name=\"contributors\" value=\"Contributors\" dojoAttachPoint=\"feedEntryCheckBoxContributors\" dojoAttachEvent=\"onclick:_toggleCheckbox\"/>\n\t\t\t\t<label for=\"title\" dojoAttachPoint=\"feedEntryCheckBoxLabelContributors\"></label>\n </td>\n <td dojoAttachPoint=\"feedEntryCellid\">\n <input type=\"checkbox\" name=\"id\" value=\"Id\" dojoAttachPoint=\"feedEntryCheckBoxId\" dojoAttachEvent=\"onclick:_toggleCheckbox\"/>\n\t\t\t\t<label for=\"title\" dojoAttachPoint=\"feedEntryCheckBoxLabelId\"></label>\n </td>\n <td rowspan=\"2\" align=\"right\">\n <span class=\"feedEntryViewerMenu\" dojoAttachPoint=\"close\" dojoAttachEvent=\"onclick:_toggleOptions\"></span>\n </td>\n\t\t</tr>\n\t\t<tr class=\"feedEntryViewerDisplayCheckbox\" dojoAttachPoint=\"entryCheckBoxRow2\" width=\"100%\" style=\"display: none;\">\n <td dojoAttachPoint=\"feedEntryCellupdated\">\n <input type=\"checkbox\" name=\"updated\" value=\"Updated\" dojoAttachPoint=\"feedEntryCheckBoxUpdated\" dojoAttachEvent=\"onclick:_toggleCheckbox\"/>\n\t\t\t\t<label for=\"title\" dojoAttachPoint=\"feedEntryCheckBoxLabelUpdated\"></label>\n </td>\n <td dojoAttachPoint=\"feedEntryCellsummary\">\n <input type=\"checkbox\" name=\"summary\" value=\"Summary\" dojoAttachPoint=\"feedEntryCheckBoxSummary\" dojoAttachEvent=\"onclick:_toggleCheckbox\"/>\n\t\t\t\t<label for=\"title\" dojoAttachPoint=\"feedEntryCheckBoxLabelSummary\"></label>\n </td>\n <td dojoAttachPoint=\"feedEntryCellcontent\">\n <input type=\"checkbox\" name=\"content\" value=\"Content\" dojoAttachPoint=\"feedEntryCheckBoxContent\" dojoAttachEvent=\"onclick:_toggleCheckbox\"/>\n\t\t\t\t<label for=\"title\" dojoAttachPoint=\"feedEntryCheckBoxLabelContent\"></label>\n </td>\n </tr>\n </table>\n \n <table class=\"feedEntryViewerContainer\" border=\"0\" width=\"100%\">\n <tr class=\"feedEntryViewerTitle\" dojoAttachPoint=\"entryTitleRow\" style=\"display: none;\">\n <td>\n <table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n <tr class=\"graphic-tab-lgray\">\n\t\t\t\t\t\t<td class=\"lp2\">\n\t\t\t\t\t\t\t<span class=\"lp\" dojoAttachPoint=\"entryTitleHeader\"></span>\n\t\t\t\t\t\t</td>\n </tr>\n <tr>\n <td dojoAttachPoint=\"entryTitleNode\">\n </td>\n </tr>\n </table>\n </td>\n </tr>\n\n <tr class=\"feedEntryViewerAuthor\" dojoAttachPoint=\"entryAuthorRow\" style=\"display: none;\">\n <td>\n <table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n <tr class=\"graphic-tab-lgray\">\n\t\t\t\t\t\t<td class=\"lp2\">\n\t\t\t\t\t\t\t<span class=\"lp\" dojoAttachPoint=\"entryAuthorHeader\"></span>\n\t\t\t\t\t\t</td>\n </tr>\n <tr>\n <td dojoAttachPoint=\"entryAuthorNode\">\n </td>\n </tr>\n </table>\n </td>\n </tr>\n\n <tr class=\"feedEntryViewerContributor\" dojoAttachPoint=\"entryContributorRow\" style=\"display: none;\">\n <td>\n <table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n <tr class=\"graphic-tab-lgray\">\n\t\t\t\t\t\t<td class=\"lp2\">\n\t\t\t\t\t\t\t<span class=\"lp\" dojoAttachPoint=\"entryContributorHeader\"></span>\n\t\t\t\t\t\t</td>\n </tr>\n <tr>\n <td dojoAttachPoint=\"entryContributorNode\" class=\"feedEntryViewerContributorNames\">\n </td>\n </tr>\n </table>\n </td>\n </tr>\n \n <tr class=\"feedEntryViewerId\" dojoAttachPoint=\"entryIdRow\" style=\"display: none;\">\n <td>\n <table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n <tr class=\"graphic-tab-lgray\">\n\t\t\t\t\t\t<td class=\"lp2\">\n\t\t\t\t\t\t\t<span class=\"lp\" dojoAttachPoint=\"entryIdHeader\"></span>\n\t\t\t\t\t\t</td>\n </tr>\n <tr>\n <td dojoAttachPoint=\"entryIdNode\" class=\"feedEntryViewerIdText\">\n </td>\n </tr>\n </table>\n </td>\n </tr>\n \n <tr class=\"feedEntryViewerUpdated\" dojoAttachPoint=\"entryUpdatedRow\" style=\"display: none;\">\n <td>\n <table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n <tr class=\"graphic-tab-lgray\">\n\t\t\t\t\t\t<td class=\"lp2\">\n\t\t\t\t\t\t\t<span class=\"lp\" dojoAttachPoint=\"entryUpdatedHeader\"></span>\n\t\t\t\t\t\t</td>\n </tr>\n <tr>\n <td dojoAttachPoint=\"entryUpdatedNode\" class=\"feedEntryViewerUpdatedText\">\n </td>\n </tr>\n </table>\n </td>\n </tr>\n \n <tr class=\"feedEntryViewerSummary\" dojoAttachPoint=\"entrySummaryRow\" style=\"display: none;\">\n <td>\n <table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n <tr class=\"graphic-tab-lgray\">\n\t\t\t\t\t\t<td class=\"lp2\">\n\t\t\t\t\t\t\t<span class=\"lp\" dojoAttachPoint=\"entrySummaryHeader\"></span>\n\t\t\t\t\t\t</td>\n </tr>\n <tr>\n <td dojoAttachPoint=\"entrySummaryNode\">\n </td>\n </tr>\n </table>\n </td>\n </tr>\n \n <tr class=\"feedEntryViewerContent\" dojoAttachPoint=\"entryContentRow\" style=\"display: none;\">\n <td>\n <table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n <tr class=\"graphic-tab-lgray\">\n\t\t\t\t\t\t<td class=\"lp2\">\n\t\t\t\t\t\t\t<span class=\"lp\" dojoAttachPoint=\"entryContentHeader\"></span>\n\t\t\t\t\t\t</td>\n </tr>\n <tr>\n <td dojoAttachPoint=\"entryContentNode\">\n </td>\n </tr>\n </table>\n </td>\n </tr>\n </table>\n</div>\n"}});4define("dojox/atom/widget/FeedEntryViewer", [5 "dojo/_base/kernel",6 "dojo/_base/connect",7 "dojo/_base/declare",8 "dojo/_base/fx",9 "dojo/_base/array",10 "dojo/dom-style",11 "dojo/dom-construct",12 "dijit/_Widget",13 "dijit/_Templated",14 "dijit/_Container",15 "dijit/layout/ContentPane",16 "../io/Connection",17 "dojo/text!./templates/FeedEntryViewer.html",18 "dojo/text!./templates/EntryHeader.html",19 "dojo/i18n!./nls/FeedEntryViewer"20], function (dojo, connect, declare, fx, arrayUtil, domStyle, domConstruct, _Widget, _Templated, _Container, ContentPane, Connection, template, headerTemplate, i18nViewer) {21dojo.experimental("dojox.atom.widget.FeedEntryViewer");22var FeedEntryViewer = declare("dojox.atom.widget.FeedEntryViewer", [_Widget, _Templated, _Container],{23 // summary:24 // An ATOM feed entry editor for publishing updated ATOM entries, or viewing non-editable entries.25 entrySelectionTopic: "", //The topic to listen on for entries to edit.26 _validEntryFields: {}, //The entry fields that were present on the entry and are being displayed.27 //This works in conjunction with what is selected to be displayed.28 displayEntrySections: "", //What current sections of the entries to display as a comma separated list.29 _displayEntrySections: null,30 31 //Control options for the display options menu.32 enableMenu: false,33 enableMenuFade: false,34 _optionButtonDisplayed: true,35 //Templates for the HTML rendering. Need to figure these out better, admittedly.36 templateString: template,37 38 _entry: null, //The entry that is being viewed/edited.39 _feed: null, //The feed the entry came from.40 _editMode: false, //Flag denoting the state of the widget, in edit mode or not.41 42 postCreate: function(){43 if(this.entrySelectionTopic !== ""){44 this._subscriptions = [dojo.subscribe(this.entrySelectionTopic, this, "_handleEvent")];45 }46 var _nlsResources = i18nViewer;47 this.displayOptions.innerHTML = _nlsResources.displayOptions;48 this.feedEntryCheckBoxLabelTitle.innerHTML = _nlsResources.title;49 this.feedEntryCheckBoxLabelAuthors.innerHTML = _nlsResources.authors;50 this.feedEntryCheckBoxLabelContributors.innerHTML = _nlsResources.contributors;51 this.feedEntryCheckBoxLabelId.innerHTML = _nlsResources.id;52 this.close.innerHTML = _nlsResources.close;53 this.feedEntryCheckBoxLabelUpdated.innerHTML = _nlsResources.updated;54 this.feedEntryCheckBoxLabelSummary.innerHTML = _nlsResources.summary;55 this.feedEntryCheckBoxLabelContent.innerHTML = _nlsResources.content;56 },57 startup: function(){58 if(this.displayEntrySections === ""){59 this._displayEntrySections = ["title","authors","contributors","summary","content","id","updated"];60 }else{61 this._displayEntrySections = this.displayEntrySections.split(",");62 }63 this._setDisplaySectionsCheckboxes();64 if(this.enableMenu){65 domStyle.set(this.feedEntryViewerMenu, 'display', '');66 if(this.entryCheckBoxRow && this.entryCheckBoxRow2){67 if(this.enableMenuFade){68 fx.fadeOut({node: this.entryCheckBoxRow,duration: 250}).play();69 fx.fadeOut({node: this.entryCheckBoxRow2,duration: 250}).play();70 }71 }72 }73 },74 clear: function(){75 // summary:76 // Function to clear the state of the widget.77 this.destroyDescendants();78 this._entry=null;79 this._feed=null;80 this.clearNodes();81 },82 83 clearNodes: function(){84 // summary:85 // Function to clear all the display nodes for the ATOM entry from the viewer.86 arrayUtil.forEach([87 "entryTitleRow", "entryAuthorRow", "entryContributorRow", "entrySummaryRow", "entryContentRow",88 "entryIdRow", "entryUpdatedRow"89 ], function(node){90 domStyle.set(this[node], "display", "none");91 }, this);92 arrayUtil.forEach([93 "entryTitleNode", "entryTitleHeader", "entryAuthorHeader", "entryContributorHeader",94 "entryContributorNode", "entrySummaryHeader", "entrySummaryNode", "entryContentHeader",95 "entryContentNode", "entryIdNode", "entryIdHeader", "entryUpdatedHeader", "entryUpdatedNode"96 ], function(part){97 while(this[part].firstChild){98 domConstruct.destroy(this[part].firstChild);99 }100 }101 ,this);102 103 },104 setEntry: function(/*object*/entry, /*object*/feed, /*boolean*/leaveMenuState){105 // summary:106 // Function to set the current entry that is being edited.107 // entry:108 // Instance of dojox.atom.io.model.Entry to display for reading/editing.109 this.clear();110 this._validEntryFields = {};111 this._entry = entry;112 this._feed = feed;113 if(entry !== null){114 // Handle the title.115 if(this.entryTitleHeader){116 this.setTitleHeader(this.entryTitleHeader, entry);117 }118 119 if(this.entryTitleNode){120 this.setTitle(this.entryTitleNode, this._editMode, entry);121 }122 if(this.entryAuthorHeader){123 this.setAuthorsHeader(this.entryAuthorHeader, entry);124 }125 if(this.entryAuthorNode){126 this.setAuthors(this.entryAuthorNode, this._editMode, entry);127 }128 129 if(this.entryContributorHeader){130 this.setContributorsHeader(this.entryContributorHeader, entry);131 }132 if(this.entryContributorNode){133 this.setContributors(this.entryContributorNode, this._editMode, entry);134 }135 if(this.entryIdHeader){136 this.setIdHeader(this.entryIdHeader, entry);137 }138 if(this.entryIdNode){139 this.setId(this.entryIdNode, this._editMode, entry);140 }141 if(this.entryUpdatedHeader){142 this.setUpdatedHeader(this.entryUpdatedHeader, entry);143 }144 if(this.entryUpdatedNode){145 this.setUpdated(this.entryUpdatedNode, this._editMode, entry);146 }147 if(this.entrySummaryHeader){148 this.setSummaryHeader(this.entrySummaryHeader, entry);149 }150 if(this.entrySummaryNode){151 this.setSummary(this.entrySummaryNode, this._editMode, entry);152 }153 if(this.entryContentHeader){154 this.setContentHeader(this.entryContentHeader, entry);155 }156 if(this.entryContentNode){157 this.setContent(this.entryContentNode, this._editMode, entry);158 }159 }160 this._displaySections();161 },162 setTitleHeader: function(/*DOMNode*/ titleHeaderNode, /*object*/entry){163 // summary:164 // Function to set the contents of the title header node in the template to some value.165 // description:166 // Function to set the contents of the title header node in the template to some value.167 // This exists specifically so users can over-ride how the title data is filled out from an entry.168 // titleAnchorNode:169 // The DOM node to attach the title data to.170 // editMode:171 // Boolean to indicate if the display should be in edit mode or not.172 // entry:173 // The Feed Entry to work with.174 if(entry.title && entry.title.value && entry.title.value !== null){175 var _nlsResources = i18nViewer;176 var titleHeader = new EntryHeader({title: _nlsResources.title});177 titleHeaderNode.appendChild(titleHeader.domNode);178 }179 },180 setTitle: function(titleAnchorNode, editMode, entry){181 // summary:182 // Function to set the contents of the title node in the template to some value from the entry.183 // description:184 // Function to set the contents of the title node in the template to some value from the entry.185 // This exists specifically so users can over-ride how the title data is filled out from an entry.186 // titleAnchorNode:187 // The DOM node to attach the title data to.188 // editMode:189 // Boolean to indicate if the display should be in edit mode or not.190 // entry:191 // The Feed Entry to work with.192 if(entry.title && entry.title.value && entry.title.value !== null){193 if(entry.title.type == "text"){194 var titleNode = document.createTextNode(entry.title.value);195 titleAnchorNode.appendChild(titleNode);196 }else{197 var titleViewNode = document.createElement("span");198 var titleView = new ContentPane({refreshOnShow: true, executeScripts: false}, titleViewNode);199 titleView.attr('content', entry.title.value);200 titleAnchorNode.appendChild(titleView.domNode);201 }202 this.setFieldValidity("title", true);203 }204 },205 setAuthorsHeader: function(/*DOMNode*/ authorHeaderNode, /*object*/entry){206 // summary:207 // Function to set the title format for the authors section of the author row in the template to some value from the entry.208 // description:209 // Function to set the title format for the authors section of the author row in the template to some value from the entry.210 // This exists specifically so users can over-ride how the author data is filled out from an entry.211 // authorHeaderNode:212 // The DOM node to attach the author section header data to.213 // entry:214 // The Feed Entry to work with.215 if(entry.authors && entry.authors.length > 0){216 var _nlsResources = i18nViewer;217 var authorHeader = new EntryHeader({title: _nlsResources.authors});218 authorHeaderNode.appendChild(authorHeader.domNode);219 }220 },221 setAuthors: function(/*DOMNode*/ authorsAnchorNode, /*boolean*/editMode, /*object*/entry){222 // summary:223 // Function to set the contents of the author node in the template to some value from the entry.224 // description:225 // Function to set the contents of the author node in the template to some value from the entry.226 // This exists specifically so users can over-ride how the title data is filled out from an entry.227 // authorsAnchorNode:228 // The DOM node to attach the author data to.229 // editMode:230 // Boolean to indicate if the display should be in edit mode or not.231 // entry:232 // The Feed Entry to work with.233 authorsAnchorNode.innerHTML = "";234 if(entry.authors && entry.authors.length > 0){235 for(var i in entry.authors){236 if(entry.authors[i].name){237 var anchor = authorsAnchorNode;238 if(entry.authors[i].uri){239 var link = document.createElement("a");240 anchor.appendChild(link);241 link.href = entry.authors[i].uri;242 anchor = link;243 }244 var name = entry.authors[i].name;245 if(entry.authors[i].email){246 name = name + " (" + entry.authors[i].email + ")";247 }248 var authorNode = document.createTextNode(name);249 anchor.appendChild(authorNode);250 var breakNode = document.createElement("br");251 authorsAnchorNode.appendChild(breakNode);252 this.setFieldValidity("authors", true);253 }254 }255 }256 },257 setContributorsHeader: function(/*DOMNode*/ contributorsHeaderNode, /*object*/entry){258 // summary:259 // Function to set the contents of the contributor header node in the template to some value from the entry.260 // description:261 // Function to set the contents of the contributor header node in the template to some value from the entry.262 // This exists specifically so users can over-ride how the title data is filled out from an entry.263 // contributorsHeaderNode:264 // The DOM node to attach the contributor title to.265 // entry:266 // The Feed Entry to work with.267 if(entry.contributors && entry.contributors.length > 0){268 var _nlsResources = i18nViewer;269 var contributorHeader = new EntryHeader({title: _nlsResources.contributors});270 contributorsHeaderNode.appendChild(contributorHeader.domNode);271 }272 },273 setContributors: function(/*DOMNode*/ contributorsAnchorNode, /*boolean*/editMode, /*object*/entry){274 // summary:275 // Function to set the contents of the contributor node in the template to some value from the entry.276 // description:277 // Function to set the contents of the contributor node in the template to some value from the entry.278 // This exists specifically so users can over-ride how the title data is filled out from an entry.279 // contributorsAnchorNode:280 // The DOM node to attach the contributor data to.281 // editMode:282 // Boolean to indicate if the display should be in edit mode or not.283 // entry:284 // The Feed Entry to work with.285 if(entry.contributors && entry.contributors.length > 0){286 for(var i in entry.contributors){287 var contributorNode = document.createTextNode(entry.contributors[i].name);288 contributorsAnchorNode.appendChild(contributorNode);289 var breakNode = document.createElement("br");290 contributorsAnchorNode.appendChild(breakNode);291 this.setFieldValidity("contributors", true);292 }293 }294 },295 296 setIdHeader: function(/*DOMNode*/ idHeaderNode, /*object*/entry){297 // summary:298 // Function to set the contents of the ID node in the template to some value from the entry.299 // description:300 // Function to set the contents of the ID node in the template to some value from the entry.301 // This exists specifically so users can over-ride how the title data is filled out from an entry.302 // idAnchorNode:303 // The DOM node to attach the ID data to.304 // entry:305 // The Feed Entry to work with.306 if(entry.id && entry.id !== null){307 var _nlsResources = i18nViewer;308 var idHeader = new EntryHeader({title: _nlsResources.id});309 idHeaderNode.appendChild(idHeader.domNode);310 }311 },312 setId: function(/*DOMNode*/ idAnchorNode, /*boolean*/editMode, /*object*/entry){313 // summary:314 // Function to set the contents of the ID node in the template to some value from the entry.315 // description:316 // Function to set the contents of the ID node in the template to some value from the entry.317 // This exists specifically so users can over-ride how the title data is filled out from an entry.318 // idAnchorNode:319 // The DOM node to attach the ID data to.320 // editMode:321 // Boolean to indicate if the display should be in edit mode or not.322 // entry:323 // The Feed Entry to work with.324 if(entry.id && entry.id !== null){325 var idNode = document.createTextNode(entry.id);326 idAnchorNode.appendChild(idNode);327 this.setFieldValidity("id", true);328 }329 },330 331 setUpdatedHeader: function(/*DOMNode*/ updatedHeaderNode, /*object*/entry){332 // summary:333 // Function to set the contents of the updated header node in the template to some value from the entry.334 // description:335 // Function to set the contents of the updated header node in the template to some value from the entry.336 // This exists specifically so users can over-ride how the title data is filled out from an entry.337 // updatedHeaderNode:338 // The DOM node to attach the updated header data to.339 // entry:340 // The Feed Entry to work with.341 if(entry.updated && entry.updated !== null){342 var _nlsResources = i18nViewer;343 var updatedHeader = new EntryHeader({title: _nlsResources.updated});344 updatedHeaderNode.appendChild(updatedHeader.domNode);345 }346 },347 setUpdated: function(/*DOMNode*/ updatedAnchorNode, /*boolean*/editMode, /*object*/entry){348 // summary:349 // Function to set the contents of the updated node in the template to some value from the entry.350 // description:351 // Function to set the contents of the updated node in the template to some value from the entry.352 // This exists specifically so users can over-ride how the title data is filled out from an entry.353 // updatedAnchorNode:354 // The DOM node to attach the udpated data to.355 // editMode:356 // Boolean to indicate if the display should be in edit mode or not.357 // entry:358 // The Feed Entry to work with.359 if(entry.updated && entry.updated !== null){360 var updatedNode = document.createTextNode(entry.updated);361 updatedAnchorNode.appendChild(updatedNode);362 this.setFieldValidity("updated", true);363 }364 },365 setSummaryHeader: function(/*DOMNode*/ summaryHeaderNode, /*object*/entry){366 // summary:367 // Function to set the contents of the summary node in the template to some value from the entry.368 // description:369 // Function to set the contents of the summary node in the template to some value from the entry.370 // This exists specifically so users can over-ride how the title data is filled out from an entry.371 // summaryHeaderNode:372 // The DOM node to attach the summary title to.373 // entry:374 // The Feed Entry to work with.375 if(entry.summary && entry.summary.value && entry.summary.value !== null){376 var _nlsResources = i18nViewer;377 var summaryHeader = new EntryHeader({title: _nlsResources.summary});378 summaryHeaderNode.appendChild(summaryHeader.domNode);379 }380 },381 setSummary: function(/*DOMNode*/ summaryAnchorNode, /*boolean*/editMode, /*object*/entry){382 // summary:383 // Function to set the contents of the summary node in the template to some value from the entry.384 // description:385 // Function to set the contents of the summary node in the template to some value from the entry.386 // This exists specifically so users can over-ride how the title data is filled out from an entry.387 // summaryAnchorNode:388 // The DOM node to attach the summary data to.389 // editMode:390 // Boolean to indicate if the display should be in edit mode or not.391 // entry:392 // The Feed Entry to work with.393 if(entry.summary && entry.summary.value && entry.summary.value !== null){394 var summaryViewNode = document.createElement("span");395 var summaryView = new ContentPane({refreshOnShow: true, executeScripts: false}, summaryViewNode);396 summaryView.attr('content', entry.summary.value);397 summaryAnchorNode.appendChild(summaryView.domNode);398 this.setFieldValidity("summary", true);399 }400 },401 setContentHeader: function(/*DOMNode*/ contentHeaderNode, /*object*/entry){402 // summary:403 // Function to set the contents of the content node in the template to some value from the entry.404 // description:405 // Function to set the contents of the content node in the template to some value from the entry.406 // This exists specifically so users can over-ride how the title data is filled out from an entry.407 // contentHeaderNode:408 // The DOM node to attach the content data to.409 // entry:410 // The Feed Entry to work with.411 if(entry.content && entry.content.value && entry.content.value !== null){412 var _nlsResources = i18nViewer;413 var contentHeader = new EntryHeader({title: _nlsResources.content});414 contentHeaderNode.appendChild(contentHeader.domNode);415 }416 },417 setContent: function(/*DOMNode*/ contentAnchorNode, /*boolean*/editMode, /*object*/entry){418 // summary:419 // Function to set the contents of the content node in the template to some value from the entry.420 // description:421 // Function to set the contents of the content node in the template to some value from the entry.422 // This exists specifically so users can over-ride how the title data is filled out from an entry.423 // contentAnchorNode:424 // The DOM node to attach the content data to.425 // editMode:426 // Boolean to indicate if the display should be in edit mode or not.427 // entry:428 // The Feed Entry to work with.429 if(entry.content && entry.content.value && entry.content.value !== null){430 var contentViewNode = document.createElement("span");431 var contentView = new ContentPane({refreshOnShow: true, executeScripts: false},contentViewNode);432 contentView.attr('content', entry.content.value);433 contentAnchorNode.appendChild(contentView.domNode);434 this.setFieldValidity("content", true);435 }436 },437 _displaySections: function(){438 // summary:439 // Internal function for determining which sections of the view to actually display.440 // returns:441 // Nothing.442 domStyle.set(this.entryTitleRow, 'display', 'none');443 domStyle.set(this.entryAuthorRow, 'display', 'none');444 domStyle.set(this.entryContributorRow, 'display', 'none');445 domStyle.set(this.entrySummaryRow, 'display', 'none');446 domStyle.set(this.entryContentRow, 'display', 'none');447 domStyle.set(this.entryIdRow, 'display', 'none');448 domStyle.set(this.entryUpdatedRow, 'display', 'none');449 for(var i in this._displayEntrySections){450 var section = this._displayEntrySections[i].toLowerCase();451 if(section === "title" && this.isFieldValid("title")){452 domStyle.set(this.entryTitleRow, 'display', '');453 }454 if(section === "authors" && this.isFieldValid("authors")){455 domStyle.set(this.entryAuthorRow, 'display', '');456 }457 if(section === "contributors" && this.isFieldValid("contributors")){458 domStyle.set(this.entryContributorRow, 'display', '');459 }460 if(section === "summary" && this.isFieldValid("summary")){461 domStyle.set(this.entrySummaryRow, 'display', '');462 }463 if(section === "content" && this.isFieldValid("content")){464 domStyle.set(this.entryContentRow, 'display', '');465 }466 if(section === "id" && this.isFieldValid("id")){467 domStyle.set(this.entryIdRow, 'display', '');468 }469 if(section === "updated" && this.isFieldValid("updated")){470 domStyle.set(this.entryUpdatedRow, 'display', '');471 }472 }473 },474 setDisplaySections: function(/*array*/sectionsArray){475 // summary:476 // Function for setting which sections of the entry should be displayed.477 // sectionsArray:478 // Array of string names that indicate which sections to display.479 // returns:480 // Nothing.481 if(sectionsArray !== null){482 this._displayEntrySections = sectionsArray;483 this._displaySections();484 }else{485 this._displayEntrySections = ["title","authors","contributors","summary","content","id","updated"];486 }487 },488 _setDisplaySectionsCheckboxes: function(){489 // summary:490 // Internal function for setting which checkboxes on the display are selected.491 // returns:492 // Nothing.493 var items = ["title","authors","contributors","summary","content","id","updated"];494 for(var i in items){495 if(arrayUtil.indexOf(this._displayEntrySections, items[i]) == -1){496 domStyle.set(this["feedEntryCell"+items[i]], 'display', 'none');497 }else{498 this["feedEntryCheckBox"+items[i].substring(0,1).toUpperCase()+items[i].substring(1)].checked=true;499 }500 }501 },502 _readDisplaySections: function(){503 // summary:504 // Internal function for reading what is currently checked for display and generating the display list from it.505 var checkedList = [];506 if(this.feedEntryCheckBoxTitle.checked){507 checkedList.push("title");508 }509 if(this.feedEntryCheckBoxAuthors.checked){510 checkedList.push("authors");511 }512 if(this.feedEntryCheckBoxContributors.checked){513 checkedList.push("contributors");514 }515 if(this.feedEntryCheckBoxSummary.checked){516 checkedList.push("summary");517 }518 if(this.feedEntryCheckBoxContent.checked){519 checkedList.push("content");520 }521 if(this.feedEntryCheckBoxId.checked){522 checkedList.push("id");523 }524 if(this.feedEntryCheckBoxUpdated.checked){525 checkedList.push("updated");526 }527 this._displayEntrySections = checkedList;528 },529 _toggleCheckbox: function(/*object*/checkBox){530 // summary:531 // Internal function for determining of a particular entry is editable.532 // description:533 // Internal function for determining of a particular entry is editable.534 // This is used for determining if the delete action should be displayed or not.535 // checkBox:536 // The checkbox object to toggle the selection on.537 if(checkBox.checked){538 checkBox.checked=false;539 }else{540 checkBox.checked=true;541 }542 this._readDisplaySections();543 this._displaySections();544 },545 _toggleOptions: function(/*object*/checkBox){546 // summary:547 // Internal function for determining of a particular entry is editable.548 // description:549 // Internal function for determining of a particular entry is editable.550 // This is used for determining if the delete action should be displayed or not.551 // checkBox:552 // The checkbox object to toggle the selection on.553 if(this.enableMenu){554 var fade = null;555 var anim;556 var anim2;557 if(this._optionButtonDisplayed){558 if(this.enableMenuFade){559 anim = fx.fadeOut({node: this.entryCheckBoxDisplayOptions,duration: 250});560 connect.connect(anim, "onEnd", this, function(){561 domStyle.set(this.entryCheckBoxDisplayOptions, 'display', 'none');562 domStyle.set(this.entryCheckBoxRow, 'display', '');563 domStyle.set(this.entryCheckBoxRow2, 'display', '');564 fx.fadeIn({node: this.entryCheckBoxRow, duration: 250}).play();565 fx.fadeIn({node: this.entryCheckBoxRow2, duration: 250}).play();566 });567 anim.play();568 }else{569 domStyle.set(this.entryCheckBoxDisplayOptions, 'display', 'none');570 domStyle.set(this.entryCheckBoxRow, 'display', '');571 domStyle.set(this.entryCheckBoxRow2, 'display', '');572 }573 this._optionButtonDisplayed=false;574 }else{575 if(this.enableMenuFade){576 anim = fx.fadeOut({node: this.entryCheckBoxRow,duration: 250});577 anim2 = fx.fadeOut({node: this.entryCheckBoxRow2,duration: 250});578 connect.connect(anim, "onEnd", this, function(){579 domStyle.set(this.entryCheckBoxRow, 'display', 'none');580 domStyle.set(this.entryCheckBoxRow2, 'display', 'none');581 domStyle.set(this.entryCheckBoxDisplayOptions, 'display', '');582 fx.fadeIn({node: this.entryCheckBoxDisplayOptions, duration: 250}).play();583 });584 anim.play();585 anim2.play();586 }else{587 domStyle.set(this.entryCheckBoxRow, 'display', 'none');588 domStyle.set(this.entryCheckBoxRow2, 'display', 'none');589 domStyle.set(this.entryCheckBoxDisplayOptions, 'display', '');590 }591 this._optionButtonDisplayed=true;592 }593 }594 },595 _handleEvent: function(/*object*/entrySelectionEvent){596 // summary:597 // Internal function for listening to a topic that will handle entry notification.598 // entrySelectionEvent:599 // The topic message containing the entry that was selected for view.600 // returns:601 // Nothing.602 if(entrySelectionEvent.source != this){603 if(entrySelectionEvent.action == "set" && entrySelectionEvent.entry){604 this.setEntry(entrySelectionEvent.entry, entrySelectionEvent.feed);605 }else if(entrySelectionEvent.action == "delete" && entrySelectionEvent.entry && entrySelectionEvent.entry == this._entry){606 this.clear();607 }608 }609 },610 setFieldValidity: function(/*string*/field, /*boolean*/isValid){611 // summary:612 // Function to set whether a field in the view is valid and displayable.613 // description:614 // Function to set whether a field in the view is valid and displayable.615 // This is needed for over-riding of the set* functions and customization of how data is displayed in the attach point.616 // So if custom implementations use their own display logic, they can still enable the field.617 // field:618 // The field name to set the valid parameter on. Such as 'content', 'id', etc.619 // isValid:620 // Flag denoting if the field is valid or not.621 // returns:622 // Nothing.623 if(field){624 var lowerField = field.toLowerCase();625 this._validEntryFields[field] = isValid;626 }627 },628 629 isFieldValid: function(/*string*/field){630 // summary:631 // Function to return if a displayable field is valid or not632 // field:633 // The field name to get the valid parameter of. Such as 'content', 'id', etc.634 // returns:635 // boolean denoting if the field is valid and set.636 return this._validEntryFields[field.toLowerCase()];637 },638 getEntry: function(){639 return this._entry;640 },641 getFeed: function(){642 return this._feed;643 },644 destroy: function(){645 this.clear();646 arrayUtil.forEach(this._subscriptions, dojo.unsubscribe);647 }648});649var EntryHeader = FeedEntryViewer.EntryHeader = declare("dojox.atom.widget.EntryHeader", [_Widget, _Templated, _Container],{650 // summary:651 // Widget representing a header in a FeedEntryViewer/Editor652 title: "",653 templateString: headerTemplate,654 postCreate: function(){655 this.setListHeader();656 },657 setListHeader: function(/*string*/title){658 this.clear();659 if(title){660 this.title = title;661 }662 var textNode = document.createTextNode(this.title);663 this.entryHeaderNode.appendChild(textNode);664 },665 clear: function(){666 this.destroyDescendants();667 if(this.entryHeaderNode){668 for(var i = 0; i < this.entryHeaderNode.childNodes.length; i++){669 this.entryHeaderNode.removeChild(this.entryHeaderNode.childNodes[i]);670 }671 }672 },673 destroy: function(){674 this.clear();675 }676});677return FeedEntryViewer;...

Full Screen

Full Screen

FeedEntryViewer.js

Source:FeedEntryViewer.js Github

copy

Full Screen

1define([2 "dojo/_base/kernel",3 "dojo/_base/connect",4 "dojo/_base/declare",5 "dojo/_base/fx",6 "dojo/_base/array",7 "dojo/dom-style",8 "dojo/dom-construct",9 "dijit/_Widget",10 "dijit/_Templated",11 "dijit/_Container",12 "dijit/layout/ContentPane",13 "../io/Connection",14 "dojo/text!./templates/FeedEntryViewer.html",15 "dojo/text!./templates/EntryHeader.html",16 "dojo/i18n!./nls/FeedEntryViewer"17], function (dojo, connect, declare, fx, arrayUtil, domStyle, domConstruct, _Widget, _Templated, _Container, ContentPane, Connection, template, headerTemplate, i18nViewer) {18dojo.experimental("dojox.atom.widget.FeedEntryViewer");19var FeedEntryViewer = declare("dojox.atom.widget.FeedEntryViewer", [_Widget, _Templated, _Container],{20 // summary:21 // An ATOM feed entry editor for publishing updated ATOM entries, or viewing non-editable entries.22 entrySelectionTopic: "", //The topic to listen on for entries to edit.23 _validEntryFields: {}, //The entry fields that were present on the entry and are being displayed.24 //This works in conjunction with what is selected to be displayed.25 displayEntrySections: "", //What current sections of the entries to display as a comma separated list.26 _displayEntrySections: null,27 28 //Control options for the display options menu.29 enableMenu: false,30 enableMenuFade: false,31 _optionButtonDisplayed: true,32 //Templates for the HTML rendering. Need to figure these out better, admittedly.33 templateString: template,34 35 _entry: null, //The entry that is being viewed/edited.36 _feed: null, //The feed the entry came from.37 _editMode: false, //Flag denoting the state of the widget, in edit mode or not.38 39 postCreate: function(){40 if(this.entrySelectionTopic !== ""){41 this._subscriptions = [dojo.subscribe(this.entrySelectionTopic, this, "_handleEvent")];42 }43 var _nlsResources = i18nViewer;44 this.displayOptions.innerHTML = _nlsResources.displayOptions;45 this.feedEntryCheckBoxLabelTitle.innerHTML = _nlsResources.title;46 this.feedEntryCheckBoxLabelAuthors.innerHTML = _nlsResources.authors;47 this.feedEntryCheckBoxLabelContributors.innerHTML = _nlsResources.contributors;48 this.feedEntryCheckBoxLabelId.innerHTML = _nlsResources.id;49 this.close.innerHTML = _nlsResources.close;50 this.feedEntryCheckBoxLabelUpdated.innerHTML = _nlsResources.updated;51 this.feedEntryCheckBoxLabelSummary.innerHTML = _nlsResources.summary;52 this.feedEntryCheckBoxLabelContent.innerHTML = _nlsResources.content;53 },54 startup: function(){55 if(this.displayEntrySections === ""){56 this._displayEntrySections = ["title","authors","contributors","summary","content","id","updated"];57 }else{58 this._displayEntrySections = this.displayEntrySections.split(",");59 }60 this._setDisplaySectionsCheckboxes();61 if(this.enableMenu){62 domStyle.set(this.feedEntryViewerMenu, 'display', '');63 if(this.entryCheckBoxRow && this.entryCheckBoxRow2){64 if(this.enableMenuFade){65 fx.fadeOut({node: this.entryCheckBoxRow,duration: 250}).play();66 fx.fadeOut({node: this.entryCheckBoxRow2,duration: 250}).play();67 }68 }69 }70 },71 clear: function(){72 // summary:73 // Function to clear the state of the widget.74 this.destroyDescendants();75 this._entry=null;76 this._feed=null;77 this.clearNodes();78 },79 80 clearNodes: function(){81 // summary:82 // Function to clear all the display nodes for the ATOM entry from the viewer.83 arrayUtil.forEach([84 "entryTitleRow", "entryAuthorRow", "entryContributorRow", "entrySummaryRow", "entryContentRow",85 "entryIdRow", "entryUpdatedRow"86 ], function(node){87 domStyle.set(this[node], "display", "none");88 }, this);89 arrayUtil.forEach([90 "entryTitleNode", "entryTitleHeader", "entryAuthorHeader", "entryContributorHeader",91 "entryContributorNode", "entrySummaryHeader", "entrySummaryNode", "entryContentHeader",92 "entryContentNode", "entryIdNode", "entryIdHeader", "entryUpdatedHeader", "entryUpdatedNode"93 ], function(part){94 while(this[part].firstChild){95 domConstruct.destroy(this[part].firstChild);96 }97 }98 ,this);99 100 },101 setEntry: function(/*object*/entry, /*object*/feed, /*boolean*/leaveMenuState){102 // summary:103 // Function to set the current entry that is being edited.104 // entry:105 // Instance of dojox.atom.io.model.Entry to display for reading/editing.106 this.clear();107 this._validEntryFields = {};108 this._entry = entry;109 this._feed = feed;110 if(entry !== null){111 // Handle the title.112 if(this.entryTitleHeader){113 this.setTitleHeader(this.entryTitleHeader, entry);114 }115 116 if(this.entryTitleNode){117 this.setTitle(this.entryTitleNode, this._editMode, entry);118 }119 if(this.entryAuthorHeader){120 this.setAuthorsHeader(this.entryAuthorHeader, entry);121 }122 if(this.entryAuthorNode){123 this.setAuthors(this.entryAuthorNode, this._editMode, entry);124 }125 126 if(this.entryContributorHeader){127 this.setContributorsHeader(this.entryContributorHeader, entry);128 }129 if(this.entryContributorNode){130 this.setContributors(this.entryContributorNode, this._editMode, entry);131 }132 if(this.entryIdHeader){133 this.setIdHeader(this.entryIdHeader, entry);134 }135 if(this.entryIdNode){136 this.setId(this.entryIdNode, this._editMode, entry);137 }138 if(this.entryUpdatedHeader){139 this.setUpdatedHeader(this.entryUpdatedHeader, entry);140 }141 if(this.entryUpdatedNode){142 this.setUpdated(this.entryUpdatedNode, this._editMode, entry);143 }144 if(this.entrySummaryHeader){145 this.setSummaryHeader(this.entrySummaryHeader, entry);146 }147 if(this.entrySummaryNode){148 this.setSummary(this.entrySummaryNode, this._editMode, entry);149 }150 if(this.entryContentHeader){151 this.setContentHeader(this.entryContentHeader, entry);152 }153 if(this.entryContentNode){154 this.setContent(this.entryContentNode, this._editMode, entry);155 }156 }157 this._displaySections();158 },159 setTitleHeader: function(/*DOMNode*/ titleHeaderNode, /*object*/entry){160 // summary:161 // Function to set the contents of the title header node in the template to some value.162 // description:163 // Function to set the contents of the title header node in the template to some value.164 // This exists specifically so users can over-ride how the title data is filled out from an entry.165 // titleAnchorNode:166 // The DOM node to attach the title data to.167 // editMode:168 // Boolean to indicate if the display should be in edit mode or not.169 // entry:170 // The Feed Entry to work with.171 if(entry.title && entry.title.value && entry.title.value !== null){172 var _nlsResources = i18nViewer;173 var titleHeader = new EntryHeader({title: _nlsResources.title});174 titleHeaderNode.appendChild(titleHeader.domNode);175 }176 },177 setTitle: function(titleAnchorNode, editMode, entry){178 // summary:179 // Function to set the contents of the title node in the template to some value from the entry.180 // description:181 // Function to set the contents of the title node in the template to some value from the entry.182 // This exists specifically so users can over-ride how the title data is filled out from an entry.183 // titleAnchorNode:184 // The DOM node to attach the title data to.185 // editMode:186 // Boolean to indicate if the display should be in edit mode or not.187 // entry:188 // The Feed Entry to work with.189 if(entry.title && entry.title.value && entry.title.value !== null){190 if(entry.title.type == "text"){191 var titleNode = document.createTextNode(entry.title.value);192 titleAnchorNode.appendChild(titleNode);193 }else{194 var titleViewNode = document.createElement("span");195 var titleView = new ContentPane({refreshOnShow: true, executeScripts: false}, titleViewNode);196 titleView.attr('content', entry.title.value);197 titleAnchorNode.appendChild(titleView.domNode);198 }199 this.setFieldValidity("title", true);200 }201 },202 setAuthorsHeader: function(/*DOMNode*/ authorHeaderNode, /*object*/entry){203 // summary:204 // Function to set the title format for the authors section of the author row in the template to some value from the entry.205 // description:206 // Function to set the title format for the authors section of the author row in the template to some value from the entry.207 // This exists specifically so users can over-ride how the author data is filled out from an entry.208 // authorHeaderNode:209 // The DOM node to attach the author section header data to.210 // entry:211 // The Feed Entry to work with.212 if(entry.authors && entry.authors.length > 0){213 var _nlsResources = i18nViewer;214 var authorHeader = new EntryHeader({title: _nlsResources.authors});215 authorHeaderNode.appendChild(authorHeader.domNode);216 }217 },218 setAuthors: function(/*DOMNode*/ authorsAnchorNode, /*boolean*/editMode, /*object*/entry){219 // summary:220 // Function to set the contents of the author node in the template to some value from the entry.221 // description:222 // Function to set the contents of the author node in the template to some value from the entry.223 // This exists specifically so users can over-ride how the title data is filled out from an entry.224 // authorsAnchorNode:225 // The DOM node to attach the author data to.226 // editMode:227 // Boolean to indicate if the display should be in edit mode or not.228 // entry:229 // The Feed Entry to work with.230 authorsAnchorNode.innerHTML = "";231 if(entry.authors && entry.authors.length > 0){232 for(var i in entry.authors){233 if(entry.authors[i].name){234 var anchor = authorsAnchorNode;235 if(entry.authors[i].uri){236 var link = document.createElement("a");237 anchor.appendChild(link);238 link.href = entry.authors[i].uri;239 anchor = link;240 }241 var name = entry.authors[i].name;242 if(entry.authors[i].email){243 name = name + " (" + entry.authors[i].email + ")";244 }245 var authorNode = document.createTextNode(name);246 anchor.appendChild(authorNode);247 var breakNode = document.createElement("br");248 authorsAnchorNode.appendChild(breakNode);249 this.setFieldValidity("authors", true);250 }251 }252 }253 },254 setContributorsHeader: function(/*DOMNode*/ contributorsHeaderNode, /*object*/entry){255 // summary:256 // Function to set the contents of the contributor header node in the template to some value from the entry.257 // description:258 // Function to set the contents of the contributor header node in the template to some value from the entry.259 // This exists specifically so users can over-ride how the title data is filled out from an entry.260 // contributorsHeaderNode:261 // The DOM node to attach the contributor title to.262 // entry:263 // The Feed Entry to work with.264 if(entry.contributors && entry.contributors.length > 0){265 var _nlsResources = i18nViewer;266 var contributorHeader = new EntryHeader({title: _nlsResources.contributors});267 contributorsHeaderNode.appendChild(contributorHeader.domNode);268 }269 },270 setContributors: function(/*DOMNode*/ contributorsAnchorNode, /*boolean*/editMode, /*object*/entry){271 // summary:272 // Function to set the contents of the contributor node in the template to some value from the entry.273 // description:274 // Function to set the contents of the contributor node in the template to some value from the entry.275 // This exists specifically so users can over-ride how the title data is filled out from an entry.276 // contributorsAnchorNode:277 // The DOM node to attach the contributor data to.278 // editMode:279 // Boolean to indicate if the display should be in edit mode or not.280 // entry:281 // The Feed Entry to work with.282 if(entry.contributors && entry.contributors.length > 0){283 for(var i in entry.contributors){284 var contributorNode = document.createTextNode(entry.contributors[i].name);285 contributorsAnchorNode.appendChild(contributorNode);286 var breakNode = document.createElement("br");287 contributorsAnchorNode.appendChild(breakNode);288 this.setFieldValidity("contributors", true);289 }290 }291 },292 293 setIdHeader: function(/*DOMNode*/ idHeaderNode, /*object*/entry){294 // summary:295 // Function to set the contents of the ID node in the template to some value from the entry.296 // description:297 // Function to set the contents of the ID node in the template to some value from the entry.298 // This exists specifically so users can over-ride how the title data is filled out from an entry.299 // idAnchorNode:300 // The DOM node to attach the ID data to.301 // entry:302 // The Feed Entry to work with.303 if(entry.id && entry.id !== null){304 var _nlsResources = i18nViewer;305 var idHeader = new EntryHeader({title: _nlsResources.id});306 idHeaderNode.appendChild(idHeader.domNode);307 }308 },309 setId: function(/*DOMNode*/ idAnchorNode, /*boolean*/editMode, /*object*/entry){310 // summary:311 // Function to set the contents of the ID node in the template to some value from the entry.312 // description:313 // Function to set the contents of the ID node in the template to some value from the entry.314 // This exists specifically so users can over-ride how the title data is filled out from an entry.315 // idAnchorNode:316 // The DOM node to attach the ID data to.317 // editMode:318 // Boolean to indicate if the display should be in edit mode or not.319 // entry:320 // The Feed Entry to work with.321 if(entry.id && entry.id !== null){322 var idNode = document.createTextNode(entry.id);323 idAnchorNode.appendChild(idNode);324 this.setFieldValidity("id", true);325 }326 },327 328 setUpdatedHeader: function(/*DOMNode*/ updatedHeaderNode, /*object*/entry){329 // summary:330 // Function to set the contents of the updated header node in the template to some value from the entry.331 // description:332 // Function to set the contents of the updated header node in the template to some value from the entry.333 // This exists specifically so users can over-ride how the title data is filled out from an entry.334 // updatedHeaderNode:335 // The DOM node to attach the updated header data to.336 // entry:337 // The Feed Entry to work with.338 if(entry.updated && entry.updated !== null){339 var _nlsResources = i18nViewer;340 var updatedHeader = new EntryHeader({title: _nlsResources.updated});341 updatedHeaderNode.appendChild(updatedHeader.domNode);342 }343 },344 setUpdated: function(/*DOMNode*/ updatedAnchorNode, /*boolean*/editMode, /*object*/entry){345 // summary:346 // Function to set the contents of the updated node in the template to some value from the entry.347 // description:348 // Function to set the contents of the updated node in the template to some value from the entry.349 // This exists specifically so users can over-ride how the title data is filled out from an entry.350 // updatedAnchorNode:351 // The DOM node to attach the udpated data to.352 // editMode:353 // Boolean to indicate if the display should be in edit mode or not.354 // entry:355 // The Feed Entry to work with.356 if(entry.updated && entry.updated !== null){357 var updatedNode = document.createTextNode(entry.updated);358 updatedAnchorNode.appendChild(updatedNode);359 this.setFieldValidity("updated", true);360 }361 },362 setSummaryHeader: function(/*DOMNode*/ summaryHeaderNode, /*object*/entry){363 // summary:364 // Function to set the contents of the summary node in the template to some value from the entry.365 // description:366 // Function to set the contents of the summary node in the template to some value from the entry.367 // This exists specifically so users can over-ride how the title data is filled out from an entry.368 // summaryHeaderNode:369 // The DOM node to attach the summary title to.370 // entry:371 // The Feed Entry to work with.372 if(entry.summary && entry.summary.value && entry.summary.value !== null){373 var _nlsResources = i18nViewer;374 var summaryHeader = new EntryHeader({title: _nlsResources.summary});375 summaryHeaderNode.appendChild(summaryHeader.domNode);376 }377 },378 setSummary: function(/*DOMNode*/ summaryAnchorNode, /*boolean*/editMode, /*object*/entry){379 // summary:380 // Function to set the contents of the summary node in the template to some value from the entry.381 // description:382 // Function to set the contents of the summary node in the template to some value from the entry.383 // This exists specifically so users can over-ride how the title data is filled out from an entry.384 // summaryAnchorNode:385 // The DOM node to attach the summary data to.386 // editMode:387 // Boolean to indicate if the display should be in edit mode or not.388 // entry:389 // The Feed Entry to work with.390 if(entry.summary && entry.summary.value && entry.summary.value !== null){391 var summaryViewNode = document.createElement("span");392 var summaryView = new ContentPane({refreshOnShow: true, executeScripts: false}, summaryViewNode);393 summaryView.attr('content', entry.summary.value);394 summaryAnchorNode.appendChild(summaryView.domNode);395 this.setFieldValidity("summary", true);396 }397 },398 setContentHeader: function(/*DOMNode*/ contentHeaderNode, /*object*/entry){399 // summary:400 // Function to set the contents of the content node in the template to some value from the entry.401 // description:402 // Function to set the contents of the content node in the template to some value from the entry.403 // This exists specifically so users can over-ride how the title data is filled out from an entry.404 // contentHeaderNode:405 // The DOM node to attach the content data to.406 // entry:407 // The Feed Entry to work with.408 if(entry.content && entry.content.value && entry.content.value !== null){409 var _nlsResources = i18nViewer;410 var contentHeader = new EntryHeader({title: _nlsResources.content});411 contentHeaderNode.appendChild(contentHeader.domNode);412 }413 },414 setContent: function(/*DOMNode*/ contentAnchorNode, /*boolean*/editMode, /*object*/entry){415 // summary:416 // Function to set the contents of the content node in the template to some value from the entry.417 // description:418 // Function to set the contents of the content node in the template to some value from the entry.419 // This exists specifically so users can over-ride how the title data is filled out from an entry.420 // contentAnchorNode:421 // The DOM node to attach the content data to.422 // editMode:423 // Boolean to indicate if the display should be in edit mode or not.424 // entry:425 // The Feed Entry to work with.426 if(entry.content && entry.content.value && entry.content.value !== null){427 var contentViewNode = document.createElement("span");428 var contentView = new ContentPane({refreshOnShow: true, executeScripts: false},contentViewNode);429 contentView.attr('content', entry.content.value);430 contentAnchorNode.appendChild(contentView.domNode);431 this.setFieldValidity("content", true);432 }433 },434 _displaySections: function(){435 // summary:436 // Internal function for determining which sections of the view to actually display.437 // returns:438 // Nothing.439 domStyle.set(this.entryTitleRow, 'display', 'none');440 domStyle.set(this.entryAuthorRow, 'display', 'none');441 domStyle.set(this.entryContributorRow, 'display', 'none');442 domStyle.set(this.entrySummaryRow, 'display', 'none');443 domStyle.set(this.entryContentRow, 'display', 'none');444 domStyle.set(this.entryIdRow, 'display', 'none');445 domStyle.set(this.entryUpdatedRow, 'display', 'none');446 for(var i in this._displayEntrySections){447 var section = this._displayEntrySections[i].toLowerCase();448 if(section === "title" && this.isFieldValid("title")){449 domStyle.set(this.entryTitleRow, 'display', '');450 }451 if(section === "authors" && this.isFieldValid("authors")){452 domStyle.set(this.entryAuthorRow, 'display', '');453 }454 if(section === "contributors" && this.isFieldValid("contributors")){455 domStyle.set(this.entryContributorRow, 'display', '');456 }457 if(section === "summary" && this.isFieldValid("summary")){458 domStyle.set(this.entrySummaryRow, 'display', '');459 }460 if(section === "content" && this.isFieldValid("content")){461 domStyle.set(this.entryContentRow, 'display', '');462 }463 if(section === "id" && this.isFieldValid("id")){464 domStyle.set(this.entryIdRow, 'display', '');465 }466 if(section === "updated" && this.isFieldValid("updated")){467 domStyle.set(this.entryUpdatedRow, 'display', '');468 }469 }470 },471 setDisplaySections: function(/*array*/sectionsArray){472 // summary:473 // Function for setting which sections of the entry should be displayed.474 // sectionsArray:475 // Array of string names that indicate which sections to display.476 // returns:477 // Nothing.478 if(sectionsArray !== null){479 this._displayEntrySections = sectionsArray;480 this._displaySections();481 }else{482 this._displayEntrySections = ["title","authors","contributors","summary","content","id","updated"];483 }484 },485 _setDisplaySectionsCheckboxes: function(){486 // summary:487 // Internal function for setting which checkboxes on the display are selected.488 // returns:489 // Nothing.490 var items = ["title","authors","contributors","summary","content","id","updated"];491 for(var i in items){492 if(arrayUtil.indexOf(this._displayEntrySections, items[i]) == -1){493 domStyle.set(this["feedEntryCell"+items[i]], 'display', 'none');494 }else{495 this["feedEntryCheckBox"+items[i].substring(0,1).toUpperCase()+items[i].substring(1)].checked=true;496 }497 }498 },499 _readDisplaySections: function(){500 // summary:501 // Internal function for reading what is currently checked for display and generating the display list from it.502 var checkedList = [];503 if(this.feedEntryCheckBoxTitle.checked){504 checkedList.push("title");505 }506 if(this.feedEntryCheckBoxAuthors.checked){507 checkedList.push("authors");508 }509 if(this.feedEntryCheckBoxContributors.checked){510 checkedList.push("contributors");511 }512 if(this.feedEntryCheckBoxSummary.checked){513 checkedList.push("summary");514 }515 if(this.feedEntryCheckBoxContent.checked){516 checkedList.push("content");517 }518 if(this.feedEntryCheckBoxId.checked){519 checkedList.push("id");520 }521 if(this.feedEntryCheckBoxUpdated.checked){522 checkedList.push("updated");523 }524 this._displayEntrySections = checkedList;525 },526 _toggleCheckbox: function(/*object*/checkBox){527 // summary:528 // Internal function for determining of a particular entry is editable.529 // description:530 // Internal function for determining of a particular entry is editable.531 // This is used for determining if the delete action should be displayed or not.532 // checkBox:533 // The checkbox object to toggle the selection on.534 if(checkBox.checked){535 checkBox.checked=false;536 }else{537 checkBox.checked=true;538 }539 this._readDisplaySections();540 this._displaySections();541 },542 _toggleOptions: function(/*object*/checkBox){543 // summary:544 // Internal function for determining of a particular entry is editable.545 // description:546 // Internal function for determining of a particular entry is editable.547 // This is used for determining if the delete action should be displayed or not.548 // checkBox:549 // The checkbox object to toggle the selection on.550 if(this.enableMenu){551 var fade = null;552 var anim;553 var anim2;554 if(this._optionButtonDisplayed){555 if(this.enableMenuFade){556 anim = fx.fadeOut({node: this.entryCheckBoxDisplayOptions,duration: 250});557 connect.connect(anim, "onEnd", this, function(){558 domStyle.set(this.entryCheckBoxDisplayOptions, 'display', 'none');559 domStyle.set(this.entryCheckBoxRow, 'display', '');560 domStyle.set(this.entryCheckBoxRow2, 'display', '');561 fx.fadeIn({node: this.entryCheckBoxRow, duration: 250}).play();562 fx.fadeIn({node: this.entryCheckBoxRow2, duration: 250}).play();563 });564 anim.play();565 }else{566 domStyle.set(this.entryCheckBoxDisplayOptions, 'display', 'none');567 domStyle.set(this.entryCheckBoxRow, 'display', '');568 domStyle.set(this.entryCheckBoxRow2, 'display', '');569 }570 this._optionButtonDisplayed=false;571 }else{572 if(this.enableMenuFade){573 anim = fx.fadeOut({node: this.entryCheckBoxRow,duration: 250});574 anim2 = fx.fadeOut({node: this.entryCheckBoxRow2,duration: 250});575 connect.connect(anim, "onEnd", this, function(){576 domStyle.set(this.entryCheckBoxRow, 'display', 'none');577 domStyle.set(this.entryCheckBoxRow2, 'display', 'none');578 domStyle.set(this.entryCheckBoxDisplayOptions, 'display', '');579 fx.fadeIn({node: this.entryCheckBoxDisplayOptions, duration: 250}).play();580 });581 anim.play();582 anim2.play();583 }else{584 domStyle.set(this.entryCheckBoxRow, 'display', 'none');585 domStyle.set(this.entryCheckBoxRow2, 'display', 'none');586 domStyle.set(this.entryCheckBoxDisplayOptions, 'display', '');587 }588 this._optionButtonDisplayed=true;589 }590 }591 },592 _handleEvent: function(/*object*/entrySelectionEvent){593 // summary:594 // Internal function for listening to a topic that will handle entry notification.595 // entrySelectionEvent:596 // The topic message containing the entry that was selected for view.597 // returns:598 // Nothing.599 if(entrySelectionEvent.source != this){600 if(entrySelectionEvent.action == "set" && entrySelectionEvent.entry){601 this.setEntry(entrySelectionEvent.entry, entrySelectionEvent.feed);602 }else if(entrySelectionEvent.action == "delete" && entrySelectionEvent.entry && entrySelectionEvent.entry == this._entry){603 this.clear();604 }605 }606 },607 setFieldValidity: function(/*string*/field, /*boolean*/isValid){608 // summary:609 // Function to set whether a field in the view is valid and displayable.610 // description:611 // Function to set whether a field in the view is valid and displayable.612 // This is needed for over-riding of the set* functions and customization of how data is displayed in the attach point.613 // So if custom implementations use their own display logic, they can still enable the field.614 // field:615 // The field name to set the valid parameter on. Such as 'content', 'id', etc.616 // isValid:617 // Flag denoting if the field is valid or not.618 // returns:619 // Nothing.620 if(field){621 var lowerField = field.toLowerCase();622 this._validEntryFields[field] = isValid;623 }624 },625 626 isFieldValid: function(/*string*/field){627 // summary:628 // Function to return if a displayable field is valid or not629 // field:630 // The field name to get the valid parameter of. Such as 'content', 'id', etc.631 // returns:632 // boolean denoting if the field is valid and set.633 return this._validEntryFields[field.toLowerCase()];634 },635 getEntry: function(){636 return this._entry;637 },638 getFeed: function(){639 return this._feed;640 },641 destroy: function(){642 this.clear();643 arrayUtil.forEach(this._subscriptions, dojo.unsubscribe);644 }645});646var EntryHeader = FeedEntryViewer.EntryHeader = declare("dojox.atom.widget.EntryHeader", [_Widget, _Templated, _Container],{647 // summary:648 // Widget representing a header in a FeedEntryViewer/Editor649 title: "",650 templateString: headerTemplate,651 postCreate: function(){652 this.setListHeader();653 },654 setListHeader: function(/*string*/title){655 this.clear();656 if(title){657 this.title = title;658 }659 var textNode = document.createTextNode(this.title);660 this.entryHeaderNode.appendChild(textNode);661 },662 clear: function(){663 this.destroyDescendants();664 if(this.entryHeaderNode){665 for(var i = 0; i < this.entryHeaderNode.childNodes.length; i++){666 this.entryHeaderNode.removeChild(this.entryHeaderNode.childNodes[i]);667 }668 }669 },670 destroy: function(){671 this.clear();672 }673});674return FeedEntryViewer;...

Full Screen

Full Screen

views.py

Source:views.py Github

copy

Full Screen

1from django.shortcuts import render2from rest_framework import viewsets, status3from rest_framework.response import Response4from .models import Entry, Participant, Result, Survey_result5from .serializers import EntryQuesSerializer, ParticipantSerializer, EntryYesSerializer, EntryNoSerializer, \6 ResultSerializer, SurveySerializer7import random8from rest_framework.decorators import action9from django.db.models import F10class ResultViewSet(viewsets.ModelViewSet):11 queryset = Result.objects.all()12 serializer_class = ResultSerializer13 @action(detail=False, methods=['POST'])14 def post_answer_training(self, request):15 participant = Participant.objects.get(participant_id=request.data['id'])16 entry = Entry.objects.get(id=request.data['question'])17 Result.objects.create(worker_id=participant, user_points=request.data['score'], agent_points=0,18 bought_information=request.data['yes_no'], round_num=request.data['round'],19 training_question=True, entry_id=entry, buy_info_decision_time=0)20 participant.training_round = participant.training_round + 121 participant.save()22 return Response("result created", status=status.HTTP_200_OK)23 @action(detail=False, methods=['POST'])24 def post_answer_game(self, request):25 participant = Participant.objects.get(participant_id=request.data['id'])26 entry = Entry.objects.get(id=request.data['question'])27 entry.used_count = entry.used_count + 128 entry.save()29 Result.objects.create(worker_id=participant, user_points=request.data['score'], agent_points=0,30 bought_information=request.data['yes_no'], round_num=request.data['round'],31 training_question=False, entry_id=entry, buy_info_decision_time=0)32 participant.game_round = participant.game_round + 133 participant.save()34 return Response("result created", status=status.HTTP_200_OK)35class EntryViewSet(viewsets.ModelViewSet):36 queryset = Entry.objects.all()37 serializer_class = EntryQuesSerializer38 @action(detail=False, methods=['POST'])39 def get_another_game_ent(self, request):40 participant = Participant.objects.get(participant_id=request.data['id'])41 if participant.game_round > 20:42 return Response(False, status=status.HTTP_200_OK)43 ent_obj = Entry.objects.filter(used_count__lte=1)44 random_ent = random.sample(list(ent_obj), 1)45 serializer = EntryQuesSerializer(random_ent, many=True)46 serializer.data[0]['round'] = participant.game_round47 return Response(serializer.data[0], status=status.HTTP_200_OK)48 @action(detail=False, methods=['POST'])49 def get_another_training_ent(self, request):50 participant = Participant.objects.get(participant_id=request.data['id'])51 if participant.training_round == 1:52 ent_obj = Entry.objects.filter(sold_with__gt=F('z') * F('voi') + F('sold_without'))53 random_ent = random.sample(list(ent_obj), 1)54 serializer = EntryQuesSerializer(random_ent, many=True)55 serializer.data[0]['round'] = 156 return Response(serializer.data[0], status=status.HTTP_200_OK)57 if participant.training_round == 2:58 ent_obj = Entry.objects.filter(sold_with__lt=F('sold_without'))59 random_ent = random.sample(list(ent_obj), 1)60 serializer = EntryQuesSerializer(random_ent, many=True)61 serializer.data[0]['round'] = 262 return Response(serializer.data[0], status=status.HTTP_200_OK)63 ent_obj = Entry.objects.all()64 random_ent = random.sample(list(ent_obj), 1)65 serializer = EntryQuesSerializer(random_ent, many=True)66 serializer.data[0]['round'] = participant.training_round67 return Response(serializer.data[0], status=status.HTTP_200_OK)68 @action(detail=False, methods=['GET'])69 def get_first(self, request):70 ent_obj = Entry.objects.filter(sold_with__gt=F('z') * F('voi') + F('sold_without'))71 random_ent = random.sample(list(ent_obj), 1)72 serializer = EntryQuesSerializer(random_ent, many=True)73 return Response(serializer.data[0], status=status.HTTP_200_OK)74 @action(detail=False, methods=['GET'])75 def get_second(self, request):76 ent_obj = Entry.objects.filter(sold_with__lt=F('sold_without'))77 random_ent = random.sample(list(ent_obj), 1)78 serializer = EntryQuesSerializer(random_ent, many=True)79 return Response(serializer.data[0], status=status.HTTP_200_OK)80class EntryYesViewSet(viewsets.ModelViewSet):81 queryset = Entry.objects.all()82 serializer_class = EntryYesSerializer83 @action(detail=False, methods=['POST'])84 def get_bidders(self, request):85 entry = Entry.objects.get(id=request.data['id'])86 entrys_sum = []87 if entry.s == 1:88 entrys_sum = [entry.v11, entry.v21, entry.v31, entry.v41, entry.v51]89 if entry.s == 2:90 entrys_sum = [entry.v12, entry.v22, entry.v32, entry.v42, entry.v52]91 if entry.s == 3:92 entrys_sum = [entry.v13, entry.v23, entry.v33, entry.v43, entry.v53]93 if entry.s == 4:94 entrys_sum = [entry.v14, entry.v24, entry.v34, entry.v44, entry.v54]95 if entry.s == 5:96 entrys_sum = [entry.v15, entry.v25, entry.v35, entry.v45, entry.v55]97 if entry.s == 6:98 entrys_sum = [entry.v16, entry.v26, entry.v36, entry.v46, entry.v56]99 if entry.s == 7:100 entrys_sum = [entry.v17, entry.v27, entry.v37, entry.v47, entry.v57]101 entrys_count = [0, 0, 0, 0, 0]102 for i in range(1, entry.y + 1):103 if i == entry.n1:104 entrys_count[i - 1] = entrys_count[i - 1] + 1105 if i == entry.n2:106 entrys_count[i - 1] = entrys_count[i - 1] + 1107 if i == entry.n3:108 entrys_count[i - 1] = entrys_count[i - 1] + 1109 if i == entry.n4:110 entrys_count[i - 1] = entrys_count[i - 1] + 1111 if i == entry.n5:112 entrys_count[i - 1] = entrys_count[i - 1] + 1113 if i == entry.n6:114 entrys_count[i - 1] = entrys_count[i - 1] + 1115 if i == entry.n7:116 entrys_count[i - 1] = entrys_count[i - 1] + 1117 if i == entry.n8:118 entrys_count[i - 1] = entrys_count[i - 1] + 1119 type_json = {'t1': entrys_count[0], 't2': entrys_count[1], 't3': entrys_count[2], 't4': entrys_count[3],120 't5': entrys_count[4], 't1_bid': entrys_sum[0], 't2_bid': entrys_sum[1], 't3_bid': entrys_sum[2],121 't4_bid': entrys_sum[3], 't5_bid': entrys_sum[4]}122 return Response(type_json, status=status.HTTP_200_OK)123 @action(detail=False, methods=['POST'])124 def get_yes(self, request):125 entry = Entry.objects.get(id=request.data['question'])126 serializer = EntryYesSerializer(entry, many=False)127 return Response(serializer.data, status=status.HTTP_200_OK)128class EntryNoViewSet(viewsets.ModelViewSet):129 queryset = Entry.objects.all()130 serializer_class = EntryNoSerializer131 @action(detail=False, methods=['POST'])132 def get_bidders(self, request):133 entry = Entry.objects.get(id=request.data['id'])134 entrys_sum = [0, 0, 0, 0, 0]135 entrys_count = [0, 0, 0, 0, 0]136 if entry.n1 == 1:137 entrys_count[0] = entrys_count[0] + 1138 entrys_sum[0] = entry.n1_without139 if entry.n1 == 2:140 entrys_count[1] = entrys_count[1] + 1141 entrys_sum[1] = entry.n1_without142 if entry.n1 == 3:143 entrys_count[2] = entrys_count[2] + 1144 entrys_sum[2] = entry.n1_without145 if entry.n1 == 4:146 entrys_count[3] = entrys_count[3] + 1147 entrys_sum[3] = entry.n1_without148 if entry.n1 == 5:149 entrys_count[4] = entrys_count[4] + 1150 entrys_sum[4] = entry.n1_without151 if entry.n2 == 1:152 entrys_count[0] = entrys_count[0] + 1153 entrys_sum[0] = entry.n2_without154 if entry.n2 == 2:155 entrys_count[1] = entrys_count[1] + 1156 entrys_sum[1] = entry.n2_without157 if entry.n2 == 3:158 entrys_count[2] = entrys_count[2] + 1159 entrys_sum[2] = entry.n2_without160 if entry.n2 == 4:161 entrys_count[3] = entrys_count[3] + 1162 entrys_sum[3] = entry.n2_without163 if entry.n2 == 5:164 entrys_count[4] = entrys_count[4] + 1165 entrys_sum[4] = entry.n2_without166 if entry.n3 == 1:167 entrys_count[0] = entrys_count[0] + 1168 entrys_sum[0] = entry.n3_without169 if entry.n3 == 2:170 entrys_count[1] = entrys_count[1] + 1171 entrys_sum[1] = entry.n3_without172 if entry.n3 == 3:173 entrys_count[2] = entrys_count[2] + 1174 entrys_sum[2] = entry.n3_without175 if entry.n3 == 4:176 entrys_count[3] = entrys_count[3] + 1177 entrys_sum[3] = entry.n3_without178 if entry.n3 == 5:179 entrys_count[4] = entrys_count[4] + 1180 entrys_sum[4] = entry.n3_without181 if entry.n4 == 1:182 entrys_count[0] = entrys_count[0] + 1183 entrys_sum[0] = entry.n4_without184 if entry.n4 == 2:185 entrys_count[1] = entrys_count[1] + 1186 entrys_sum[1] = entry.n4_without187 if entry.n4 == 3:188 entrys_count[2] = entrys_count[2] + 1189 entrys_sum[2] = entry.n4_without190 if entry.n4 == 4:191 entrys_count[3] = entrys_count[3] + 1192 entrys_sum[3] = entry.n4_without193 if entry.n4 == 5:194 entrys_count[4] = entrys_count[4] + 1195 entrys_sum[4] = entry.n4_without196 if entry.n5 == 1:197 entrys_count[0] = entrys_count[0] + 1198 entrys_sum[0] = entry.n5_without199 if entry.n5 == 2:200 entrys_count[1] = entrys_count[1] + 1201 entrys_sum[1] = entry.n5_without202 if entry.n5 == 3:203 entrys_count[2] = entrys_count[2] + 1204 entrys_sum[2] = entry.n5_without205 if entry.n5 == 4:206 entrys_count[3] = entrys_count[3] + 1207 entrys_sum[3] = entry.n5_without208 if entry.n5 == 5:209 entrys_count[4] = entrys_count[4] + 1210 entrys_sum[4] = entry.n5_without211 if entry.n6 == 1:212 entrys_count[0] = entrys_count[0] + 1213 entrys_sum[0] = entry.n6_without214 if entry.n6 == 2:215 entrys_count[1] = entrys_count[1] + 1216 entrys_sum[1] = entry.n6_without217 if entry.n6 == 3:218 entrys_count[2] = entrys_count[2] + 1219 entrys_sum[2] = entry.n6_without220 if entry.n6 == 4:221 entrys_count[3] = entrys_count[3] + 1222 entrys_sum[3] = entry.n6_without223 if entry.n6 == 5:224 entrys_count[4] = entrys_count[4] + 1225 entrys_sum[4] = entry.n6_without226 if entry.n7 == 1:227 entrys_count[0] = entrys_count[0] + 1228 entrys_sum[0] = entry.n7_without229 if entry.n7 == 2:230 entrys_count[1] = entrys_count[1] + 1231 entrys_sum[1] = entry.n7_without232 if entry.n7 == 3:233 entrys_count[2] = entrys_count[2] + 1234 entrys_sum[2] = entry.n7_without235 if entry.n7 == 4:236 entrys_count[3] = entrys_count[3] + 1237 entrys_sum[3] = entry.n7_without238 if entry.n7 == 5:239 entrys_count[4] = entrys_count[4] + 1240 entrys_sum[4] = entry.n7_without241 if entry.n8 == 1:242 entrys_count[0] = entrys_count[0] + 1243 entrys_sum[0] = entry.n8_without244 if entry.n8 == 2:245 entrys_count[1] = entrys_count[1] + 1246 entrys_sum[1] = entry.n8_without247 if entry.n8 == 3:248 entrys_count[2] = entrys_count[2] + 1249 entrys_sum[2] = entry.n8_without250 if entry.n8 == 4:251 entrys_count[3] = entrys_count[3] + 1252 entrys_sum[3] = entry.n8_without253 if entry.n8 == 5:254 entrys_count[4] = entrys_count[4] + 1255 entrys_sum[4] = entry.n8_without256 type_json = {'t1': entrys_count[0], 't2': entrys_count[1], 't3': entrys_count[2], 't4': entrys_count[3],257 't5': entrys_count[4], 't1_bid': entrys_sum[0], 't2_bid': entrys_sum[1], 't3_bid': entrys_sum[2],258 't4_bid': entrys_sum[3], 't5_bid': entrys_sum[4]}259 return Response(type_json, status=status.HTTP_200_OK)260 @action(detail=False, methods=['POST'])261 def get_no(self, request):262 entry = Entry.objects.get(id=request.data['question'])263 serializer = EntryNoSerializer(entry, many=False)264 return Response(serializer.data, status=status.HTTP_200_OK)265class ParticipantViewSet(viewsets.ModelViewSet):266 queryset = Participant.objects.all()267 serializer_class = ParticipantSerializer268 @action(detail=False, methods=['POST'])269 def add_participant(self, request):270 participant = Participant.objects.create(age=request.data['age'], gender=request.data['gender'],271 education=request.data['education'],272 nationality=request.data['nationality'], instructions_time="-1",273 training_time="-1",274 game_time="-1", bonus=0, bonus_payed=False, HITId="-1",275 AssignmentId="-1",276 round_pass_instructions=1, instructions_score=0)277 return Response(participant.participant_id, status=status.HTTP_200_OK)278 @action(detail=False, methods=['POST'])279 def is_participant(self, request):280 try:281 participant = Participant.objects.get(participant_id=request.data['id'])282 if participant.round_pass_instructions > 3:283 return Response(False, status=status.HTTP_200_OK)284 return Response(True, status=status.HTTP_200_OK)285 except Participant.DoesNotExist:286 return Response(False, status=status.HTTP_200_OK)287 @action(detail=False, methods=['POST'])288 def pass_instructions(self, request):289 try:290 participant = Participant.objects.get(participant_id=request.data['id'])291 if participant.round_pass_instructions > 3 or participant.instructions_score < 7:292 return Response(False, status=status.HTTP_200_OK)293 return Response(True, status=status.HTTP_200_OK)294 except Participant.DoesNotExist:295 return Response(False, status=status.HTTP_200_OK)296 @action(detail=False, methods=['POST'])297 def update_score(self, request):298 participant = Participant.objects.get(participant_id=request.data['id'])299 participant.instructions_score = request.data['score']300 participant.instructions_time = request.data['time']301 if request.data['score'] < 7:302 participant.round_pass_instructions = participant.round_pass_instructions + 1303 participant.save()304 if participant.round_pass_instructions > 3:305 return Response(False, status=status.HTTP_200_OK)306 return Response(True, status=status.HTTP_200_OK)307 @action(detail=False, methods=['POST'])308 def get_round(self, request):309 participant = Participant.objects.get(participant_id=request.data['id'])310 return Response(participant.training_round, status=status.HTTP_200_OK)311 @action(detail=False, methods=['POST'])312 def get_round_game(self, request):313 participant = Participant.objects.get(participant_id=request.data['id'])314 return Response(participant.game_round, status=status.HTTP_200_OK)315class SurveyViewSet(viewsets.ModelViewSet):316 queryset = Survey_result.objects.all()317 serializer_class = SurveySerializer318 @action(detail=False, methods=['POST'])319 def add_survey(self, request):320 participant = Participant.objects.get(participant_id=request.data['id'])321 survey1 = Survey_result.objects.create(answer=request.data['q1'],322 question='Overall, how satisfied were you with this HIT?',323 worker_id=participant)324 survey2 = Survey_result.objects.create(answer=request.data['q2'],325 question='What was your attention span when you did the HIT?',326 worker_id=participant)327 survey3 = Survey_result.objects.create(answer=request.data['q3'],328 question='Are you happy with the bonus?(2$)', worker_id=participant)329 survey4 = Survey_result.objects.create(answer=request.data['q4'],330 question='Do you have any comments?', worker_id=participant)...

Full Screen

Full Screen

attachbox_ui.js

Source:attachbox_ui.js Github

copy

Full Screen

1TrexMessage.addMsg({2 '@attacher.ins': "삽입",3 '@attacher.del': "삭제",4 '@attacher.preview.image': "#iconpath/pn_preview.gif",5 '@attacher.delete.confirm': "삭제하시면 본문에서도 삭제됩니다. 계속하시겠습니까?",6 '@attacher.delete.all.confirm': "모든 첨부 파일을 삭제하시겠습니까? 삭제하시면 본문에서도 삭제됩니다.",7 '@attacher.exist.alert': "이미 본문에 삽입되어 있습니다."8});9Trex.install("attachbox.onAttachBoxInitialized @if config.sidebar.attachbox.show = true", function(editor, toolbar, sidebar, canvas, config) {10 var attachbox = editor.getAttachBox();11 if (config.sidebar.attachbox.show == _TRUE) {12 Object.extend(attachbox, Trex.I.AttachBox);13 attachbox.onAttachBoxInitialized(config, canvas, editor);14 }15});16Trex.I.AttachBox = {17 useBox: _TRUE,18 isDisplay: _FALSE,19 lastSelectedEntry: _NULL,20 onAttachBoxInitialized: function(config, canvas) {21 var _entryBox = this;22 this.canvas = canvas;23 24 var _initializedId = ((config.initializedId) ? config.initializedId : "");25 this.elBox = $must("tx_attach_div" + _initializedId, "Trex.I.AttachBox");26 27 this.elList = $must("tx_attach_list" + _initializedId, "Trex.I.AttachBox");28 var _elPreview = $must('tx_attach_preview' + _initializedId, "Trex.I.AttachBox");29 this.elPreviewKind = $tom.collect(_elPreview, "p");30 var _elPreviewImg = $tom.collect(_elPreview, "img");31 this.elPreviewImg = _elPreviewImg;32 this.imageResizer = new Trex.ImageResizer(_elPreviewImg, {33 maxWidth: 147,34 maxHeight: 108,35 defImgUrl: TXMSG("@attacher.preview.image"),36 onComplete: function(width, height) { //vertical positioning37 _elPreviewImg.style.marginTop = Math.floor((108 - height) / 2).toPx();38 }39 });40 41 this.elDelete = $tom.collect("#tx_attach_delete" + _initializedId + " a");42 $tx.observe(this.elDelete, 'click', function() {43 if (config.sidebar.attachbox.confirmForDeleteAll) {44 _entryBox.onDeleteAll(false);45 } else {46 _entryBox.onDeleteAll(true);47 }48 });49 50 if (typeof showAttachBox == "function") { //NOTE: 첨부박스가 보여질 때 실행할 서비스 콜백51 this.observeJob(Trex.Ev.__ATTACHBOX_SHOW, function() {52 showAttachBox();53 });54 }55 if (typeof hideAttachBox == "function") { //NOTE: 첨부박스가 감춰질 때 실행할 서비스 콜백56 this.observeJob(Trex.Ev.__ATTACHBOX_HIDE, function() {57 hideAttachBox();58 });59 }60 61 var _elProgress = $must('tx_upload_progress' + _initializedId, 'Trex.I.AttachBox');62 this.elProgress = _elProgress;63 this.elProgressPercent = $tom.collect(_elProgress, "div");64 this.elProgressTicker = $tom.collect(_elProgress, "p");65 66 this.observeJob(Trex.Ev.__ENTRYBOX_ENTRY_ADDED, function(entry) {67 _entryBox.registerEntryNode(entry);68 _entryBox.displayBox();69 });70 this.observeJob(Trex.Ev.__ENTRYBOX_ENTRY_MODIFIED, function(entry) {71 _entryBox.modifyEntryNode(entry);72 _entryBox.refreshPreview();73 });74 this.observeJob(Trex.Ev.__ENTRYBOX_ENTRY_REMOVED, function(entry) {75 _entryBox.removeEntryNode(entry);76 _entryBox.displayBox();77 if (_entryBox.lastSelectedEntry && _entryBox.lastSelectedEntry.key == entry.key) {78 _entryBox.refreshPreview();79 }80 81 });82 this.observeJob(Trex.Ev.__ENTRYBOX_ALL_ENTRY_REMOVED, function() {83 _entryBox.datalist.each(function(entry) {84 _entryBox.removeEntryNode(entry, _TRUE);85 });86 _entryBox.displayBox();87 if (_entryBox.lastSelectedEntry) {88 _entryBox.refreshPreview();89 }90 });91 this.observeJob(Trex.Ev.__ENTRYBOX_ENTRY_REFRESH, function(entry) {92 _entryBox.displayBox();93 _entryBox.refreshEntryNode(entry);94 });95 96 var _elUploadedSize = $tx('tx_attach_up_size' + _initializedId), _elMaximumSize = $tx('tx_attach_max_size' + _initializedId), _elGroupUsedSize = $tx('tx_attach_group_used_size' + _initializedId), _elGroupMaximumSize = $tx('tx_attach_group_max_size' + _initializedId);97 98 this.observeJob(Trex.Ev.__ENTRYBOX_CAPACITY_UPDATE, function() {99 var capacity = config.sidebar.capacity;100 if (capacity.show == _FALSE) {101 return;102 }103 104 if (_elUploadedSize) {105 _elUploadedSize.innerText = capacity.uploaded.toByteUnit();106 }107 if (_elMaximumSize) {108 // maximum을 안쓰고 available을 사용하는 이유는 group 값 이용시 group.used의 사용여하에 따라 최대치가 달라지기 때문109 _elMaximumSize.innerText = capacity.available.toByteUnit();110 }111 if (capacity.group) {112 if (_elGroupUsedSize) {113 _elGroupUsedSize.innerText = (capacity.group.used + capacity.uploaded).toByteUnit();114 }115 if (_elGroupMaximumSize) {116 _elGroupMaximumSize.innerText = capacity.group.maximum.toByteUnit();117 }118 }119 });120 121 // canvas에서 제거된 첨부파일은 첨부박스에는 1차로는 남아있기 때문에 아래와 같은 삭제 과정이 필요하지 않다122 // canvas.observeJob(Trex.Ev.__CANVAS_PANEL_DELETE_SOMETHING, function(ev){123 // // 데이터중에 존재하지 stage에 존재하지 않는 entry는 박스에서 바로 제거124 // _entryBox.datalist.each(function (entry) {125 // if (entry.type =='image' && entry.actor.name == 'image' && entry.existStage == false) {126 // entry.execRemove();127 // }128 // });129 // _entryBox.refreshPreview();130 // });131 },132 onDeleteAll: function(force) {133 if (this.datalist.length === 0) {134 return;135 }136 if (!force && !confirm(TXMSG("@attacher.delete.all.confirm"))) {137 return;138 }139 this.datalist.each(function(entry) {140 if (entry.deletedMark == _FALSE) {141 entry.execRemove();142 }143 });144 // this.imageResizer.execResize(TXMSG("@attacher.preview.image"));145 this.initPreviewImage();146 },147 checkDisplay: function() {148 return this.isDisplay;149 },150 setDisplay: function(isDisplay) {151 this.isDisplay = isDisplay;152 },153 displayBox: function() {154 var isDisplay = _FALSE;155 for (var i = 0; i < this.datalist.length; i++) {156 if (this.datalist[i].deletedMark == _FALSE) {157 isDisplay = _TRUE;158 }159 }160 //var isDisplay = (this.datalist.length > 0);161 if (this.isDisplay == isDisplay) {162 return;163 }164 if (isDisplay) {165 $tx.show(this.elBox);166 this.fireJobs(Trex.Ev.__ATTACHBOX_SHOW, _TRUE);167 } else {168 $tx.hide(this.elBox);169 this.fireJobs(Trex.Ev.__ATTACHBOX_HIDE, _FALSE);170 }171 this.isDisplay = isDisplay;172 },173 registerEntryNode: function(entry) {174 var _elData = tx.li({175 className: "type-" + entry.type176 });177 if (entry.actor.boxonly) {178 $tx.addClassName(_elData, "tx-boxonly");179 }180 this.elList.appendChild(_elData);181 entry.elData = _elData;182 183 entry.makeSelection = function(isPreviewed) {184 if (isPreviewed) {185 this.showEntryThumb(entry);186 } else {187 this.hideEntryThumb(entry);188 }189 }190.bind(this);191 192 //NOTE: only blog cuz iframe area193 $tx.observe(_elData, 'mouseover', this.onEntryMouseOver.bind(this, entry));194 $tx.observe(_elData, 'mouseout', this.onEntryMouseOut.bind(this, entry));195 196 var _elRow = tx.dl();197 _elData.appendChild(_elRow);198 199 var _elName = tx.dt({200 className: "tx-name",201 unselectable: "on"202 }, entry.boxAttr.name); //파일명203 entry.elName = _elName;204 _elRow.appendChild(_elName);205 $tx.observe(_elData, 'click', function(e) {206 var _el = $tx.element(e);207 if (_el.className == "tx-delete" || _el.className == "tx-insert") {208 return;209 }210 if (e.ctrlKey) {211 this.clickEntryWithCtrl(entry);212 } else if (e.shiftKey) {213 this.clickEntryWithShift(entry);214 } else {215 this.clickEntry(entry);216 }217 if (entry.actor.name == 'image') { //NOTE: get image scale218 if (!entry.data.width || !entry.data.height) {219 new Trex.ImageScale(entry.data);220 }221 }222 }223.bind(this), _FALSE);224 225 var _elButton = tx.dd({226 className: "tx-button"227 }); //버튼228 _elRow.appendChild(_elButton);229 230 var _elDelete = tx.a({231 className: "tx-delete"232 }, TXMSG("@attacher.del")); //삭제233 _elButton.appendChild(_elDelete);234 $tx.observe(_elDelete, 'click', function() {235 if (!confirm(TXMSG("@attacher.delete.confirm"))) {236 return;237 }238 entry.execRemove();239 }, _FALSE);240 241 242 var _elInsert = tx.a({243 className: "tx-insert"244 }, TXMSG("@attacher.ins")); //삽입245 entry.elInsert = _elInsert;246 _elButton.appendChild(_elInsert);247 $tx.observe(_elInsert, 'click', function() {248 if (entry.existStage && !entry.actor.config.multipleuse) {249 alert(TXMSG("@attacher.exist.alert"));250 } else {251 entry.execAppend();252 }253 }, _FALSE);254 255 256 },257 changeState: function(entry) {258 var _existStage = entry.existStage;259 if (_existStage && !entry.actor.config.multipleuse) {260 $tx.addClassName(entry.elData, "tx-existed");261 } else {262 $tx.removeClassName(entry.elData, "tx-existed");263 }264 },265 modifyEntryNode: function(entry) {266 entry.elName.innerText = entry.boxAttr.name;267 },268 removeEntryNode: function(entry, force) {269 if (force) {270 entry.elData.parentNode.removeChild(entry.elData);271 } else if (entry.deletedMark) {272 $tx.hide(entry.elData);273 }274 },275 refreshEntryNode: function(entry) {276 if (entry.deletedMark) {277 $tx.hide(entry.elData);278 } else {279 $tx.show(entry.elData);280 }281 },282 refreshPreview: function() {283 // reload last selected entry284 for (var i = 0, l = this.datalist.length - 1; i < l; ++i) {285 var entry = this.datalist[i];286 if (this.lastSelectedEntry && this.lastSelectedEntry.key == entry.key && entry.deleteMark == false) {287 this.setPreivewImage(entry);288 return _TRUE;289 }290 }291 292 // reselect293 for (var i = 0, l = this.datalist.length - 1; i < l; ++i) {294 var entry = this.datalist[i];295 if (entry.deletedMark == false && $tx.hasClassName(entry.elData, "tx-clicked")) {296 this.setPreivewImage(entry);297 return _TRUE;298 }299 }300 301 // init302 this.initPreviewImage();303 return _FALSE;304 },305 setPreivewImage: function(entry) {306 this.imageResizer.execResize(entry.boxAttr.image);307 this.lastSelectedEntry = entry;308 },309 initPreviewImage: function() {310 this.imageResizer.execResize(TXMSG("@attacher.preview.image"));311 this.lastSelectedEntry = _NULL;312 },313 showEntryThumb: function(entry) {314 $tx.addClassName(entry.elData, "tx-clicked");315 $tx.removeClassName(entry.elData, "tx-hovered");316 },317 hideEntryThumb: function(entry) {318 $tx.removeClassName(entry.elData, "tx-clicked");319 },320 onEntryMouseOver: function(entry) {321 $tx.addClassName(entry.elData, "tx-hovered");322 },323 onEntryMouseOut: function(entry) {324 $tx.removeClassName(entry.elData, "tx-hovered");325 },326 startUpload: function() {327 this.elProgressPercent.style.width = "0".toPx();328 $tx.setStyle(this.elList, {329 opacity: 0.3330 });331 $tx.show(this.elProgress);332 },333 doUpload: function(percent) {334 var progressWidth = 300;335 this.elProgressPercent.style.width = Math.floor(progressWidth * (isNaN(percent) ? 0 : parseFloat(percent) * 0.01)).toPx();336 this.elProgressTicker.innerText = Math.floor((isNaN(percent) ? 0 : parseFloat(percent))) + "%";337 },338 endUpload: function() {339 $tx.hide(this.elProgress);340 $tx.setStyle(this.elList, {341 opacity: 1342 });343 },344 clickEntry: function(entry) {345 if (this.lastSelectedEntry) {346 if (this.lastSelectedEntry.key == entry.key) {347 return;348 }349 this.datalist.each(function(entry) {350 entry.makeSelection(_FALSE);351 });352 }353 this.elPreviewKind.className = ((entry.boxAttr.className) ? entry.boxAttr.className : "");354 entry.makeSelection(_TRUE);355 this.setPreivewImage(entry);356 },357 clickEntryWithCtrl: function(entry) {358 if ($tx.hasClassName(entry.elData, 'tx-clicked')) {359 entry.makeSelection(_FALSE);360 this.refreshPreview();361 } else {362 this.elPreviewKind.className = ((entry.boxAttr.className) ? entry.boxAttr.className : "");363 entry.makeSelection(_TRUE);364 this.setPreivewImage(entry);365 }366 },367 clickEntryWithShift: function(entry) {368 if ($tx.hasClassName(entry.elData, 'tx-clicked')) {369 entry.makeSelection(_FALSE);370 this.lastSelectedEntry = _NULL;371 } else {372 var idx = this.getIndexOf(entry);373 var targetIdx;374 if (this.lastSelectedEntry) {375 targetIdx = this.getIndexOf(this.lastSelectedEntry);376 }377 378 var from = targetIdx, to = idx;379 if (idx == targetIdx) {380 from = to = idx;381 } else if (idx < targetIdx) {382 from = idx;383 to = targetIdx;384 }385 386 this.elPreviewKind.className = ((entry.boxAttr.className) ? entry.boxAttr.className : "");387 for (var i = from; i < to + 1; i++) {388 this.datalist[i].makeSelection(_TRUE);389 }390 this.setPreivewImage(entry);391 }392 },393 getIndexOf: function(entry) {394 var i, matched;395 for (i = 0; i < this.datalist.length; i++) {396 if (this.datalist[i] === entry) {397 matched = _TRUE;398 break;399 }400 }401 return matched ? i : -1;402 },403 getSelectedList: function(attachType) {404 var _list = [];405 var _source;406 if (attachType) {407 _source = this.getAttachments(attachType);408 } else {409 _source = this.datalist;410 }411 _source.each(function(entry) {412 if ($tx.hasClassName(entry.elData, "tx-clicked")) {413 _list.push(entry);414 }415 });416 return _list;417 },418 removeSelection: function(datalist) {419 datalist.each(function(data) {420 $tx.removeClassName(data.elData, "tx-clicked");421 })422 }...

Full Screen

Full Screen

entries.py

Source:entries.py Github

copy

Full Screen

2import os3import requests4import config5import utils6def entry(uids, ctList):7 utils.log('entry sync START', verbose=True)8 if uids is None or ctList is None or len(uids) != len(ctList):9 print('Please provide valid uids')10 utils.log('entry sync END', verbose=True)11 return12 entriesMap = {}13 assetsMap = {}14 with open('./data/mapping/entries.json') as f:15 entriesMap = json.load(f)16 with open('./data/mapping/assets.json') as f:17 assetsMap = json.load(f)18 def updateEntryDst(uid, ct):19 file_field_uid = []20 file_field_uid_multiple = []...

Full Screen

Full Screen

leap.js

Source:leap.js Github

copy

Full Screen

1/**2 * Copyright (c) 2014-present, Facebook, Inc.3 *4 * This source code is licensed under the MIT license found in the5 * LICENSE file in the root directory of this source tree.6 */7import assert from "assert";8import { Emitter } from "./emit";9import { inherits } from "util";10import { getTypes } from "./util";11function Entry() {12 assert.ok(this instanceof Entry);13}14function FunctionEntry(returnLoc) {15 Entry.call(this);16 getTypes().assertLiteral(returnLoc);17 this.returnLoc = returnLoc;18}19inherits(FunctionEntry, Entry);20exports.FunctionEntry = FunctionEntry;21function LoopEntry(breakLoc, continueLoc, label) {22 Entry.call(this);23 const t = getTypes();24 t.assertLiteral(breakLoc);25 t.assertLiteral(continueLoc);26 if (label) {27 t.assertIdentifier(label);28 } else {29 label = null;30 }31 this.breakLoc = breakLoc;32 this.continueLoc = continueLoc;33 this.label = label;34}35inherits(LoopEntry, Entry);36exports.LoopEntry = LoopEntry;37function SwitchEntry(breakLoc) {38 Entry.call(this);39 getTypes().assertLiteral(breakLoc);40 this.breakLoc = breakLoc;41}42inherits(SwitchEntry, Entry);43exports.SwitchEntry = SwitchEntry;44function TryEntry(firstLoc, catchEntry, finallyEntry) {45 Entry.call(this);46 const t = getTypes();47 t.assertLiteral(firstLoc);48 if (catchEntry) {49 assert.ok(catchEntry instanceof CatchEntry);50 } else {51 catchEntry = null;52 }53 if (finallyEntry) {54 assert.ok(finallyEntry instanceof FinallyEntry);55 } else {56 finallyEntry = null;57 }58 // Have to have one or the other (or both).59 assert.ok(catchEntry || finallyEntry);60 this.firstLoc = firstLoc;61 this.catchEntry = catchEntry;62 this.finallyEntry = finallyEntry;63}64inherits(TryEntry, Entry);65exports.TryEntry = TryEntry;66function CatchEntry(firstLoc, paramId) {67 Entry.call(this);68 const t = getTypes();69 t.assertLiteral(firstLoc);70 t.assertIdentifier(paramId);71 this.firstLoc = firstLoc;72 this.paramId = paramId;73}74inherits(CatchEntry, Entry);75exports.CatchEntry = CatchEntry;76function FinallyEntry(firstLoc, afterLoc) {77 Entry.call(this);78 const t = getTypes();79 t.assertLiteral(firstLoc);80 t.assertLiteral(afterLoc);81 this.firstLoc = firstLoc;82 this.afterLoc = afterLoc;83}84inherits(FinallyEntry, Entry);85exports.FinallyEntry = FinallyEntry;86function LabeledEntry(breakLoc, label) {87 Entry.call(this);88 const t = getTypes();89 t.assertLiteral(breakLoc);90 t.assertIdentifier(label);91 this.breakLoc = breakLoc;92 this.label = label;93}94inherits(LabeledEntry, Entry);95exports.LabeledEntry = LabeledEntry;96function LeapManager(emitter) {97 assert.ok(this instanceof LeapManager);98 assert.ok(emitter instanceof Emitter);99 this.emitter = emitter;100 this.entryStack = [new FunctionEntry(emitter.finalLoc)];101}102let LMp = LeapManager.prototype;103exports.LeapManager = LeapManager;104LMp.withEntry = function(entry, callback) {105 assert.ok(entry instanceof Entry);106 this.entryStack.push(entry);107 try {108 callback.call(this.emitter);109 } finally {110 let popped = this.entryStack.pop();111 assert.strictEqual(popped, entry);112 }113};114LMp._findLeapLocation = function(property, label) {115 for (let i = this.entryStack.length - 1; i >= 0; --i) {116 let entry = this.entryStack[i];117 let loc = entry[property];118 if (loc) {119 if (label) {120 if (entry.label &&121 entry.label.name === label.name) {122 return loc;123 }124 } else if (entry instanceof LabeledEntry) {125 // Ignore LabeledEntry entries unless we are actually breaking to126 // a label.127 } else {128 return loc;129 }130 }131 }132 return null;133};134LMp.getBreakLoc = function(label) {135 return this._findLeapLocation("breakLoc", label);136};137LMp.getContinueLoc = function(label) {138 return this._findLeapLocation("continueLoc", label);...

Full Screen

Full Screen

DynamicEntryPlugin.js

Source:DynamicEntryPlugin.js Github

copy

Full Screen

...54 resolve();55 });56 });57 };58 Promise.resolve(this.entry()).then(entry => {59 if (typeof entry === "string" || Array.isArray(entry)) {60 addEntry(entry, "main").then(() => callback(), callback);61 } else if (typeof entry === "object") {62 Promise.all(63 Object.keys(entry).map(name => {64 return addEntry(entry[name], name);65 })66 ).then(() => callback(), callback);67 }68 });69 }70 );71 }72}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestTimeToBuyAndSellStock = require('./BestTimeToBuyAndSellStock.js');2var btbs = new BestTimeToBuyAndSellStock();3var prices = [7,1,5,3,6,4];4var profit = btbs.maxProfit(prices);5console.log(profit);6class BestTimeToBuyAndSellStock {7 maxProfit(prices) {8 let min = Number.MAX_SAFE_INTEGER;9 let max = 0;10 for (let i = 0; i < prices.length; i++) {11 if (prices[i] < min) {12 min = prices[i];13 } else if (prices[i] - min > max) {14 max = prices[i] - min;15 }16 }17 return max;18 }19}20module.exports = BestTimeToBuyAndSellStock;

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestBuddies = require("./test3");2var bestBuddies = new BestBuddies();3bestBuddies.entry();4var BestBuddies = require("./test3");5var bestBuddies = new BestBuddies();6bestBuddies.entry();7var BestBuddies = require("./test3");8var bestBuddies = new BestBuddies();9bestBuddies.entry();10var BestBuddies = require("./test3");11var bestBuddies = new BestBuddies();12bestBuddies.entry();13var BestBuddies = require("./test3");14var bestBuddies = new BestBuddies();15bestBuddies.entry();16var BestBuddies = require("./test3");17var bestBuddies = new BestBuddies();18bestBuddies.entry();19var BestBuddies = require("./test3");20var bestBuddies = new BestBuddies();21bestBuddies.entry();22var BestBuddies = require("./test3");23var bestBuddies = new BestBuddies();24bestBuddies.entry();25var BestBuddies = require("./test3");26var bestBuddies = new BestBuddies();27bestBuddies.entry();28var BestBuddies = require("./test3");29var bestBuddies = new BestBuddies();30bestBuddies.entry();

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestBuy = require('bestbuy');2var bb = new BestBuy('xxxxxx');3bb.products('(search=ipod)', {show: 'sku,name,salePrice', pageSize: 3, page: 1}, function(err, data) {4 if (err) {5 console.log('ERROR: ' + err);6 } else {7 console.log('Product Search Results:');8 console.log(data.products);9 }10});11var request = require('request');12 if (!error && response.statusCode == 200) {13 }14})15{ [Error: connect ETIMEDOUT]16 syscall: 'connect' }17var http = require('http');18 console.log("Got response: " + res.statusCode);19}).on('error', function(e) {20 console.log("Got error: " + e.message);21});22{ [Error: connect ETIMEDOUT]23 syscall: 'connect' }24var http = require('http');25 console.log("Got response: " + res.statusCode);26}).on('error', function(e) {27 console.log("Got error: " + e.message);28});29{ [Error: connect ETIMEDOUT]30 syscall: 'connect' }31var request = require('request');32 if (!error && response.statusCode == 200) {33 }34})35{ [Error: connect ET

Full Screen

Using AI Code Generation

copy

Full Screen

1var b = new BestTimeToBuyAndSellStock();2b.entry();3var b = new BestTimeToBuyAndSellStock();4b.entry();5class BestTimeToBuyAndSellStock {6 entry() {7 var prices = [7, 1, 5, 3, 6, 4];8 var maxProfit = this.maxProfit(prices);9 console.log(maxProfit);10 }11 maxProfit(prices) {12 var maxProfit = 0;13 var minPrice = Number.MAX_SAFE_INTEGER;14 for (var i = 0; i < prices.length; i++) {15 if (prices[i] < minPrice) {16 minPrice = prices[i];17 }18 else if (prices[i] - minPrice > maxProfit) {19 maxProfit = prices[i] - minPrice;20 }21 }22 return maxProfit;23 }24}

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestFirstSearch = require('./BestFirstSearch.js');2var data = require('./data.js');3var test = new BestFirstSearch(data);4test.entry();5var BestFirstSearch = function(data){6 this.data = data;7 this.openList = [];8 this.closedList = [];9 this.path = [];10 this.pathCost = 0;11 this.maxQueueSize = 0;12 this.nodesExpanded = 0;13 this.pathFound = false;14};15BestFirstSearch.prototype = {16 entry: function(){17 var self = this;18 self.openList.push(self.data.start);19 while(self.openList.length > 0){20 self.maxQueueSize = self.maxQueueSize < self.openList.length ? self.openList.length : self.maxQueueSize;21 var currentNode = self.openList.shift();22 self.closedList.push(currentNode);23 self.nodesExpanded++;24 if(self.isGoal(currentNode)){25 self.pathFound = true;26 break;27 }28 self.expand(currentNode);29 }30 self.printResult();31 },32 expand: function(currentNode){33 var self = this;34 var possibleMoves = self.data.adjacencyList[currentNode];35 possibleMoves.forEach(function(possibleMove){36 if(self.closedList.indexOf(possibleMove) == -1 && self.openList.indexOf(possibleMove) == -1){37 self.openList.push(possibleMove);38 self.path.push({39 });40 }41 });42 self.openList.sort(function(a, b){43 return self.data.heuristic[b] - self.data.heuristic[a];44 });45 },46 isGoal: function(currentNode){47 return currentNode == this.data.goal;48 },49 printResult: function(){50 var self = this;51 if(self.pathFound){52 console.log('Path found');53 console.log('Path cost: ' + self.pathCost);54 console.log('Max queue size: ' + self.maxQueueSize);55 console.log('Nodes expanded: ' + self.nodesExpanded);56 }57 else{58 console.log('Path not found');59 }60 }61};62module.exports = BestFirstSearch;63var data = {64 adjacencyList: {

Full Screen

Using AI Code Generation

copy

Full Screen

1var b = new BestFit();2var data = b.entry([1,2,3,4,5,6,7,8,9,10], 3);3console.log(data);4var b = new BestFit();5var data = b.entry([1,2,3,4,5,6,7,8,9,10], 4);6console.log(data);7var b = new BestFit();8var data = b.entry([1,2,3,4,5,6,7,8,9,10], 5);9console.log(data);10var b = new BestFit();11var data = b.entry([1,2,3,4,5,6,7,8,9,10], 6);12console.log(data);13var b = new BestFit();14var data = b.entry([1,2,3,4,5,6,7,8,9,10], 7);15console.log(data);16var b = new BestFit();17var data = b.entry([1,2,3,4,5,6,7,8,9,10], 8);18console.log(data);19var b = new BestFit();20var data = b.entry([1,2,3,4,5,6,7,8,9,10], 9);21console.log(data);22var b = new BestFit();23var data = b.entry([1,2,3,4,5,6,7,8,9,10], 10);24console.log(data);25var b = new BestFit();26var data = b.entry([1,2,3,4,5,6,7,8,9,10], 11);27console.log(data);

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestOf = require('./BestOf');2var best = new BestOf();3best.entry('test1.js');4best.entry('test2.js');5best.entry('test3.js');6best.entry('test4.js');7best.entry('test5.js');8best.entry('test6.js');9best.entry('test7.js');10best.entry('test8.js');11best.entry('test9.js');12best.entry('test10.js');13best.entry('test11.js');14best.entry('test12.js');15best.entry('test13.js');16best.entry('test14.js');17best.entry('test15.js');18best.entry('test16.js');19best.entry('test17.js');20best.entry('test18.js');21best.entry('test19.js');22best.entry('test20.js');23best.entry('test21.js');24best.entry('test22.js');25best.entry('test23.js');26best.entry('test24.js');27best.entry('test25.js');28best.entry('test26.js');29best.entry('test27.js');30best.entry('test28.js');31best.entry('test29.js');32best.entry('test30.js');33best.entry('test31.js');34best.entry('test32.js');35best.entry('test33.js');36best.entry('test34.js');37best.entry('test35.js');38best.entry('test36.js');39best.entry('test37.js');40best.entry('test38.js');41best.entry('test39.js');42best.entry('test40.js');43best.entry('test41.js');44best.entry('test42.js');45best.entry('test43.js');46best.entry('test44.js');47best.entry('test45.js');48best.entry('test46.js');49best.entry('test47.js');50best.entry('test48.js');51best.entry('test49.js');52best.entry('test50.js');53best.entry('test51.js');54best.entry('test52.js');55best.entry('test53.js');56best.entry('test54.js');57best.entry('test55.js');58best.entry('test56.js');59best.entry('test57.js');60best.entry('test58.js');61best.entry('test59.js');62best.entry('test60.js');63best.entry('test61.js');64best.entry('test62.js');65best.entry('test63.js');66best.entry('test64.js');67best.entry('test65.js');68best.entry('test66.js');69best.entry('test67.js');

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Best automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful